Array / listitem not working
#1

hello, so earlier I made a thread about listitems someone said to array it, so I did...

Here's my code..
But It still returns listitem value 0 eaech time.

so if I had 30 people in the server, an 10 of them are jailed, If ID 10 is jailed, an you try an unjail him, It will just unjail id 0 each time, Never unjailing anything above ID 0.

PHP код:
new Prisoners[MAX_PLAYERS];
CustomPickupsOnGameModeInit() {
    
paybail CreateDynamicPickup(131416, -1444.4275,2083.1318,1000.0859,20,20);
CustomPickupsOnPlayerPickupPickup(playeridpickup) {
    if(
pickup == paybail) {
        
bailPlayer(playerid);
        
movePlayerBack(playerid1.5);
    }
}
bailPlayer(playerid) {
    new 
msg[128];
    
dialogstr[0] = 0;
    for(new 
i=0;i<MAX_PLAYERS;i++) {
        if(
IsPlayerConnectEx(i)) {
            new 
jailtime GetPVarInt(i"ReleaseTime");
            
jailtime -= gettime();
            if(
jailtime 0) {
                
format(msg128"Prisoner: %s - Bail Price: $%d\n",GetPlayerNameEx(iENameType_RPName_NoMask), GetPVarInt(i"Bail"));
                
strcat(dialogstrmsgsizeof(dialogstr));
                
Prisoners[i]++;
            }
            
ShowPlayerDialog(playeridEFactionsDialog_PayingBailDIALOG_STYLE_LIST"List of prisoners."dialogstr"Pay Bail""Cancel");
        }
    }
    return 
1;
}
case 
EFactionsDialog_PayingBail: {
            if(
response) {        
                new 
paidbail[256];
                new 
bailreceived[256];
                new 
bailcost GetPVarInt(Prisoners[listitem], "Bail");
                new 
money GetPVarInt(playerid"Money");
                if(
money bailcost) { 
                    
SendClientMessage(playeridX11_TOMATO_2"You do not have enough money for bail!");
                    return 
1;
                }
                
GiveMoneyEx(playerid, -bailcost);                
                
format(paidbailsizeof(paidbail),"You have bailed %s out of jail bail, cost: $%d",GetPlayerNameEx(Prisoners[listitem], ENameType_RPName_NoMask), GetPVarInt(Prisoners[listitem], "Bail"));
                
format(bailreceivedsizeof(bailreceived),"Your bail has been paid  by %s, bail cost: $%d",GetPlayerNameEx(playeridENameType_RPName_NoMask), GetPVarInt(Prisoners[listitem], "Bail"));
                
SendClientMessage(playeridCOLOR_GREENpaidbail);
                
SendClientMessage(Prisoners[listitem], COLOR_GREENbailreceived);
                
bailfromjail(Prisoners[listitem]);                
                return 
1;
            }
        }
bailfromjail(listitem) {    
    
releaseFromJail(Prisoners[listitem]);                    
    
DeletePVar(Prisoners[listitem], "ReleaseTime");
    return 
1;

Can anyone show me where I've gone wrong.. I seriously can't figure this out an it's annoying please help
Reply
#2

Problem is in Prisoners[i]++;

pawn Код:
bailPlayer(playerid)
{
    new msg[128],count;
    dialogstr[0] = 0;
    for(new prisoner_id=0; prisoner_id < MAX_PLAYERS; prisoner_id++)
        if(IsPlayerConnectEx(prisoner_id))
        {
            new jailtime = GetPVarInt(prisoner_id, "ReleaseTime");
            jailtime -= gettime();
            if(jailtime > 0)
            {
                format(msg, sizeof(msg), "Prisoner: %s - Bail Price: $%d\n",GetPlayerNameEx(prisoner_id, ENameType_RPName_NoMask), GetPVarInt(prisoner_id, "Bail"));
                strcat(dialogstr, msg);
                Prisoners[count++] = prisoner_id; // storing an ID
            }
        }

    if(count == 0) SendClientMessage(playerid, X11_TOMATO_2, "0 prisoners");
    else ShowPlayerDialog(playerid, EFactionsDialog_PayingBail, DIALOG_STYLE_LIST, "List of prisoners.", dialogstr, "Pay Bail", "Cancel");
    return 1;
}
and change to
pawn Код:
bailfromjail(listitem);
in case EFactionsDialog_PayingBail
Reply
#3

You should consider to change the array into a player array because the prisoners can change while the dialog was up

Therefor you should also check if the prisoner is still connected or is still a prisoner in OnDialogResponse
Reply
#4

Thanks for those who replied.

I did what you suggested, works now as far as I can see, wont know if it fully works till I put it in the main server with 30+ People on.
Also, It regenerates the list each time someone steps on it, So that should solve people "Logging" out when being bailed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)