Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] GiveItem with more features

Junior Spellweaver
Joined
Jan 5, 2015
Messages
173
Reaction score
194
What is this ?
Modified version of Cmd_GiveItem function for more features.

It also adds chat messages with given items and player names.

How to use it ?

/giveme
itemidcount - Gives item to person who used this code.
/giveall itemidcount - Gives item to every alive player in server.
/givepremium itemidcount - Gives item to every alive and premium player in server.



Search for:

Code:
if(strncmp(cmd, "/gi", 3) == 0 && (plr->profile_.ProfileData.isDevAccount & wiUserProfile::DAA_SPAWN_ITEM))        return Cmd_GiveItem(plr, cmd);


Change with:

Code:
if(strncmp(cmd, "/giveme", 7) == 0 && (plr->profile_.ProfileData.isDevAccount & wiUserProfile::DAA_SPAWN_ITEM))        return Cmd_GiveItem(plr, cmd, false, false);    if(strncmp(cmd, "/giveall", 8) == 0 && (plr->profile_.ProfileData.isDevAccount & wiUserProfile::DAA_SPAWN_ITEM))        return Cmd_GiveItem(plr, cmd, true, false);    if(strncmp(cmd, "/givepremium", 8) == 0 && (plr->profile_.ProfileData.isDevAccount & wiUserProfile::DAA_SPAWN_ITEM))        return Cmd_GiveItem(plr, cmd, true, true);


Search for:

Code:
int          Cmd_GiveItem(obj_ServerPlayer* plr, const char* cmd);


Change with:

Code:
int          Cmd_GiveItem(obj_ServerPlayer* plr, const char* cmd, bool toeveryone, bool topremium);


Search for:

Code:
int ServerGameLogic::Cmd_GiveItem(obj_ServerPlayer* plr, const char* cmd)


Now change the entire function with this one:

Code:
int ServerGameLogic::Cmd_GiveItem(obj_ServerPlayer* plr, const char* cmd, bool toeveryone, bool topremium){    char buf[128];    int itemid;    int count = 1;        if(2 > sscanf(cmd, "%s %d %d", buf, &itemid, &count))        return 2;    if(g_pWeaponArmory->getConfig(itemid) == NULL) {        r3dOutToLog("Cmd_GiveItem: no item %d\n", itemid);        return 3;            }    bool logGiveItem=true;#ifdef DISABLE_GI_ACCESS_ON_PTE_MAP    if(ginfo_.channel==6) // don't care about PTE maps, as nothing there is saved        logGiveItem=false;#endif#ifdef DISABLE_GI_ACCESS_ON_PTE_STRONGHOLD_MAP    if(ginfo_.channel==6 && ginfo_.mapId==GBGameInfo::MAPID_WZ_Cliffside) // don't care about PTE maps, as nothing there is saved        logGiveItem=false;#endif#ifdef DISABLE_GI_ACCESS_FOR_CALI_SERVER    if(gServerLogic.ginfo_.mapId==GBGameInfo::MAPID_WZ_California)        logGiveItem=false;#endif                if(logGiveItem)        LogCheat(plr->peerId_, PKT_S2C_CheatWarning_s::CHEAT_AdminGiveItem, 0, "Admin Spawn Item", "%d (%s) spawned %d with quantity %d on server %s\n", plr->profile_.CustomerID, plr->userName, itemid, count, ginfo_.name);char* itemname="";const BaseItemConfig* getitem = g_pWeaponArmory->getConfig(itemid);                        if(getitem)                itemname = getitem->m_StoreName;    if(toeveryone)        {//give item to all players.for(int i=0; i<curPlayers_; i++) {                obj_ServerPlayer* player = plrList_[i];                if(player->loadout_->Alive == 0) // do not give item to death players !                    continue;                if(player->profile_.ProfileData.PremiumAcc < 0 && topremium ) // only give item if user is premium !                    continue;                char msg[512]="";                sprintf(msg,"Player: %s Rewarded with: %s ",player->loadout_->Gamertag, itemname);        PKT_C2C_ChatMessage_s n;        n.userFlag = 0;        n.msgChannel = 1;        r3dscpy(n.msg, msg);        r3dscpy(n.gamertag, "[GiveItem]");        gServerLogic.p2pBroadcastToAll(&n, sizeof(n), true);    wiInventoryItem wi;    wi.itemID   = itemid;    wi.quantity = count;        player->BackpackAddItem(wi);            }       }    else        {    wiInventoryItem wi;    wi.itemID   = itemid;    wi.quantity = count;        plr->BackpackAddItem(wi);            }            return 0;}

Pastebin for function:

Screenshot:

TaeuC30 - [Tutorial] GiveItem with more features - RaGEZONE Forums


Burak DatLife - [Tutorial] GiveItem with more features - RaGEZONE Forums





 

Attachments

You must be registered for see attachments list
Last edited:
Junior Spellweaver
Joined
Jan 5, 2015
Messages
173
Reaction score
194
Nice work

What did you mean with "give all not have void function" ?

they are all using the same function "Cmd_GiveItem"
Code:
(obj_ServerPlayer* plr, const char* cmd, bool toeveryone, bool topremium)

it determines operation with bools , you dont need to have another function for it.
 
Junior Spellweaver
Joined
Jan 5, 2015
Messages
173
Reaction score
194
Try usage the or other to code. CODE tag of this forum have a problem or idk.


Sure , added pastebin to main thread.

Thank You.
 
Experienced Elementalist
Joined
May 28, 2017
Messages
225
Reaction score
127
If u mean with more features than u could make that u can enter the clip id or the count of ammo inside the clip or which attm u like to have on your gun
 
Back
Top