How to make a enum expand?
#1

Hello,

i am wondering if its possible to have a expanding index with enums.. the reason for this is because this is what im trying to do:

---
I am making a car ownership system with mysql and i plan to store the cars in a enum. In the server each player can have up to 5 cars which they own, although they can only have a maximum of 1 car spawned at a time (Or they can have 0 cars spawned..and have them all "parked")... I want to store the cars in a enum like "CarStats[carid][cStat]" or maybe "CarStats[playerid][cStat]", i think the second one would work... however i want to make it so if you dont park you car (despawn it) before u log out, your car will stay there... so this rules out the [playerid] section...so i need to use carid? Now the carid would probably depend on which ones are taken already, so when i load the car into the script, i would do like:

pawn Код:
new carid;
for(new i = 0; i<INDEX_SIZE_OF_ENUM; i++){
     if(CarStats[i][cModel] == 0){  carid = i; continue; }
}
So now i would know this enum is free and i would put all the data into there...

But now, i am at a dilemma for what size the enum should be.... I dont want to make it huge because it would mean that is wasted space.. and if its too small then it mean eventually a car will try to spawn but there would be no free spaces! so..if i cant expand the size of it.. the only option would be to do this..

pawn Код:
new carid;
carid = 9999;
for(new i = 0; i<INDEX_SIZE_OF_ENUM; i++){
     if(CarStats[i][cModel] == 0){  carid = i; continue; }
}
if(carid == 9999) return SendClientMessage(playerid, COLOR, "Server cannot support any more vehicles..pleas try again later");
Does anyone know what i can do here?
---
Reply
#2

I don't really understand what you mean by expanding enum index. Do you mean the array size? Like..
pawn Код:
enum SomeEnum{}
new Array[12][SomeEnum];
Would become
pawn Код:
enum SomeEnum{}
new Array[13][SomeEnum];
For this I would recommend ******'s "foreach" include. And use iterators instead of enums.

I'm not sure. But I believe it is not possible to change a size of array, once created.
Reply
#3

Ill look into that, thanks.. ill revive this thread in the future if i need help
Reply
#4

okay, so i looked into Iterators and it looks like what i need.. But i just need to know if i can use it like a enum? So each its like:
pawn Код:
new Iterator:iter<10><cStat>
Im pretty sure thats not valid code, but thats the kind of thing im looking for..

Then this would mean that when i spawn a new car that someone owns i can use foreach to check if all the current slots (<10>) are taken by checking the the cModel variable is equal to 0 (will be the default) and if none are free, it adds a new slot into the Iterator..

Thats what i need, not sure how to do it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)