How To Make A /rob Command?
#4

Here try this a very simple one :
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
   dcmd(rob,3,cmdtext);
   return 0;
}

dcmd_rob(playerid, params[])
{
   new name[MAX_PLAYER_NAME];
   new pname[MAX_PLAYER_NAME];
   new string[126];
   GetPlayerName(playerid, name, sizeof(name));
   if(GetPVarInt(playerid,"CMDABUSE1")>GetTickCount())return SendClientMessage(playerid,Red,"ERROR : You must wait before using this command again!");


   if(sscanf(params, "u", playerid2)) SendClientMessage(playerid, White, "Usage : /rob [playerid]");
   else if(playerid2 == INVALID_PLAYER_ID) SendClientMessage(playerid, Red, "Error : That player is not connected!");
   else if(playerid2 == playerid) SendClientMessage(playerid, Red, "ERROR : You cant rob yourself!");
   else
   {
     new Float:px, Float:py, Float:pz;
     GetPlayerPos(playerid2, px, py, pz);
     if(IsPlayerInRangeOfPoint(playerid, 5, px, py, pz) == 0) return format(string, sizeof(string), "ERROR : You must be close to %s before robbing him!", pname), SendClientMessage(playerid, Red, string);
     new money = GetPlayerMoney(playerid2);

     GetPlayerName(playerid2, pname, sizeof(pname));
     GivePlayerMoney(playerid, money / 10);
     GivePlayerMoney(playerid2, -money / 10);
     GivePlayerScore(playerid, 1);
     format(string, sizeof(string), "Server : %s (ID : %d) has robbed $%d from you!", name, playerid, money/10);
     SendClientMessage(playerid2, Orange, string);
     format(string, sizeof(string), "Server : You have succesfully robbed %s (ID : %d) worth $%d", pname, playerid2, money/10);
     SendClientMessage(playerid, Lightblue, string);
     SetPVarInt(playerid,"CMDABUSE1",GetTickCount()+15000);
   }
   return 1;
}
You could notice that I used sscanf + dcmd.

And that I just divided the playerid2's money by 10. You can lessen it
to rob more money from playerid2.
Reply


Messages In This Thread
How To Make A /rob Command? - by stieben - 01.08.2010, 09:52
Re: How To Make A /rob Command? - by stieben - 01.08.2010, 11:22
Re: How To Make A /rob Command? - by [MWR]Blood - 01.08.2010, 11:27
Re: How To Make A /rob Command? - by ViruZZzZ_ChiLLL - 01.08.2010, 13:48
Re: How To Make A /rob Command? - by stieben - 01.08.2010, 16:42
Re: How To Make A /rob Command? - by ViruZZzZ_ChiLLL - 01.08.2010, 16:48

Forum Jump:


Users browsing this thread: 1 Guest(s)