Jailtime
#1

Код:
CMD:jail(playerid, params[])
{
    new id, time, reason[24];
    if(pAdmin[playerid] < 1) return SendClientMessage(playerid, 0xCD0000FF, "Invalid command. Please use {FFF8CF}/cmds {CD0000}to list all available commands.");
    if(sscanf(params, "uis", id, time, reason)) return SendClientMessage(playerid, -1, "{0008F7}USAGE: {FFFFFF}/JAIL ID MINUTES REASON");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Player is not connected");
    else
    {
        RemovePlayerFromVehicle(id);
	new PName[64];
	GetPlayerName(id, PName, sizeof(PName));
	new string[256], name[24], str[99], st[99];
	GetPlayerName(playerid, name, sizeof(name));
	format(string,sizeof(string),"{0008F7}[Administration]: {FF0095}%s {C90076}have used {FF0095}JAIL {C90076}on {FF0095}%s", name, PName);
	SendToAdmins(-1, string);
	format(str,sizeof(str),"{74C6D6}Administrator %s have jailed %s for %d Minutes",name,PName,time);
	SendClientMessageToAll(-1, str);
	format(st,sizeof(st),"{74C6D6}Reason: {FF0000}''%s''",reason);
	SendClientMessageToAll(-1, st);
	SetPlayerPos(id, 264.8763,81.9862,1001.0390);
	SetPlayerInterior(id, 6);
	Jailed[id] = 1;
	new jailtime = time *= 60000;
	SetTimer("SpawnPlayer(id)", jailtime, false);
    }
	return 1;
}
This my code
When i jail ingame, player doesn't get spawned when jailtime end
Reply
#2

You're using SetTimer where you should be looking at using SetTimerEx.

https://sampwiki.blast.hk/wiki/SetTimerEx

SetTimer doesn't accept parameters. SetTimerEx does.
Reply
#3

Код:
CMD:jail(playerid, params[])
{
	new id, time, reason[24];
	if(pAdmin[playerid] < 1) return SendClientMessage(playerid, 0xCD0000FF, "Invalid command. Please use {FFF8CF}/cmds {CD0000}to list all available commands.");
 	if(sscanf(params, "uis", id, time, reason)) return SendClientMessage(playerid, -1, "{0008F7}USAGE: {FFFFFF}/JAIL ID MINUTES REASON");
 	if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "Player is not connected");
    else
    {
        RemovePlayerFromVehicle(id);
	 	new PName[64];
		GetPlayerName(id, PName, sizeof(PName));
		new string[256], name[24], str[99], st[99];
		GetPlayerName(playerid, name, sizeof(name));
		format(string,sizeof(string),"{0008F7}[Administration]: {FF0095}%s {C90076}have used {FF0095}JAIL {C90076}on {FF0095}%s", name, PName);
		SendToAdmins(-1, string);
		format(str,sizeof(str),"{74C6D6}Administrator %s have jailed %s for %d Minutes",name,PName,time);
		SendClientMessageToAll(-1, str);
		format(st,sizeof(st),"{74C6D6}Reason: {FF0000}''%s''",reason);
		SendClientMessageToAll(-1, st);
		SetPlayerPos(id, 264.8763,81.9862,1001.0390);
	    SetPlayerInterior(id, 6);
	    Jailed[id] = 1;
	    new jailtime = time *= 60000;
	    SetTimerEx("SpawnPlayer", jailtime, false, "i", id);
    }
	return 1;
}
Already tried, still no Spawn at time end
Reply
#4

You cannot use timer for a samp sided function like SpawnPlayer. Never do that. The function needs to be a public callback and forwarded manually.
PHP код:
CMD:jail(playeridparams[])
{
    new 
idtimereason[24];
    if(
pAdmin[playerid] < 1) return SendClientMessage(playerid0xCD0000FF"Invalid command. Please use {FFF8CF}/cmds {CD0000}to list all available commands.");
     if(
sscanf(params"uis[24]"idtimereason)) return SendClientMessage(playerid, -1"{0008F7}USAGE: {FFFFFF}/JAIL ID MINUTES REASON");
     if(!
IsPlayerConnected(id)) return SendClientMessage(playerid, -1"Player is not connected");
    
RemovePlayerFromVehicle(id);
     new 
PName[64];
    
GetPlayerName(idPNamesizeof(PName));
    new 
string[256], name[24], str[99], st[99];
    
GetPlayerName(playeridnamesizeof(name));
    
format(string,sizeof(string),"{0008F7}[Administration]: {FF0095}%s {C90076}have used {FF0095}JAIL {C90076}on {FF0095}%s"namePName);
    
SendToAdmins(-1string);
    
format(str,sizeof(str),"{74C6D6}Administrator %s have jailed %s for %d Minutes",name,PName,time);
    
SendClientMessageToAll(-1str);
    
format(st,sizeof(st),"{74C6D6}Reason: {FF0000}''%s''",reason);
    
SendClientMessageToAll(-1st);
    
SetPlayerPos(id264.8763,81.9862,1001.0390);
    
SetPlayerInterior(id6);
    
Jailed[id] = 1;
    new 
jailtime = (time 60 1000);
    
SetTimerEx("UnjailPlayer"jailtimefalse"i"id);
    return 
1;
}
forward UnjailPlayer(playerid);
public 
UnjailPlayer(playerid)
{
    
SendClientMessage(playerid, -1"You have been unjailed.");
    
Jailed[playerid] = 0;
    return 
SpawnPlayer(playerid);

Reply
#5

Upon thinking about it more, this shouldn't be the way you should handle "jail". (Relogging will cause issue for things, and assigning a timer to simply "release" seems wasteful.)

I'm a massive fan of countdowns and tick timers.
Reply
#6

True. I prefer using gettime for stuff like mute and jail. Unless, you want to show the count down time in a gametext or a textdraw then a timer is a good choice but need to optimize em. If you are gonna stick with timer then create an array to hold the timer id, kill it properly else you will experience some lag.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)