help with robbing a player
#1

I have this command to rob a player, here it is
Код:
dcmd_rob(playerid,params[]) {
			if (justrobbed[playerid] == 1) return SendClientMessage(playerid, red, "You can not rob anyone. You must wait two minutes before attempting to rob another person.");
		  if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /rob [playerid]");
	  	new player1, playername[MAX_PLAYER_NAME], robber[MAX_PLAYER_NAME], string[128];
			player1 = strval(params);
			if (playerid == player1) return SendClientMessage(playerid, red, "You can not rob yourself!");
		 	if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID) {
		 	  new Float:x, Float:y, Float:z;
		 	  GetPlayerPos(player1,x,y,z);
				if (IsPlayerInRangeOfPoint(playerid, 5, x, y, z)){
				justrobbed[playerid] = 1;
				SetTimerEx("Rob", 120000, false, "%d", playerid);
				GetPlayerName(player1, playername, sizeof(playername));	GetPlayerName(playerid, robber, sizeof(robber));
				switch(random(5))
				{
				case 1:
				{
				format(string,sizeof(string),"You have just been robbed by %s!",robber);	SendClientMessage(player1,red,string);
				format(string,sizeof(string),"You have just robbed %s and got a +2 wanted level, and $500",playername);	SendClientMessage(playerid,red,string);
				SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
				GivePlayerMoney(playerid, 500);
				GivePlayerMoney(player1, - 500);
				}
				case 2, 3, 4, 5:
				{
					format(string,sizeof(string),"You fail to rob %s, You just got 2 stars!",playername);	SendClientMessage(playerid,red,string);
					format(string,sizeof(string),"%s has tried, but failed to rob you!",robber);	SendClientMessage(player1,red,string);
					SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
				}
				  }
  				} else return SendClientMessage(playerid, red, "You are not close enough to that player to rob them.");
			} else return SendClientMessage(playerid, red, "Player is not connected");
			return 1;
	}
The only problem is when I rob the person, the server crashes. Can anyone tell me whats wrong with it, because I cant figure out what is.
Reply
#2

Does anyone know what I did wrong?
Reply
#3

Probably where you said case 2, 3, 4, 5:

Try it like this as they do in C#:

pawn Код:
case 2:
    case 3:
    case 4:
    case 5:
    {
        //code
As I said that works in C# so it may not work here.
Reply
#4

pawn Код:
case 2, 3, 4, 5:
works fine in pawn
Reply
#5

Il give it a try


EDIT: Nope, invalid function or declaration at the case area
Reply
#6

Quote:
Originally Posted by 13smithc
Il give it a try


EDIT: Nope, invalid function or declaration at the case area
OK, good to know then.

I can't see anything wrong with it then. Try printing debug messages and then looking in your server log to see where the crash occurs.
Reply
#7

I just did that, It stoped at
Код:
SetTimerEx("Rob", 120000, false, "%d", playerid); print("6");
My code for rob() is
Код:
public Rob(playerid)
{
justrobbed[playerid] = 0;
return 1;
}
Reply
#8

Try getting rid of the "retrun 1;" there, see what happens.
Reply
#9

That wont be the reason. The Rob(); isn't called until the timer hits 0, which means if this was the problem the server would not crash for 2 minutes after the command. This isn't the normal crash where GTA closes it self and you get a box with some wierd number, its one where the server console just closes itself.
Reply
#10

That's true.

Still have no idea what's causing it, though I suggest just formatting the strings you want and then only having 2 SendClientMessages at the bottom of your cases.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)