Problem with Iterators - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with Iterators (
/showthread.php?tid=640914)
Problem with Iterators -
RedGun2015 - 09.09.2017
Hello, i try to use them for a jobid but i get this error
EDIT:
warning 203: symbol is never used: "Iter_Init@InJob"
use
Код:
new Iterator:InJob[16]<MAX_PLAYERS>;
Код:
if(PlayerInfo[playerid][pJob] > 0)
{
new jobid = PlayerInfo[playerid][pJob];
Iter_Add(InJob[jobid], playerid);
}
Can someone help me?
Re: Problem with Iterators -
Eoussama - 09.09.2017
Where is the error you mentioned?
Re: Problem with Iterators -
RedGun2015 - 09.09.2017
Quote:
Originally Posted by Eoussama
Where is the error you mentioned?
|
#edited in first post.
Re: Problem with Iterators -
Pottus - 09.09.2017
Your indexing is wack dude, seems to me you are overly thinking your problem with a dash of using the wrong kind of data usage.
You shouldn't need an iterator at all here it is pretty bad that people are giving you poor solutions to make your system design even worse.
Код:
enum JOBDATA
{
e_CurrJob,
e_Jobs[MAX_JOBS],
bool:e_InJob[MAX_JOBS],
}
static g_JobData[MAX_PLAYERS][JOBDATA];
Then just reference the data by playerid example.
Код:
if(g_JobData[playerid][e_InJob][g_JobData[playerid][e_CurrJob]])
{
}
Re: Problem with Iterators -
Eoussama - 09.09.2017
Not sure, but Try this
Код:
new
Iterator:OwnedVehicle[MAX_PLAYERS]<MAX_VEHICLES>;
Iter_Init(OwnedVehicle);
// Add vehicles to players here...
Iter_Add(OwnedVehicle[playerid], 42);
Iter_Add(OwnedVehicle[playerid], 43);
Iter_Add(OwnedVehicle[playerid], 44);
// Other code...
foreach (new vehicleid : OwnedVehicle[playerid])
{
printf("Player %d owns vehicle %d", playerid, vehicleid).
}
Use
Iter_Init(iterator_name) and see the results.
Source:
https://sampforum.blast.hk/showthread.php?tid=570937
The first method is a little bit insufficient as it uses lots of slots,
try this method:
PHP код:
Iterator:OwnedVehicles<MAX_PLAYERS, MAX_VEHICLES>;
Iterator:InJob<MAX_PLAYERS, 16>;
Re: Problem with Iterators -
RedGun2015 - 09.09.2017
Quote:
Originally Posted by Pottus
Your indexing is wack dude, seems to me you are overly thinking your problem with a dash of using the wrong kind of data usage.
You shouldn't need an iterator at all here.
Код:
enum JOBDATA
{
e_CurrJob,
e_Jobs[MAX_JOBS],
bool:e_InJob[MAX_JOBS],
}
static g_JobData[MAX_PLAYERS][JOBDATA];
Then just reference the data by playerid example.
Код:
if(g_JobData[playerid][e_InJob][g_JobData[playerid][e_CurrJob]])
{
}
|
I need the Iterator to search every single player that was added for applied for ex: for Job 14 (trucker) when they lost their Trailer to put attach back. This is what I'm trying to do. I have a timer for this and i need to search every single player that was added in Iterator.
Re: Problem with Iterators -
Pottus - 09.09.2017
You need to look here.
https://sampforum.blast.hk/showthread.php?tid=570937
Specifically Multi-Dimensional Iterators
But I still think you are overthinking and/or using some bad design choices.