[Tutorial] GiveItem with more features
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: CLICK ME
Screenshot:
https://i.imgur.com/TaeuC30.jpg
https://i.hizliresim.com/moPnAZ.png
Re: [Tutorial] GiveItem with more features
Re: [Tutorial] GiveItem with more features
Quote:
Originally Posted by
LukasCCB
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.
Re: [Tutorial] GiveItem with more features
Try usage the www.pastebin.com or other to code. CODE tag of this forum have a problem or idk.
https://pastebin.com/KxfTqEBR
Re: [Tutorial] GiveItem with more features
Quote:
Originally Posted by
LukasCCB
Sure , added pastebin to main thread.
Thank You.
Re: [Tutorial] GiveItem with more features
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