SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   A Command.. (https://forum.sa-mp.com/showthread.php?t=669195)

RedRex 08/09/2019 05:37 PM

A Command..
 
What's wrong with this command? I can pay the bail of my jail but another player cannot pay the ticket for my jail why?!

The command..
PHP Code:

CMD:bail(playeridparams[])
{
    
MoneyForBail[playerid] = random(7000) + 1000;
    
MoneyFor[playerid] = MoneyForBail[playerid];
    new 
idpName[MAX_PLAYER_NAME],tName[MAX_PLAYER_NAME],string[170];
    
GetPlayerName(playeridpNamesizeof(pName));
    
GetPlayerName(idtNamesizeof(tName));
    if(
sscanf(params"u"id)) return SendClientMessage(playeridCOLOR_WHITE"{FF0000}Syntax: /Bail <playerid>");
    if(
PlayerInfo[id][pJailed] == 0) return SendClientMessage(playeridred"{FF0000}Error: This player is not in jail.");
    if(
PlayerInfo[playerid][pJailed] == 1)
    {
         if(
BailPlayer[playerid] == 1)
           {
                   if(
MoneyForBail[playerid] > GetPlayerCash(playerid))
                {
                    if(
id == PlayerInfo[playerid][pJailed] && 1)
                    {
                           
MoneyFor[playerid] = MoneyForBail[playerid];
                        if(
GetPlayerMoney(playerid) < MoneyForBail[playerid]) return SendClientMessage(playeridCOLOR_RED"{FF0000}Error: {FFFFFF}You don't have engouh money to bail yourself."), PlayerPlaySound(playerid54060.00.05.0);
                           
format(fstr2sizeof(fstr2), "{FFFFFF}[JAIL RELEASE]: {FFD700}%s(%d) {FFFFFF}has been released from {33FF33}Jail{FFFFFF}. Bail paid ({33FF33}$%d{FFFFFF})!"GetName(playerid),playeridMoneyFor[playerid]);
                        
SendClientMessageToAll(COLOR_DODGERBLUEfstr2);
                        
BailPlayer[playerid] = 0;
                        
TextDrawHideForPlayer(playeridTextdraw0);
                        
TextDrawHideForPlayer(playeridTextdraw1);
                        
TextDrawHideForPlayer(playeridTextdraw2);
                        
TextDrawHideForPlayer(playeridTextdraw3);
                        
TextDrawHideForPlayer(playeridTextdraw9);
                        
escapeText(playerid);
                        
KillTimer(pJailTimerID[playerid]);
                         
KillTimer(SendToJail[playerid]);
                        
KillTimer(pJailCount[playerid]);
                         
BeginArrested[playerid] = 0;
                          
MoneyForBail[playerid] = 0;
                          
escapetime[playerid] = 1;
                        
SetPlayerInterior(playerid3);
                        
PlayerInfo[playerid][pJailed] = 0;
                        
SetPlayerPos(playerid199.4501,169.1128,1003.0234);
                        
SetPlayerHealth(playerid100);
                        
GivePlayerMoney(playerid, -MoneyFor[playerid]);
                        
OtherMenuBail[id] = 0;
                           
format(fstrsizeof(fstr), "[DISPATCH]: Suspect %s[%d) has bail himself."pNameplayerid);
                        
CopRadio(COLOR_DODGERBLUEfstr);
                        return 
1;
                  }
            }
        }
        else
        {
              if(
PlayerInfo[playerid][pJailed] == 1// If the id which he typed is the same as his id
            
{
                
format(fstr2,sizeof(fstr2), "{00BDFF}[Jail Released]: {FFFFFF}%s(%d) has not served their minimum Jail Sentence yet. {FFFFFF}Time left: {0080FF}%d{FFFFFF}."GetName(playerid),playerid,pJailCount[playerid]);
                
SendClientMessage(playerid, -1fstr2);
                return 
1;
               }
               else
               {
                   
format(fstr2,sizeof(fstr2), "{00BDFF}[Jail Released]: {FFFFFF}%s(%d) has not served their minimum Jail Sentence yet. {FFFFFF}Time left: {0080FF}%d{FFFFFF}."GetName(playerid),playerid,pJailCount[playerid]);
                
SendClientMessage(id, -1,fstr2);
               }
        }
        if(
PlayerInfo[playerid][pJailed] == 1)
        {
            if(
id == OtherMenuBail[id] && 1)
            {
                if(
MoneyForBail[playerid] > GetPlayerCash(id))
                {
                      if(
GetPlayerMoney(id) > MoneyForBail[playerid])
                      {
                        
format(fstrsizeof(fstr), "{FFFFFF}[JAIL RELEASE]: {FFD700}%s(%d) {FFFFFF}has been payed the bail for Player {FFD700}%s(%d){FFFFFF}. Bail Paid: ({33FF33}$%d{FFFFFF})!"tName,id,pName,playeridMoneyForBail[playerid]);
                        
SendClientMessageToAll(COLOR_DODGERBLUEfstr);
                        
BailPlayer[playerid] = 0;
                        
TextDrawHideForPlayer(playeridTextdraw0);
                        
TextDrawHideForPlayer(playeridTextdraw1);
                        
TextDrawHideForPlayer(playeridTextdraw2);
                        
TextDrawHideForPlayer(playeridTextdraw3);
                        
TextDrawHideForPlayer(playeridTextdraw9);
                        
KillTimer(pJailTimerID[playerid]);
                        
KillTimer(SendToJail[playerid]);
                        
KillTimer(pJailCount[playerid]);
                        
BeginArrested[playerid] = 0;
                        
MoneyForBail[playerid] = 0;
                        
SetPlayerInterior(playerid3);
                        
PlayerInfo[playerid][pJailed] = 0;
                        
escapetime[playerid] = 1;
                        
SetPlayerPos(playerid199.4501,169.1128,1003.0234);
                        
SetPlayerHealth(playerid100);
                        
OtherMenuBail[playerid] = 0;
                        
GivePlayerMoney(id, -MoneyFor[playerid]);
                    }
             }
            else
              {
                
format(string,sizeof(string), "{00BDFF}[Jail Released]:{FFFFFF}%s(%d) has not served their minimum Jail Sentence yet. {FFFFFF}Time left: {0080FF}%d{FFFFFF}."pName,playeridpJailCount[playerid]);
                  
SendClientMessage(playerid, -1string);
              }
            }
            else
            {
                   
SendClientMessage(playeridCOLOR_RED"{FF0000}Error: {FFFFFF}You don't have engouh money to bail this player.");
                      
PlayerPlaySound(playerid54060.00.05.0);
            }
        }
    }
    return 
1;


PHP Code:

forward pJailTimer(playerid);
public 
pJailTimer(playerid)
{
    
MoneyFor[playerid] = MoneyForBail[playerid];
    
TextDrawHideForPlayer(playeridTextdraw3);
    
RemovePlayerAttachedObject(playerid9);
    
SetPlayerSpecialAction(playeridSPECIAL_ACTION_NONE);
    
PlayerInfo[playerid][pJailed] = 1;
    
pJailCount[playerid]--;
    new 
string[128],id;
    
format(stringsizeof(string), "%d"pJailCount[playerid]);
    
TextDrawSetString(Textdraw1string);
    
TextDrawShowForPlayer(playeridTextdraw3);
     
format(stringsizeof(string), "%d"MoneyFor[playerid]);
     
TextDrawSetString(Textdraw3string);
    
SetPlayerInterior(playerid3);
    
SetPlayerHealth(playerid10000000);
    
KillTimer(SendToJail[playerid]);
    
TextDrawShowForPlayer(playeridTextdraw0);
    
TextDrawShowForPlayer(playeridTextdraw1);
    
TextDrawShowForPlayer(playeridTextdraw2);
    
TextDrawShowForPlayer(playeridTextdraw3);
    
escaped[playerid] = 1;
    
escape(playerid);
    if(
pJailCount[playerid] == 0)
    {
        
BailPlayer[playerid] = 1;
        
OtherMenuBail[id] = 1;
        
SendClientMessage(playerid, -1"Jail Sentence served! Type {0080FF}/bail {FFFFFF}to get out.");
        
GameTextForPlayer(playerid"~B~/BAIL TO LEAVE ~R~JAILED"50005);
        
KillTimer(pJailTimerID[playerid]);
        
KillTimer(SendToJail[playerid]);
        
KillTimer(pJailCount[playerid]);
        return 
1;
    }
    return 
1;



CheezIt 08/09/2019 06:11 PM

Re: A Command..
 
You're placing "playerid" in places where "id" should be

saffierr 09/09/2019 02:07 AM

Re: A Command..
 
You might as well put this code under the 'new ....;' definitions.
PHP Code:

MoneyForBail[playerid] = random(7000) + 1000;
    
MoneyFor[playerid] = MoneyForBail[playerid]; 

Use 'MoneyForBail[id]' as CheezeIt mentioned.

RedRex 09/09/2019 05:07 PM

Re: A Command..
 
Look, I've do it.. I can bail myself but another player cannot pay the bail of my jail why?


PHP Code:

CMD:bail(playeridparams[])
{
    new 
idpName[MAX_PLAYER_NAME],tName[MAX_PLAYER_NAME],string[170];
    
MoneyForBail[playerid] = random(8000) + 1000


saffierr 09/09/2019 10:30 PM

Re: A Command..
 
If you would read what we've said...
Use 'MoneyForBail[id]' instead of 'MoneyForBail[playerid]'.


All times are GMT. The time now is 11:06 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.