jailing command
#1

Im making a jail command now i placed the timer to the unjail in ongamemodeinit but it only counts to negative numbers even if the player jailtime is 0, it still counts to negative numbers as long as the player connect to server...
PHP код:
//ongamemodeinit
    
SetTimer("PrisonTimer"1000true);
//the command
CMD:ajail(playeridparams[])
{
    if(
IsPlayerAdmin(playerid) || pInfo[playerid][Admin] >= 3)
    {
        new 
playerbtimestring[128], RandomCell;
         if(
sscanf(params"uis[64]"playerbtimeparams)) return SendClientMessage(playeriderror"Usage: /ajail [playerid] [time] [reason]");
        if(!
IsPlayerConnected(playerb)) return SendClientMessage(playeriderror"Player id not connected.");
        if(
time == 0)
        {
            if(!
pInfo[playerb][Jailed]) return SendClientMessage(playerid0xFFFFFF"Player is not prisoned.");
            
SetPlayerColor(playerberror);
            
pInfo[playerb][Jailed] = 0;
            
pInfo[playerb][JailedTime] = time;
            
SetPlayerInterior(playerb0);
            
SetPlayerVirtualWorld(playerb0);
            
RandomCell random(sizeof(RandomJails));
            
SetPlayerFacingAngle(playerb88.5042);
            
SetPlayerPos(playerb1548.8394,-1669.6111,13.5656);
            
SetCameraBehindPlayer(playerb);
            
format(stringsizeof(string), "[AdmCmd]: {FF6347}An Administrator has released %s from Jail. [Reason: %s]",GetName(playerb), params);
            
SendClientMessageToAll(redstring);
            
format(stringsizeof(string), "[AdmCmd]:{FF6347}You have been released by administrator %s.",GetName(playerid));
            
SendClientMessage(playerid,redstring);
            
TogglePlayerControllable(playerb1);
        }
        else
        {
            
SetPlayerColor(playerberror);
            
pInfo[playerb][Jailed] = 2;
            
pInfo[playerb][JailedTime] = time*60;
            
SetPlayerVirtualWorld(playerb1337);
                  
SetPlayerInterior(playerb3);
            
ResetPlayerWeapons(playerb);
            
RandomCell random(sizeof(RandomJails));
            
SetPlayerFacingAngle(playerbRandomJails[RandomCell][3]);
            
TogglePlayerControllable(playerb0);
            
SetTimerEx("EnterExitTimer"5000false"i"playerb);
            
SetPlayerPos(playerbRandomJails[RandomCell][0], RandomJails[RandomCell][1], RandomJails[RandomCell][2]);
            
SetCameraBehindPlayer(playerb);
            
format(stringsizeof(string), "[AdmCmd]: {FF6347}An Administrator has jailed %s. [Reason: %s]"GetName(playerb), params);
            
SendClientMessageToAll(redstring);
            
format(stringsizeof(string), "[AdmCmd]: {FF6347}You have been jailed by administrator %s. Minutes: %d || Seconds: %d",GetName(playerid), pInfo[playerb][JailedTime]/60pInfo[playerb][JailedTime]);
            
SendClientMessage(playerbredstring);
            
GameTextForPlayer(playerb"~w~Loading Objects"35003);
            
TogglePlayerControllable(playerb0);
            
SetTimerEx("EnterExitTimer"5000false"i"playerb);
            
pInfo[playerb][pSpawnFreeze] = 1;
            
RemovePlayerAttachedObject(playerb0);
            
SetPlayerSpecialAction(playerbSPECIAL_ACTION_NONE);
        }
    }
      else return 
ShowMessage(playeriderror1);
      return 
1;

PHP код:
forward PrisonTimer();
public 
PrisonTimer()
{
    foreach(
Playerplayerid)
    {
        if(
pInfo[playerid][Jailed] == 2)
        {
            
pInfo[playerid][Jailed] = 0;
            
pInfo[playerid][JailedTime] = 0;
            
SetPlayerInterior(playerid0);
            
SetPlayerVirtualWorld(playerid0);
            
SetPlayerFacingAngle(playerid88.5042);
            
SetPlayerColor(playeriderror);
            
SetPlayerPos(playerid1548.8394,-1669.6111,13.5656);
            
SetCameraBehindPlayer(playerid);
            
SendClientMessage(playeridjblue" Time Served. Be on your best behaviour now :) .");
        }
        else
        {
            new 
string[128];
            
pInfo[playerid][JailedTime] --;
            
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[playerid][JailedTime]);
            
GameTextForPlayer(playeridstring15003);
        }
    }
    return 
1;

Reply
#2

try this sir

PHP код:
forward PrisonTimer(); 
public 
PrisonTimer() 

    new 
string[128]; 
    
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[playerid][JailedTime]);
    foreach(
Playerplayerid
    { 
        if(
pInfo[playerid][Jailed] == 2
        { 
            
KillTimer(PrisonTimer[playerid]);
            
pInfo[playerid][Jailed] = 0
            
pInfo[playerid][JailedTime] = 0
            
SetPlayerInterior(playerid0); 
            
SetPlayerVirtualWorld(playerid0); 
            
SetPlayerFacingAngle(playerid88.5042); 
            
SetPlayerColor(playeriderror); 
            
SetPlayerPos(playerid1548.8394,-1669.6111,13.5656); 
            
SetCameraBehindPlayer(playerid); 
            
SendClientMessage(playeridjblue" Time Served. Be on your best behaviour now :) ."); 
        } 
        else 
        { 
            
GameTextForPlayer(playeridstring15003); 
        } 
    } 
    
pInfo[playerid][JailedTime] --;
    return 
1

Reply
#3

Quote:
Originally Posted by sams90
Посмотреть сообщение
try this sir

PHP код:
forward PrisonTimer(); 
public 
PrisonTimer() 

    new 
string[128]; 
    
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[playerid][JailedTime]);
    foreach(
Playerplayerid
    { 
        if(
pInfo[playerid][Jailed] == 2
        { 
            
KillTimer(PrisonTimer[playerid]);
            
pInfo[playerid][Jailed] = 0
            
pInfo[playerid][JailedTime] = 0
            
SetPlayerInterior(playerid0); 
            
SetPlayerVirtualWorld(playerid0); 
            
SetPlayerFacingAngle(playerid88.5042); 
            
SetPlayerColor(playeriderror); 
            
SetPlayerPos(playerid1548.8394,-1669.6111,13.5656); 
            
SetCameraBehindPlayer(playerid); 
            
SendClientMessage(playeridjblue" Time Served. Be on your best behaviour now :) ."); 
        } 
        else 
        { 
            
GameTextForPlayer(playeridstring15003); 
        } 
    } 
    
pInfo[playerid][JailedTime] --;
    return 
1

I dont think that will fix anything...
Reply
#4

did u try that?
Reply
#5

Quote:
Originally Posted by sams90
Посмотреть сообщение
did u try that?
By the look of it and to my experience in pawno, you only just moved the string to the top , that doesnt solve the issue.. The issue at hand is , the timer is not counting down the time properly
Reply
#6

first of all dont define one things 2x time

PHP код:
if(sscanf(params"uis[64]"playerbtimeparams))
//you are defining params 2x times upthere try new reason[]; instead of params 
then why are you using this at if (time == 0) ?
PHP код:
RandomCell random(sizeof(RandomJails)); 
and why are you setting timers 2x time ?
PHP код:
SetTimerEx("EnterExitTimer"5000false"i"playerb); 
and can you explain me how it works ?

PHP код:
// in top you are setting pInfo[playerid][Jailed] == 2 when a player gets jailed by admin 
// and in down you are checking if pInfo[playerid][Jailed] == 2 so :S when the else part is called ?
 
foreach(Playerplayerid
    { 
        if(
pInfo[playerid][Jailed] == 2
        { 
            
pInfo[playerid][Jailed] = 0
            
pInfo[playerid][JailedTime] = 0
            
SetPlayerInterior(playerid0); 
            
SetPlayerVirtualWorld(playerid0); 
            
SetPlayerFacingAngle(playerid88.5042); 
            
SetPlayerColor(playeriderror); 
            
SetPlayerPos(playerid1548.8394,-1669.6111,13.5656); 
            
SetCameraBehindPlayer(playerid); 
            
SendClientMessage(playeridjblue" Time Served. Be on your best behaviour now :) ."); 
        } 
        else 
        { 
            new 
string[128]; 
            
pInfo[playerid][JailedTime] --; 
            
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[playerid][JailedTime]); 
            
GameTextForPlayer(playeridstring15003); 
        } 
    } 
im sure this will work for you
PHP код:
public PrisonTimer()
{
    for(new 
i;i<MAX_PLAYERS;i++)
    {
        if(
pInfo[i][Jailed] > 0)
        {
            if(
pInfo[i][JailedTime] == 0)
            {
                
pInfo[i][Jailed] = 0;
                
SetPlayerInterior(i0);
                
SetPlayerVirtualWorld(i0);
                
SetPlayerFacingAngle(i88.5042);
                
SetPlayerColor(ierror);
                    
SetPlayerPos(i1548.8394,-1669.6111,13.5656);
                
SetCameraBehindPlayer(i);
                    
SendClientMessage(ijblue" Time Served. Be on your best behaviour now :) .");
            }
            else
            {
                new 
string[128];
                
pInfo[i][JailedTime] --;
                    
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[i][JailedTime]);
                
GameTextForPlayer(istring15003);
            }
        }
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by khRamin78
Посмотреть сообщение
first of all dont define one things 2x time

PHP код:
if(sscanf(params"uis[64]"playerbtimeparams))
//you are defining params 2x times upthere try new reason[]; instead of params 
then why are you using this at if (time == 0) ?
PHP код:
RandomCell random(sizeof(RandomJails)); 
and why are you setting timers 2x time ?
PHP код:
SetTimerEx("EnterExitTimer"5000false"i"playerb); 
and can you explain me how it works ?

PHP код:
// in top you are setting pInfo[playerid][Jailed] == 2 when a player gets jailed by admin 
// and in down you are checking if pInfo[playerid][Jailed] == 2 so :S when the else part is called ?
 
foreach(Playerplayerid
    { 
        if(
pInfo[playerid][Jailed] == 2
        { 
            
pInfo[playerid][Jailed] = 0
            
pInfo[playerid][JailedTime] = 0
            
SetPlayerInterior(playerid0); 
            
SetPlayerVirtualWorld(playerid0); 
            
SetPlayerFacingAngle(playerid88.5042); 
            
SetPlayerColor(playeriderror); 
            
SetPlayerPos(playerid1548.8394,-1669.6111,13.5656); 
            
SetCameraBehindPlayer(playerid); 
            
SendClientMessage(playeridjblue" Time Served. Be on your best behaviour now :) ."); 
        } 
        else 
        { 
            new 
string[128]; 
            
pInfo[playerid][JailedTime] --; 
            
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[playerid][JailedTime]); 
            
GameTextForPlayer(playeridstring15003); 
        } 
    } 
im sure this will work for you
PHP код:
public PrisonTimer()
{
    for(new 
i;i<MAX_PLAYERS;i++)
    {
        if(
pInfo[i][Jailed] > 0)
        {
            if(
pInfo[i][JailedTime] == 0)
            {
                
pInfo[i][Jailed] = 0;
                
SetPlayerInterior(i0);
                
SetPlayerVirtualWorld(i0);
                
SetPlayerFacingAngle(i88.5042);
                
SetPlayerColor(ierror);
                    
SetPlayerPos(i1548.8394,-1669.6111,13.5656);
                
SetCameraBehindPlayer(i);
                    
SendClientMessage(ijblue" Time Served. Be on your best behaviour now :) .");
            }
            else
            {
                new 
string[128];
                
pInfo[i][JailedTime] --;
                    
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[i][JailedTime]);
                
GameTextForPlayer(istring15003);
            }
        }
    }
    return 
1;

You guys are not getting the issue at hand, the issue is the timer wont count down the players jailed time to release them, thats the issue...

And the enterexittimer freezes players cause i used a mapped prison so it load the objects then unfreeze the players
Reply
#8

Quote:
Originally Posted by 1fret
Посмотреть сообщение
You guys are not getting the issue at hand, the issue is the timer wont count down the players jailed time to release them, thats the issue...

And the enterexittimer freezes players cause i used a mapped prison so it load the objects then unfreeze the players
i got what your problem is and also i give it a fix try that it will work

PHP код:
public PrisonTimer() 

    for(new 
i;i<MAX_PLAYERS;i++) 
    { 
        if(
pInfo[i][Jailed] > 0
        { 
            if(
pInfo[i][JailedTime] == 0
            { 
                
pInfo[i][Jailed] = 0
                
SetPlayerInterior(i0); 
                
SetPlayerVirtualWorld(i0); 
                
SetPlayerFacingAngle(i88.5042); 
                
SetPlayerColor(ierror); 
                    
SetPlayerPos(i1548.8394,-1669.6111,13.5656); 
                
SetCameraBehindPlayer(i); 
                    
SendClientMessage(ijblue" Time Served. Be on your best behaviour now :) ."); 
            } 
            else 
            { 
                new 
string[128]; 
                
pInfo[i][JailedTime] --; 
                    
format(string,sizeof(string),"~r~Jailed Time Left: ~w~%d ~r~seconds"pInfo[i][JailedTime]); 
                
GameTextForPlayer(istring15003); 
            } 
        } 
    } 
    return 
1

actully your problem was that in prisontimer that else state wont ever be called thats why it dosnt work and with this code it will work try that
Reply
#9

RESOLVED
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)