Page 1 of 1

[FIX]/give2 command

PostPosted: Thu Aug 21, 2008 9:54 am
by Ghost_Dragon
I was running through GM commands in my family's test server and I noticed that the /give2 command wasn't working like it should. So I downloaded the REV 80 to see if maybe it was updated in it, still no. So what I did was replace it out of the EVO files. I take no credit for this...just putting it up for those people who's command isn't working.

In WorldServer.h find:
  1. bool pakGMItemtoplayer(CPlayer* thisclient, char* name , UINT itemid , UINT itemtype , UINT itemamount) ;


Replace with:
  1. bool pakGMItemtoplayer(CPlayer* thisclient, char* name , UINT itemid , UINT itemtype , UINT itemamount , UINT itemrefine , UINT itemls, UINT itemstats , UINT itemsocket) ;


In gmcmds.cpp find:
  1. else if (strcmp(command, "give2")==0)
  2.     {
  3.               if(Config.Command_Give2 > thisclient->Session->accesslevel)
  4.                         return true;
  5.             if ((tmp = strtok(NULL, " "))==NULL) return true; char* name=tmp;
  6.             if ((tmp = strtok(NULL, " "))==NULL) return true; unsigned itemid = atoi(tmp);
  7.             if ((tmp = strtok(NULL, " "))==NULL) return true; unsigned itemtype = atoi(tmp);
  8.             if ((tmp = strtok(NULL, " "))==NULL) return true; unsigned itemamount = atoi(tmp);
  9.             Log( MSG_GMACTION, " %s : /give2 %s,%i,%i,%i" , thisclient->CharInfo->charname, name, itemid, itemtype, itemamount);
  10.             return pakGMItemtoplayer( thisclient , name , itemid , itemtype , itemamount );
  11.  
  12.     }


Replace with:
  1. else if (strcmp(command, "give2")==0)
  2. {  
  3.              if(Config.Command_Item > thisclient->Session->accesslevel)
  4.                       return true;
  5.         UINT itemrefine, itemstats, itemls, itemsocket;
  6.         if ((tmp = strtok(NULL, " "))==NULL) return true; char* name=tmp;
  7.         if ((tmp = strtok(NULL, " "))==NULL) return true; UINT itemid =atoi(tmp);
  8.         if ((tmp = strtok(NULL, " "))==NULL) return true; UINT itemtype =atoi(tmp);
  9.         if ((tmp = strtok(NULL, " "))==NULL) return true; UINT itemamount =atoi(tmp);            
  10.         if ((tmp = strtok(NULL, " "))==NULL)
  11.             itemrefine =0;
  12.         else
  13.             itemrefine = atoi(tmp)<10?atoi(tmp)*16:9*16;
  14.         if ((tmp = strtok(NULL, " "))==NULL)
  15.             itemls =100;
  16.         else
  17.             itemls = atoi(tmp);
  18.         if ((tmp = strtok(NULL, " "))==NULL)
  19.             itemsocket =0;
  20.         else
  21.             itemsocket =atoi(tmp)==0?false:true;
  22.         if ((tmp = strtok(NULL, " "))==NULL)
  23.             itemstats =0;
  24.         else
  25.             itemstats =atoi(tmp);
  26.         Log( MSG_GMACTION, " %s : /give2 %s,%i,%i,%i,%i,%i,%i,%i" , thisclient->CharInfo->charname, name, itemid , itemtype , itemamount , itemrefine , itemls, itemstats , itemsocket);
  27.         return pakGMItemtoplayer( thisclient , name , itemid , itemtype , itemamount , itemrefine , itemls, itemstats , itemsocket );
  28. }


Also in gmcmds.cpp find:
  1. bool CWorldServer::pakGMItemtoplayer(CPlayer* thisclient, char* name , unsigned itemid , unsigned itemtype , unsigned itemamount)
  2. {
  3.    CItem item;
  4.  
  5.    item.count   = itemamount;
  6.    item.durability   = 40;
  7.    item.itemnum   = itemid;
  8.    item.itemtype   = itemtype;
  9.    item.lifespan   = 100;
  10.    item.refine   = 0;
  11.    item.stats   = 0;
  12.    item.socketed   = 0;
  13.    item.appraised   = 0;
  14.    item.gem = 0;
  15.  
  16.    CPlayer* otherclient = GetClientByCharName ( name );
  17.  
  18.    if(otherclient != NULL) {
  19.       unsigned newslot = otherclient->GetNewItemSlot( item );
  20.       if(newslot != 0xffff) {
  21.          ClearItem( thisclient->items[newslot] )
  22.          thisclient->items[newslot]=item;
  23.          otherclient->UpdateInventory( newslot );
  24.  
  25.          BEGINPACKET (pak, 0x702);
  26.          ADDSTRING(pak, "You have recieved an item from a GM !");
  27.          ADDBYTE(pak, 0);
  28.          otherclient->client->SendPacket(&pak);
  29.  
  30.          RESETPACKET (pak, 0x702);
  31.          ADDSTRING(pak, "Item has been given!");
  32.          ADDBYTE(pak, 0);
  33.          thisclient->client->SendPacket(&pak);
  34.       }
  35.       else {
  36.          BEGINPACKET (pak, 0x702);
  37.          ADDSTRING(pak, "No free slot !");
  38.          ADDBYTE(pak, 0);
  39.          thisclient->client->SendPacket(&pak);
  40.       }
  41.    }
  42.  
  43.    return true;
  44. }
  45.  


Replace with:
  1. bool CWorldServer::pakGMItemtoplayer(CPlayer* thisclient, char* name , UINT itemid, UINT itemtype, UINT itemamount, UINT itemrefine, UINT itemls, UINT itemstats, UINT itemsocket)
  2. {
  3.     CItem item;
  4.     item.count            = itemamount;
  5.     item.durability        = 40;
  6.     item.itemnum        = itemid;
  7.     item.itemtype        = itemtype;
  8.     item.lifespan        = 100; //itemls Set lifespan to 100
  9.     item.refine            = itemrefine;
  10.     item.stats            = itemstats;
  11.     item.socketed        = itemsocket;
  12.     item.appraised        = 1;
  13.     if(itemstats > 300)
  14.     {
  15.         item.gem = itemstats;  
  16.     }else{
  17.         item.gem = 0;
  18.     }  
  19.    
  20.    CPlayer* otherclient = GetClientByCharName ( name );
  21.  
  22.    if(otherclient != NULL) {
  23.       unsigned newslot = otherclient->GetNewItemSlot( item );
  24.       if(newslot != 0xffff) {
  25.          otherclient->items[newslot] = item;
  26.          otherclient->UpdateInventory( newslot );
  27.  
  28.          BEGINPACKET (pak, 0x702);
  29.          ADDSTRING(pak, "You have recieved an item from a GM !");
  30.          ADDBYTE(pak, 0);
  31.          otherclient->client->SendPacket(&pak);
  32.  
  33.          RESETPACKET (pak, 0x702);
  34.          ADDSTRING(pak, "Item has been given!");
  35.          ADDBYTE(pak, 0);
  36.          thisclient->client->SendPacket(&pak);
  37.       }
  38.       else {
  39.          BEGINPACKET (pak, 0x702);
  40.          ADDSTRING(pak, "No free slot !");
  41.          ADDBYTE(pak, 0);
  42.          thisclient->client->SendPacket(&pak);
  43.       }
  44.    }
  45.  
  46.    return true;
  47. }


Like I said I take no credit for this...just want to help things get working. Hope this gets fixed in the next REV.

Re: [FIX]/give2 command

PostPosted: Thu Aug 21, 2008 12:43 pm
by soccerstar
did you test it and everything worked out, and nice job !

Re: [FIX]/give2 command

PostPosted: Thu Aug 21, 2008 2:42 pm
by PurpleYouko
Nicely spotted.

One little issue though. You can potentially give away bugged items with this code. We need to fix stats and gems as they are intricately connected.

in your code, find

replace with this
  1.  
  2. if(itemstats > 300)
  3.     {
  4.         item.gem = itemstats;  
  5.     }else{
  6.         item.gem = 0;
  7.     }

if you don't do this then your player might have serious problems, particularly if they put this item into storage.
It also means it is possible to give away a gemmed item by setting stats greater than 300.

Re: [FIX]/give2 command

PostPosted: Thu Aug 21, 2008 7:56 pm
by Ghost_Dragon
Thanks purple....adding that last part in right now...

*Edited the first post to reflect Purple's addition.*