View difference between Paste ID: xUp3vHyj and KxfTqEBR
SHOW: | | - or go back to the newest paste.
1
int ServerGameLogic::Cmd_GiveItem(obj_ServerPlayer* plr, const char* cmd, bool toeveryone, bool topremium)
2
{    
3
	char buf[128];    
4
	int itemid;    
5
	int count = 1;       
6
	if(2 > sscanf(cmd, "%s %d %d", buf, &itemid, &count))        
7
		return 2;   
8
	
9
	if(g_pWeaponArmory->getConfig(itemid) == NULL) 
10
	{        
11
		r3dOutToLog("Cmd_GiveItem: no item %d\n", itemid);       
12
		return 3;           
13
	}    
14
	bool logGiveItem=true;
15
#ifdef DISABLE_GI_ACCESS_ON_PTE_MAP    
16
	if(ginfo_.channel==6) // don't care about PTE maps, as nothing there is saved        
17
		logGiveItem=false;
18
#endif
19
#ifdef DISABLE_GI_ACCESS_ON_PTE_STRONGHOLD_MAP    
20
	if(ginfo_.channel==6 && ginfo_.mapId==GBGameInfo::MAPID_WZ_Cliffside) // don't care about PTE maps, as nothing there is saved        
21
		logGiveItem=false;
22
#endif
23
#ifdef DISABLE_GI_ACCESS_FOR_CALI_SERVER    
24
	if(gServerLogic.ginfo_.mapId==GBGameInfo::MAPID_WZ_California)        
25
		logGiveItem=false;
26
#endif                
27
	if(logGiveItem)        
28
		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);
29
	char* itemname="";
30
	const BaseItemConfig* getitem = g_pWeaponArmory->getConfig(itemid);
31
	if(getitem)                
32
		itemname = getitem->m_StoreName;    
33
	if(toeveryone)        
34
	{
35
		//give item to all players.
36
		for(int i=0; i<curPlayers_; i++) 
37
		{                
38
			obj_ServerPlayer* player = plrList_[i];                
39
			if(player->loadout_->Alive == 0) // do not give item to death players !                    
40
				continue;                
41
			if(player->profile_.ProfileData.PremiumAcc < 0 && topremium ) // only give item if user is premium !                    
42
				continue;                
43
			char msg[512]="";                
44
			sprintf(msg,"Player: %s Rewarded with: %s ",player->loadout_->Gamertag, itemname);       
45
			PKT_C2C_ChatMessage_s n;        
46
			n.userFlag = 0;        
47
			n.msgChannel = 1;        
48
			r3dscpy(n.msg, msg);        
49
			r3dscpy(n.gamertag, "[GiveItem]");        
50
			gServerLogic.p2pBroadcastToAll(&n, sizeof(n), true);
51
			wiInventoryItem wi;    
52
			wi.itemID   = itemid;    
53
			wi.quantity = count;        
54
			player->BackpackAddItem(wi);
55
		}       
56
	}    
57
	else        
58
	{    
59
		wiInventoryItem wi;    
60
		wi.itemID   = itemid;    
61
		wi.quantity = count;        
62
		plr->BackpackAddItem(wi);            
63
	}            
64
	return 0;
65
}