PDA

View Full Version : [C++] PlayerCommands.



Cocain
11-03-10, 02:26 PM
As it has been done many times before in Lua, I'm now going to demonstrate a C++ script including player commands. (Yuh, I wanne be unique.) To start of I'm keeping this basic commands, but while progressing I might add more functions on request.



/* Credits claimed by AuxProductions.

More functions WILL be added on request.
*/

#include "StdAfx.h"
#include "Setup.h"

#ifdef WIN32
#pragma warning(disable:4305) // Disables the funky warning.
#endif

// Defines.
#define FOOD 35953 // http://www.wowhead.com/?item=35953
#define DRINK 33445 // http://www.wowhead.com/?item=33445

// Command Registration
static string food = "%food"; // Adds the item '35953'.
static string drink = "%drink"; // Adds the item '33445'.
static string buffs ="%buffs"; // Buffs the player.


/* FOOOD COMMAND */
if(Message == food && !Plr->CombatStatus.IsInCombat()) { //Combat check
Item * item;
item = objmgr.CreateItem(food, Plr);
item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 10);
if(!Plr->GetItemInterface()->AddItemToFreeSlot(item))
{
Plr->BroadcastMessage("No free slots were found in your inventory!");
item->DeleteMe();
}
else
{
SlotResult * sr;
sr = Plr->GetItemInterface()->LastSearchResult();
Plr->GetSession()->SendItemPushResult(item, false, true, false, true, sr->ContainerSlot, sr->Slot, 1);
}
}
else
{
Plr->BroadcastMessage("You cannot use this command when in combat!");
}

/* DRINK COMMAND */
if(Message == drink && !Plr->CombatStatus.IsInCombat()) { //Combat check
Item * item;
item = objmgr.CreateItem(DRINK, Plr);
item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 10);
if(!Plr->GetItemInterface()->AddItemToFreeSlot(item))
{
Plr->BroadcastMessage("No free slots were found in your inventory!");
item->DeleteMe();
}
else
{
SlotResult * sr;
sr = Plr->GetItemInterface()->LastSearchResult();
Plr->GetSession()->SendItemPushResult(item, false, true, false, true, sr->ContainerSlot, sr->Slot, 1);
}
}
else
{
Plr->BroadcastMessage("You cannot use this command when in combat!");
}

/* BUFFS */
if(Message == buffs && !Plr->CombatStatus.IsInCombat())
{
Plr->CastSpell(Plr, 20217, true); // BoK
plr->CastSpell(Plr, 48469, true); // Mark of the wild.

Plr->BroadcastMessage("You are now buffed!");
}


Have fun, and note this is NOT copied from anyone.

Note : I havn't got the chance to test this yet, so might be missing a bracket perhaps. Would be nice if someone tested it. ^^

Avidgamer
11-03-10, 04:58 PM
Nice release mate. Will test it when I have a chance.

StickyIcky
12-03-10, 12:44 AM
Uhm...

I made this a while back...

All it seems is that commands and a few lines are changed.

Avidgamer
12-03-10, 07:15 AM
Hmm, I've never seen it before, but you guys know me, I forget pretty much everything I see. Anyway, quite alot of LUA's, C++ scripts etc have been done before, but people modify and edit a few things, although I dont class that as a release, I still think it's okay for them to release it, as long as they say what script they've modifed and who wrote it, in this case you. And possibly have a link to the Original owner's Profile page if he is on this forum, for us to go over and +rep him aswell.

Sdyess94
27-04-10, 02:18 AM
A bit of a necro, but I have fixed his commands :)



/* Credits claimed by AuxProductions.

More functions WILL be added on request.
*/

#include "StdAfx.h"
#include "Setup.h"

#ifdef WIN32
#pragma warning(disable:4305) // Disables the funky warning.
#endif

// Defines.
#define FOOD 35953 // http://www.wowhead.com/?item=35953
#define DRINK 33445 // http://www.wowhead.com/?item=33445

// Command Registration
static string food = "%food"; // Adds the item '35953'.
static string drink = "%drink"; // Adds the item '33445'.
static string buffs ="%buffs"; // Buffs the player.

bool AuxChat(Player * Plr, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{

if(Message == food)
{
Item * item;
item = objmgr.CreateItem(FOOD, Plr);
item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 10);

if(Plr->CombatStatus.IsInCombat())
{
Plr->BroadcastMessage("You are in combat!");
item->DeleteMe();
return true;
}
else if(!Plr->GetItemInterface()->AddItemToFreeSlot(item))
{
Plr->BroadcastMessage("No free slots were found in your inventory!");
item->DeleteMe();
}
else
{

SlotResult * sr = Plr->GetItemInterface()->LastSearchResult();
Plr->GetItemInterface()->AddItemById(DRINK, 10, 0);
}
}
else if(Message == drink)
{
Item * item;
item = objmgr.CreateItem(DRINK, Plr);
item->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 10);

if(Plr->CombatStatus.IsInCombat())
{
Plr->BroadcastMessage("You are in combat!");
item->DeleteMe();
return true;
}
else if(!Plr->GetItemInterface()->AddItemToFreeSlot(item))
{
Plr->BroadcastMessage("No free slots were found in your inventory!");
item->DeleteMe();
}
else
{
SlotResult * sr = Plr->GetItemInterface()->LastSearchResult();
Plr->GetItemInterface()->AddItemById(DRINK, 10, 0);
}
}
if(Message == buffs)
{
Plr->CastSpell(Plr, 20217, true); // BoK
Plr->CastSpell(Plr, 48469, true); // Mark of the wild.
Plr->BroadcastMessage("You are now buffed!"); //orly?
}
return true;
}

void SetupChat(ScriptMgr *mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &AuxChat);
}