Detective /Track
#1

Iam having a bunch of problems with this command, i can use it once, if iam the first person detective to connect the server, but if some other detective tryes to use it, it places a checkpoint forever!...

any ideas, on how to fix it

Код:
forward detecttimer(playerid);

CMD:localizar(playerid, params[])
{
	if (GetPVarInt(playerid, "PVARemprego") == 402)
	{
	    if ((GetPlayerSkin(playerid)) == 272)
	    {
		    if(isnull(params))
			{
				SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: /localizar [ID]");
			}
			else
			{
			    if ((GetPVarInt(playerid, "PVARDetect_timer")) == 0)
			    {
			        new player;
				    player = strval(params);
				    
			        if ((IsPlayerConnected(player)) == true)
			        {
				 		new playername[128];
					    new Float:XX1, Float:YY1, Float:ZZ1;
				        GetPlayerPos(player, XX1, YY1, ZZ1);
				        GetPlayerName(player, playername, sizeof(playername));

				        SetPlayerCheckpoint(playerid, XX1, YY1, ZZ1, 3.0);
						format(playername, sizeof(playername), "[{FFFF99}Emprego{FFFFFF}]: Tentaste localizar {99FF00}%s{FFFFFF}", playername);
						SetTimer("detecttimer", 5000, 0);
						SetPVarInt(playerid, "PVARDetect_timer", 1);
						SendClientMessage(playerid, -1, playername);
					}
					else
					{
						SendClientMessage(playerid, -1,"[{FFFF99}Emprego{FFFFFF}]: Esse jogador nгo estб conectado!");
					}
				}
				else
				{
					SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: Tens que esperar 5 segundos para utilizar este comando outra vez!");
				}
	        }
	    }
	    else
	    {
			SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: Nгo tens o equipamento de detective! Vai б {0000FF}PSP{FFFFFF} equipar-te!");
		}
	}
	else
	{
		SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: Nгo йs um [{FFFF99}Detective{FFFFFF}]");
	}
	return 1;
}
public detecttimer(playerid)
{
    DisablePlayerCheckpoint(playerid);
	SetPVarInt(playerid, "PVARDetect_timer", 0);
	return 1;
}
Any advice on how to improve my programing, some tutorial i should take... Always welcome!!


Best regards Sagoza
Reply
#2

Well the only problem is that you forgot to pass the playerid to "detecttimer" just use SetTimerEx
pawn Код:
SetTimerEx("detecttimer", 5000, false, "i", playerid);
Well you could use normal arrays instead of PVars (everyone knows they are slow) but if it is only a rarly used command you could stay with it

Another personal thing would be that I dislike huge compound statements so I do
pawn Код:
CMD:localizar(playerid, params[]) {
    if(GetPVarInt(playerid, "PVARemprego") != 402) {
        return SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: Nгo йs um [{FFFF99}Detective{FFFFFF}]");
    }
    if(GetPlayerSkin(playerid) != 272) {
        return SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: Nгo tens o equipamento de detective! Vai б {0000FF}PSP{FFFFFF} equipar-te!");
    }
    if(isnull(params)) {
        return SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: /localizar [ID]");
    }
    if(GetPVarInt(playerid, "PVARDetect_timer") != 0) {
        return SendClientMessage(playerid, -1, "[{FFFF99}Emprego{FFFFFF}]: Tens que esperar 5 segundos para utilizar este comando outra vez!");
    }
    new
        player = strval(params)
    ;
    if(IsPlayerConnected(player) == false) {
        return SendClientMessage(playerid, -1,"[{FFFF99}Emprego{FFFFFF}]: Esse jogador nгo estб conectado!");
    }
    new
        Float: XX1,
        Float: YY1,
        Float: ZZ1
    ;
    GetPlayerPos(player, XX1, YY1, ZZ1);
    SetPlayerCheckpoint(playerid, XX1, YY1, ZZ1, 3.0);

    SetTimerEx("detecttimer", 5000, false, "i", playerid);
    SetPVarInt(playerid, "PVARDetect_timer", 1);

    new
        playername[128]
    ;
    GetPlayerName(player, playername, sizeof(playername));
    format(playername, sizeof(playername), "[{FFFF99}Emprego{FFFFFF}]: Tentaste localizar {99FF00}%s", playername);
    return SendClientMessage(playerid, -1, playername);
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)