SA-MP Forums Archive
Arrest...[Timer] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Arrest...[Timer] (/showthread.php?tid=639590)



Arrest...[Timer] - Man43 - 20.08.2017

Hello there a no Error / warring but When i arresting someone to he teleport to jail The problem the timer is not worked - im not see the timer.. and its not worked how will it work?

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    new 
cmd[256], idxtmp[256], name[MAX_PLAYER_NAME], file[256];
    new 
giveplayerid;
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "%s.runix"name);
    
cmd strtok(cmdtextidx);
    if(
strcmp(cmd"/arrest"true) == || strcmp(cmd"/ar"true) == 0)
    {
    new 
string[250];
    if(
IsSpawned[playerid] == 0)
    {
    
SendClientMessage(playeridCOLOR_ERROR"[DEAD]: You are dead. You cannot use this command");
    return 
1;
    }
    new 
pskin GetPlayerSkin(playerid);
    if(
pskin == 265 || pskin == 266 || pskin == 267 || pskin == 280 || pskin == 281 || pskin == 284 || pskin == 285 || pskin == 286 || pskin == 287 || pskin == 288)
    {
    
SendClientMessage(playerid,COLOR_ERROR,"{1E7F9A}[POLICE]: {FFFFFF}You are not a Law Enforcement officer ");
    return 
1;
    }
    
tmp strtok(cmdtextidx);
    if(!
strlen(tmp))
    {
    
SendClientMessage(playeridCOLOR_ERROR"{1E7F9A}[POLICE SUSPECT]: {FFFFFF}/ar (PlayerID)");
    return 
1;
    }
    
giveplayerid strval(tmp);
    if(!
IsNumeric(tmp))
    {
    
SendClientMessage(playeridCOLOR_ERROR"{1E7F9A}[POLICE SUSPECT]: {FFFFFF}USAGE: /ar (id) ID Must be a number");
    return 
1;
    }
    if(!
IsPlayerConnected(giveplayerid))
    {
    
format(stringsizeof(string), "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}ID (%d) is not an active player"giveplayerid);
    
SendClientMessage(playeridCOLOR_ERRORstring);
    return 
1;
    }
    new 
oname[24];
    new 
pname[24];
    
GetPlayerName(playerid,oname24);
    
GetPlayerName(giveplayeridpname24);
    if(
GetPlayerWantedLevel(giveplayerid) <= 3)
    {
    
format(stringsizeof(string), "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}%s(%d) Does not have a warrant. You cannot arrest a player without a warrant",pname,giveplayerid);
    
SendClientMessage(playerid,COLOR_ERROR,string);
    return 
1;
    }
    if(
IsPlayerInAnyVehicle(playerid))
    {
    
SendClientMessage(playerid,COLOR_ERROR,"{1E7F9A}[POLICE SUSPECT]: {FFFFFF}You cannot arrest a suspect if you are in a car");
    return 
1;
    }
    if(
IsPlayerInAnyVehicle(giveplayerid))
    {
    
SendClientMessage(playerid,COLOR_ERROR,"{1E7F9A}[POLICE SUSPECT]: {FFFFFF}You cannot arrest this player while he in vehicle.");
    return 
1;
    }
    if(
GetDistanceBetweenPlayers(playerid,giveplayerid) > 10)
    {
    
format(stringsizeof(string), "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}%s(%d) Is too far away. You cannot arrest that player",pname,giveplayerid);
    
SendClientMessage(playerid,COLOR_ERROR,string);
    return 
1;
    }
    if(
IsSpawned[giveplayerid] == 0)
    {
    
format(stringsizeof(string), "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}%s(%d) Is dead. You cannot arrest a dead body",pname,giveplayerid);
    
SendClientMessage(playerid,COLOR_ERROR,string);
    return 
1;
    }
    
SetPlayerVirtualWorld(giveplayerid,0);
    if(
GetPlayerWantedLevel(playerid) >=3)
    {
    
SendClientMessage(playerid,COLOR_ERROR,"{1E7F9A}[POLICE SUSPECT]: {FFFFFF}You cannot use this command on this player.. You can {1E7F9A}/ticket {FFFFFF}him.");
    return 
1;
    }
    if(
giveplayerid == playerid)
    {
    
SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest yourself.");
    return 
1;
    }
    new 
spawn random(sizeof(PrisonSpawn)), string2[250], Float:healthcopname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME];
    
GetPlayerName(playeridcopnamesizeof(copname));
    
GetPlayerName(strval(tmp), arrestedsizeof(arrested));
    
GetPlayerHealth(strval(tmp), health);
    
SendClientMessage(strval(tmp), GREY"|_| San Andreas Police Dept. |_|");
    
format(stringsizeof(string), "{FF9300}[POLICE ARRESTED]: {008FFF}Offiecr %s {008FFF}has arrested you."copname);
    
SendClientMessage(strval(tmp), WHITEstring);
    
ResetPlayerWeapons(strval(tmp));
    
SetPlayerPos(strval(tmp), PrisonSpawn[spawn][0], PrisonSpawn[spawn][1], PrisonSpawn[spawn][2]);
    
SetPlayerFacingAngle(strval(tmp), PrisonSpawn[spawn][3]);
    
SetCameraBehindPlayer(strval(tmp));
    if(
GetPlayerWantedLevel(strval(tmp)) >= && GetPlayerWantedLevel(strval(tmp)) <= 5)
    {
    
PrisonTime[strval(tmp)] = 60;
    
GivePlayerMoney(playerid,25000);
    
GivePlayerScore(playerid,1);
    }
    else if(
GetPlayerWantedLevel(strval(tmp)) >= && GetPlayerWantedLevel(strval(tmp)) <= 8)
    {
    
PrisonTime[strval(tmp)] = 120;
    
GivePlayerMoney(playerid,35000);
    
GivePlayerScore(playerid,1);
    }
    else if(
GetPlayerWantedLevel(strval(tmp)) >= && GetPlayerWantedLevel(playerid) <= 11)
    {
    
PrisonTime[strval(tmp)] = 180;
    
GivePlayerMoney(playerid,45000);
    
GivePlayerScore(playerid,2);
    }
    else if(
GetPlayerWantedLevel(strval(tmp)) >= 12 && GetPlayerWantedLevel(strval(tmp)) <= 14)
    {
    
PrisonTime[strval(tmp)] = 240;
    
GivePlayerMoney(playerid,55000);
    
GivePlayerScore(playerid,2);
    }
    else if(
GetPlayerWantedLevel(strval(tmp)) >= 15)
    {
    
PrisonTime[strval(tmp)] = 300;
    
GivePlayerMoney(playerid,65000);
    
GivePlayerScore(playerid,3);
    }
    
SetPlayerWantedLevel(strval(tmp), 0);
    
SetPlayerInterior(strval(tmp),3);
    
SetPlayerHealth(strval(tmp),99999);
    
TogglePlayerControllable(strval(tmp), true);
    
SetPlayerJailed(strval(tmp), true);
    
format(string2sizeof(string2), "{FF9300}[POLICE ARRESTED]: {008FFF}Officer %s[ID:%d] {1FFF00}arrested {FF9300}%s[ID:%d]."copnameplayeridarrestedstrval(tmp));
    
SendClientMessageToAll(playeridstring2);
    if(
health <= 90)
    {
    
SendClientMessage(strval(tmp), GREY"|_| San Andreas Police Dept. |_|");
    
SendClientMessage(strval(tmp), WHITE"SAPD has given you some food.");
    
SetPlayerHealth(strval(tmp), health+10);
    
ApplyAnimation(strval(tmp), "FOOD""EAT_Burger"4.000000);
    }
    return 
1;
    }
      return 
0;

PHP код:
public Unjail()
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            new 
file[256], name[MAX_PLAYER_NAME];
            
GetPlayerName(inamesizeof(name));
            
format(filesizeof(file), "%s.runix"name);
            if(
IsPlayerJailed(i))
            {
                if(
PrisonTime[i] > 0)
                {
                    
PrisonTime[i] --;
                    new 
string[256];
                    
format(stringsizeof(string), "~w~TIME LEFT~n~~r~%d"PrisonTime[i]);
                    
GameTextForPlayer(istring30006);
                }
                if(
PrisonTime[i] == 0)
                {
                    new 
string[256];
                    
SetPlayerInterior(i3);
                    
SetPlayerPos(i231.1111146.70391003.0234);
                    
SetPlayerFacingAngle(i272.8459);
                    
SetCameraBehindPlayer(i);
                    
PD[i] = 2;
                    
SendClientMessage(iGREY"|_| San Andreas Police Dept. |_|");
                    
SendClientMessage(iWHITE"You are free to go. Just don't get into trouble.");
                    
format(stringsizeof(string), "%s[ID:%d] has been released from prison."namei);
                    
SendClientMessageToAll(istring);
                    
SetPlayerHealth(i,100);
                    
SetPlayerJailed(ifalse);
                    
SetPlayerPrisonTime(i0);
                }
            }
        }
    }




Re: Arrest...[Timer] - TheCman - 20.08.2017

I think your Unjail function is meant to be called each second no matter what. Try something like SetTimer("Unjail", 1000, true); in your OnFilterScriptInit or OnGamemodeInit.


Re: Arrest...[Timer] - Man43 - 20.08.2017

i add SetTimer("Unjail", 1000, true); at my OnGamemodeInit But still not work... what to do?


Re: Arrest...[Timer] - Ghazal - 20.08.2017

In this Unjail function, you're checking if the player is jailed by using this, "IsPlayerJailed", however on your arrest command, you did not set his IsPlayerJailed to true or 1.


Re: Arrest...[Timer] - TheCman - 20.08.2017

Ghazal, wrong, there's this in his arrest function:
Код:
    SetPlayerJailed(strval(tmp), true);
Let's debug the whole thing from the start then. Man43 can you add a printf at the top of your unjail function, and check the logs to see if it's properly called?


Re: Arrest...[Timer] - Man43 - 20.08.2017

In the top i put this

forward Unjail(); and here for
PHP код:
stock IsPlayerJailed(playerid)
{
    new 
file[256], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(filesizeof(file), "%s.runix"name);
    if(
dini_Int(file"Jail") == 1)
    {
        return 
true;
    }
    else if(
dini_Int(file"Jail") == 0)
    {
        return 
false;
    }
    return 
true;

What to do now?


Re: Arrest...[Timer] - TheCman - 20.08.2017

Show SetPlayerJailed function too, just to make sure it works on the same ini file and key.


Re: Arrest...[Timer] - Man43 - 20.08.2017

Ok here you go:

Код:
stock SetPlayerJailed(playerid, bool)
{
	new file[256], name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof(name));
	format(file, sizeof(file), "%s.runix", name);
	if(bool == 1) dini_IntSet(file, "Jail", 1);
	else if(bool == 0) dini_IntSet(file, "Jail", 0);
	return true;
}



Re: Arrest...[Timer] - TheCman - 20.08.2017

Well, that part seems all fine, so let's go back to my initial suggestion, and debug this from the start. Could you add a printf at the top of your unjail function please? Then check your logs to see if the function is indeed called.


Re: Arrest...[Timer] - Man43 - 20.08.2017

What do you mean add printf at the top?