PDA

View Full Version : Array / listitem not working


Prokill911
17/02/2015, 09:40 PM
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.


new Prisoners[MAX_PLAYERS];
CustomPickupsOnGameModeInit() {
paybail = CreateDynamicPickup(1314, 16, -1444.4275,2083.1318,1000.0859,20,20);
CustomPickupsOnPlayerPickupPickup(playerid, pickup) {
if(pickup == paybail) {
bailPlayer(playerid);
movePlayerBack(playerid, 1.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(msg, 128, "Prisoner: %s - Bail Price: $%d\n",GetPlayerNameEx(i, ENameType_RPName_NoMask), GetPVarInt(i, "Bail"));
strcat(dialogstr, msg, sizeof(dialogstr));
Prisoners[i]++;
}
ShowPlayerDialog(playerid, EFactionsDialog_PayingBail, DIALOG_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(playerid, X11_TOMATO_2, "You do not have enough money for bail!");
return 1;
}
GiveMoneyEx(playerid, -bailcost);
format(paidbail, sizeof(paidbail),"You have bailed %s out of jail bail, cost: $%d",GetPlayerNameEx(Prisoners[listitem], ENameType_RPName_NoMask), GetPVarInt(Prisoners[listitem], "Bail"));
format(bailreceived, sizeof(bailreceived),"Your bail has been paid by %s, bail cost: $%d",GetPlayerNameEx(playerid, ENameType_RPName_NoMask), GetPVarInt(Prisoners[listitem], "Bail"));
SendClientMessage(playerid, COLOR_GREEN, paidbail);
SendClientMessage(Prisoners[listitem], COLOR_GREEN, bailreceived);
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

Jefff
17/02/2015, 10:20 PM
Problem is in Prisoners[i]++;

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 bailfromjail(listitem); in case EFactionsDialog_PayingBail

Nero_3D
17/02/2015, 10:35 PM
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

Prokill911
17/02/2015, 11:48 PM
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.