Arrest...[Timer]
#1

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(playerid, cmdtext[])
{
    new 
cmd[256], idx, tmp[256], name[MAX_PLAYER_NAME], file[256];
    new 
giveplayerid;
    
GetPlayerName(playerid, name, sizeof(name));
    
format(file, sizeof(file), "%s.runix", name);
    
cmd = strtok(cmdtext, idx);
    if(
strcmp(cmd, "/arrest", true) == 0 || strcmp(cmd, "/ar", true) == 0)
    {
    new 
string[250];
    if(
IsSpawned[playerid] == 0)
    {
    
SendClientMessage(playerid, COLOR_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(cmdtext, idx);
    if(!
strlen(tmp))
    {
    
SendClientMessage(playerid, COLOR_ERROR, "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}/ar (PlayerID)");
    return 
1;
    }
    
giveplayerid = strval(tmp);
    if(!
IsNumeric(tmp))
    {
    
SendClientMessage(playerid, COLOR_ERROR, "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}USAGE: /ar (id) ID Must be a number");
    return 
1;
    }
    if(!
IsPlayerConnected(giveplayerid))
    {
    
format(string, sizeof(string), "{1E7F9A}[POLICE SUSPECT]: {FFFFFF}ID (%d) is not an active player", giveplayerid);
    
SendClientMessage(playerid, COLOR_ERROR, string);
    return 
1;
    }
    new 
oname[24];
    new 
pname[24];
    
GetPlayerName(playerid,oname, 24);
    
GetPlayerName(giveplayerid, pname, 24);
    if(
GetPlayerWantedLevel(giveplayerid) <= 3)
    {
    
format(string, sizeof(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(string, sizeof(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(string, sizeof(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) >=1 & 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:health, copname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME];
    
GetPlayerName(playerid, copname, sizeof(copname));
    
GetPlayerName(strval(tmp), arrested, sizeof(arrested));
    
GetPlayerHealth(strval(tmp), health);
    
SendClientMessage(strval(tmp), GREY, "|_| San Andreas Police Dept. |_|");
    
format(string, sizeof(string), "{FF9300}[POLICE ARRESTED]: {008FFF}Offiecr %s {008FFF}has arrested you.", copname);
    
SendClientMessage(strval(tmp), WHITE, string);
    
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)) >= 4 && GetPlayerWantedLevel(strval(tmp)) <= 5)
    {
    
PrisonTime[strval(tmp)] = 60;
    
GivePlayerMoney(playerid,25000);
    
GivePlayerScore(playerid,1);
    }
    else if(
GetPlayerWantedLevel(strval(tmp)) >= 6 && GetPlayerWantedLevel(strval(tmp)) <= 8)
    {
    
PrisonTime[strval(tmp)] = 120;
    
GivePlayerMoney(playerid,35000);
    
GivePlayerScore(playerid,1);
    }
    else if(
GetPlayerWantedLevel(strval(tmp)) >= 9 && 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(string2, sizeof(string2), "{FF9300}[POLICE ARRESTED]: {008FFF}Officer %s[ID:%d] {1FFF00}arrested {FF9300}%s[ID:%d].", copname, playerid, arrested, strval(tmp));
    
SendClientMessageToAll(playerid, string2);
    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.0, 0, 0, 0, 0, 0);
    }
    return 
1;
    }
      return 
0;
} 
PHP код:
public Unjail()
{
    for(new 
i = 0; i < MAX_PLAYERS; i++)
    {
        if(
IsPlayerConnected(i))
        {
            new 
file[256], name[MAX_PLAYER_NAME];
            
GetPlayerName(i, name, sizeof(name));
            
format(file, sizeof(file), "%s.runix", name);
            if(
IsPlayerJailed(i))
            {
                if(
PrisonTime[i] > 0)
                {
                    
PrisonTime[i] --;
                    new 
string[256];
                    
format(string, sizeof(string), "~w~TIME LEFT~n~~r~%d", PrisonTime[i]);
                    
GameTextForPlayer(i, string, 3000, 6);
                }
                if(
PrisonTime[i] == 0)
                {
                    new 
string[256];
                    
SetPlayerInterior(i, 3);
                    
SetPlayerPos(i, 231.1111, 146.7039, 1003.0234);
                    
SetPlayerFacingAngle(i, 272.8459);
                    
SetCameraBehindPlayer(i);
                    
PD[i] = 2;
                    
SendClientMessage(i, GREY, "|_| San Andreas Police Dept. |_|");
                    
SendClientMessage(i, WHITE, "You are free to go. Just don't get into trouble.");
                    
format(string, sizeof(string), "%s[ID:%d] has been released from prison.", name, i);
                    
SendClientMessageToAll(i, string);
                    
SetPlayerHealth(i,100);
                    
SetPlayerJailed(i, false);
                    
SetPlayerPrisonTime(i, 0);
                }
            }
        }
    }
} 
Reply
#2

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.
Reply
#3

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

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.
Reply
#5

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?
Reply
#6

In the top i put this

forward Unjail(); and here for
PHP код:
stock IsPlayerJailed(playerid)
{
    new 
file[256], name[MAX_PLAYER_NAME];
    
GetPlayerName(playerid, name, sizeof(name));
    
format(file, sizeof(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?
Reply
#7

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

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;
}
Reply
#9

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.
Reply
#10

What do you mean add printf at the top?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)