String Problem
#1

Hello i made a string for a realese but when i get realesed it dosent shows for how much time i was there for exsample
if i got jailed for 5 seconds then i everyone get this message "[PG]DarkLored Has been released from jail after 0 seconds"

so here is my code :

pawn Код:
@Release(playerid);
@Release(playerid)
{
    new string[120];
    new Time = GetPVarInt(playerid, "JailTime");
    if(!IsPlayerConnected(playerid))
        return 0;

    if(Time < 1)
    {
      SetPVarInt(playerid, "Jailed", 0);
      SetPlayerInterior(playerid, 6);
      SetPlayerPos(playerid, 246.5301,86.7577,1003.6406);
      SetPlayerFacingAngle(playerid, 176.7961);
      SetPlayerHealth(playerid,100);
      format(string,sizeof(string),"%s(%d) Has been realesed from Los Santos Jail after %d seconds",GetName(playerid),playerid,Time);
      SendClientMessageToAll(COLOR_ORANGE,string);
      return 1;
    }

    new str[30];
    format(str, sizeof(str), "You will be released in: %d", Time);
    GameTextForPlayer(playerid, str, 2500, 3); // Change it if you want

    SetPVarInt(playerid, "JailTime", Time - 1); // Decrease the player's jail time
    SetTimerEx("@Release", 1000, false, "i", playerid);
    return 1;
}
Reply
#2

the problem lies in ur coding.
Quote:

if(Time < 1)
{
SetPVarInt(playerid, "Jailed", 0);
SetPlayerInterior(playerid, 6);
SetPlayerPos(playerid, 246.5301,86.7577,1003.6406);
SetPlayerFacingAngle(playerid, 176.7961);
SetPlayerHealth(playerid,100);
format(string,sizeof(string),"%s(%d) Has been realesed from Los Santos Jail after %d seconds",GetName(playerid),playerid,Time);
SendClientMessageToAll(COLOR_ORANGE,string);
return 1;
}

your code says if Time < 1
that means your time variable has reached 0.
and then u have called it in "abcxyz was released after %d seconds"
so basically ur calling it when the time is 0, so it will show zero.
do this,
create two variables when u jail someone that stores the time.
one that decreases, and one that doesnt.
consider one as Time1 and the other as Time2.
now, let Time1 be constant, and Time2 decrease.
now in your statement, do
if Time2 < 1
and later where you call it to replace the %d, call Time1
this should fix your issue.
i hope this helped.
Reply
#3

I didnt get can you explain more with exsamples
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)