Timer in command
#1

So this command is used to locate players with wanted levels(Suspects).I tried putting timer so it shows the suspect location 5 seconds after typing /loc command.I wanted it to look like this.
(Types /loc playerid)
Код:
Requesting intel on suspect..
[Location]Example was last reported seen at Idlewood.
Full cmd
Код:
CMD:loc(playerid, params[])
{
	new giveplayerid, string[256], giveplayer[25];
	if (GetPVarInt(playerid, "playerorg") != 0)
	{
		if(!IsALaw(playerid)) return SendClientMessage2(playerid, COLOR_RED, "Error: You are not a law enforcer!");
	}
	else return SendClientMessage2(playerid, COLOR_RED, "Error: You are not a law enforcer!");
	if (GetPVarInt(playerid, "podfskin") == -1) return SendClientMessage2(playerid, COLOR_RED, "{FF5357}Error: {FFFFFF}You are off duty.");
	if (sscanf(params, "u", giveplayerid)) return SendClientMessage2(playerid, COLOR_ORANGE, "Usage: /loc [playerid]");
	if (!IsPlayerConnected2(giveplayerid)) return SendClientMessage2(playerid, COLOR_RED, "{FF5357}Error: {FFFFFF}Inactive player id!");
	GetPlayerName(giveplayerid, giveplayer, MAX_PLAYER_NAME);
	if (GetPlayerWantedLevel(giveplayerid) == 0) return SendPlayerFormattedText(playerid, COLOR_RED, "{FF5357}Error: {FFFFFF}%s isn't a wanted player.", giveplayer, "");
	if (orcl[giveplayerid][0] != 0) return SendPlayerFormattedText(playerid, COLOR_RED, "Error: %s isn't spawned.", giveplayer, "");
 	SetTimer("Requesting intel on suspect...", 3000, false);
	if (playerZone[giveplayerid] > sizeof(zonenames)-11) SendPlayerFormattedText(playerid, COLOR_WHITE, "[Location] %s was last reported seen in %s.", giveplayer, zonenames[playerZone[giveplayerid]][z_name]);
	else
	{
		format(string, 128, "[location] %s was last reported seen in %s, %s.", giveplayer, zonenames[playerZone[giveplayerid]][z_name], zonenames[sizeof(zonenames)-(zonetype[playerZone[giveplayerid]]+1)][z_name]);
		SendClientMessage2(playerid, COLOR_WHITE, string);
	}
	return 1;
}
Never really used the timers,help me out please.Thanks in advance.
Reply
#2

Just make timer on final code that locate player (idk english so i cant figure this code..)

example (this is not like this code but.)
forward loc(playerid);
public loc(playerid)
{
Final location code
}
Reply
#3

Here you are:
PHP код:
CMD:loc(playeridparams[])
{
    new 
giveplayeridstring[256], giveplayer[25];
    if(
sscanf(params"u"giveplayerid)) return SendClientMessage2(playeridCOLOR_ORANGE"Usage: /loc [playerid]");
    if (
GetPVarInt(playerid"playerorg") != 0)
    {
        if(!
IsALaw(playerid)) return SendClientMessage2(playeridCOLOR_RED"Error: You are not a law enforcer!");
    }
    else return 
SendClientMessage2(playeridCOLOR_RED"Error: You are not a law enforcer!");
    if (
GetPVarInt(playerid"podfskin") == -1) return SendClientMessage2(playeridCOLOR_RED"{FF5357}Error: {FFFFFF}You are off duty.");
    if (!
IsPlayerConnected2(giveplayerid)) return SendClientMessage2(playeridCOLOR_RED"{FF5357}Error: {FFFFFF}Inactive player id!");
    
GetPlayerName(giveplayeridgiveplayerMAX_PLAYER_NAME);
    if (
GetPlayerWantedLevel(giveplayerid) == 0) return SendPlayerFormattedText(playeridCOLOR_RED"{FF5357}Error: {FFFFFF}%s isn't a wanted player."giveplayer"");
    if (
orcl[giveplayerid][0] != 0) return SendPlayerFormattedText(playeridCOLOR_RED"Error: %s isn't spawned."giveplayer"");
      
SendClientMessage2(playeridCOLOR_WHITE"Requesting intel on suspect...");
      
//LocTimer is the name of the forward, which I created bellow
    
SetTimerEx("LocTimer"5000false"i"playerid"i"giveplayerid); //5000 equals 5 seconds, because it is in milisecondsSetTimerEx("LocTimer", 5000, false, "i", playerid, "i", giveplayerid); //5000 equals 5 seconds, because it is in miliseconds
    
return 1;
}
forward LocTimer(playerid,giveplayerid); //Here Is the created forward
public LocTimer(playerid,giveplayerid//Here we are using the forward with the functions, which happen 5 seconds after typing the command
{
    
GetPlayerName(giveplayeridgiveplayerMAX_PLAYER_NAME); 
    if (
playerZone[giveplayerid] > sizeof(zonenames)-11SendPlayerFormattedText(playeridCOLOR_WHITE"[Location] %s was last reported seen in %s."giveplayerzonenames[playerZone[giveplayerid]][z_name]);
    else
    {
        
format(string128"[location] %s was last reported seen in %s, %s."giveplayerzonenames[playerZone[giveplayerid]][z_name], zonenames[sizeof(zonenames)-(zonetype[playerZone[giveplayerid]]+1)][z_name]);
        
SendClientMessage2(playeridCOLOR_WHITEstring);
    }

There are some explenations, which I think will be helpful!
Reply
#4

Quote:
Originally Posted by Kraeror
Посмотреть сообщение
Here you are:
PHP код:
CMD:loc(playeridparams[])
{
    new 
giveplayeridstring[256], giveplayer[25];
    if(
sscanf(params"u"giveplayerid)) return SendClientMessage2(playeridCOLOR_ORANGE"Usage: /loc [playerid]");
    if (
GetPVarInt(playerid"playerorg") != 0)
    {
        if(!
IsALaw(playerid)) return SendClientMessage2(playeridCOLOR_RED"Error: You are not a law enforcer!");
    }
    else return 
SendClientMessage2(playeridCOLOR_RED"Error: You are not a law enforcer!");
    if (
GetPVarInt(playerid"podfskin") == -1) return SendClientMessage2(playeridCOLOR_RED"{FF5357}Error: {FFFFFF}You are off duty.");
    if (!
IsPlayerConnected2(giveplayerid)) return SendClientMessage2(playeridCOLOR_RED"{FF5357}Error: {FFFFFF}Inactive player id!");
    
GetPlayerName(giveplayeridgiveplayerMAX_PLAYER_NAME);
    if (
GetPlayerWantedLevel(giveplayerid) == 0) return SendPlayerFormattedText(playeridCOLOR_RED"{FF5357}Error: {FFFFFF}%s isn't a wanted player."giveplayer"");
    if (
orcl[giveplayerid][0] != 0) return SendPlayerFormattedText(playeridCOLOR_RED"Error: %s isn't spawned."giveplayer"");
      
SendClientMessage2(playeridCOLOR_WHITE"Requesting intel on suspect...");
      
//LocTimer is the name of the forward, which I created bellow
    
SetTimerEx("LocTimer"5000false"i"playerid"i"giveplayerid); //5000 equals 5 seconds, because it is in milisecondsSetTimerEx("LocTimer", 5000, false, "i", playerid, "i", giveplayerid); //5000 equals 5 seconds, because it is in miliseconds
    
return 1;
}
forward LocTimer(playerid,giveplayerid); //Here Is the created forward
public LocTimer(playerid,giveplayerid//Here we are using the forward with the functions, which happen 5 seconds after typing the command
{
        
GetPlayerName(giveplayeridgiveplayerMAX_PLAYER_NAME); 
    if (
playerZone[giveplayerid] > sizeof(zonenames)-11SendPlayerFormattedText(playeridCOLOR_WHITE"[Location] %s was last reported seen in %s."giveplayerzonenames[playerZone[giveplayerid]][z_name]);
    else
    {
        
format(string128"[location] %s was last reported seen in %s, %s."giveplayerzonenames[playerZone[giveplayerid]][z_name], zonenames[sizeof(zonenames)-(zonetype[playerZone[giveplayerid]]+1)][z_name]);
        
SendClientMessage2(playeridCOLOR_WHITEstring);
    }

There are some explenations, which I think will be helpful!
Nice it works,got some issues but fixed it.Thanks! +rep
Reply
#5

Quote:
Originally Posted by ItzColaBoi
Посмотреть сообщение
Nice it works,got some issues but fixed it.Thanks! +rep
You are welcome
Reply
#6

EDIT:There is a problem.When i try to locate the suspect it shows the location of player id 0 only.Any help?

Код:
CMD:loc(playerid, params[]) 
{ 
    new giveplayerid,  giveplayer[25]; 
    if(sscanf(params, "u", giveplayerid)) return SendClientMessage2(playerid, COLOR_ORANGE, "Usage: /loc [playerid]"); 
    if (GetPVarInt(playerid, "playerorg") != 0) 
    { 
        if(!IsALaw(playerid)) return SendClientMessage2(playerid, COLOR_RED, "Error: You are not a law enforcer!"); 
    } 
    else return SendClientMessage2(playerid, COLOR_RED, "Error: You are not a law enforcer!"); 
    if (GetPVarInt(playerid, "podfskin") == -1) return SendClientMessage2(playerid, COLOR_RED, "{FF5357}Error: {FFFFFF}You are off duty."); 
    if (!IsPlayerConnected2(giveplayerid)) return SendClientMessage2(playerid, COLOR_RED, "{FF5357}Error: {FFFFFF}Inactive player id!"); 
    GetPlayerName(giveplayerid, giveplayer, MAX_PLAYER_NAME); 
    if (GetPlayerWantedLevel(giveplayerid) == 0) return SendPlayerFormattedText(playerid, COLOR_RED, "{FF5357}Error: {FFFFFF}%s isn't a wanted player.", giveplayer, ""); 
    if (orcl[giveplayerid][0] != 0) return SendPlayerFormattedText(playerid, COLOR_RED, "Error: %s isn't spawned.", giveplayer, ""); 
      SendClientMessage2(playerid, COLOR_WHITE, "Requesting intel on suspect..."); 
    SetTimerEx("LocTimer", 5000, false, "i", playerid, "i", giveplayerid); 
SetTimerEx("LocTimer", 5000, false, "i", playerid, "i", giveplayerid); 
    return 1; 
} 
forward LocTimer(playerid,giveplayerid); //Here Is the created forward 
public LocTimer(playerid,giveplayerid) //Here we are using the forward with the functions, which happen 5 seconds after typing the command 
{ 
    new giveplayer[25], string[256];
    GetPlayerName(giveplayerid, giveplayer, MAX_PLAYER_NAME);  
    if (playerZone[giveplayerid] > sizeof(zonenames)-11) SendPlayerFormattedText(playerid, COLOR_WHITE, "[Location] %s was last reported seen in %s.", giveplayer, zonenames[playerZone[giveplayerid]][z_name]); 
    else 
    { 
        format(string, 128, "[location] %s was last reported seen in %s, %s.", giveplayer, zonenames[playerZone[giveplayerid]][z_name], zonenames[sizeof(zonenames)-(zonetype[playerZone[giveplayerid]]+1)][z_name]); 
        SendClientMessage2(playerid, COLOR_WHITE, string); 
    } 
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)