How can i limit an model?
#1

Hello guys,yesterday,with your support,i almost finished my dynamic dealership almost from scratch.
What i have to do now,i want to learn how to limit the models,like:
I want to be 10 infernus,when someone buys the tenth infernus,you can-t buy infernus anymore...so like 10 infernus on the hole server to be bought,and when the limit is reached,to stop the buy of infernus.
How can i doo it?I was thinking about a global variable and when the infernus is bought,to set that variable on +1 and then the limit [10 ] is reached,to stop the cmd but i dont actually know how.

Any tips are welcome.
Thanks in advance
Reply
#2

Does this limit get reset on server restarts/crashes?
Reply
#3

No,the limit its not made.ineed to make the limit but i do not know how.
Reply
#4

pawn Код:
native IsValidVehicle(vehicleid);

CountInfernuses()
{
    new
        vehiclecount = GetVehiclePoolSize(),
        count = 0;
    for(new i=0; i <= vehiclecount; i++)
    {
        if(!IsValidVehicle(i) || GetVehicleModel(i) != 411) continue;
        count ++;
    }
    return count;
}
Use this function to loop through all of the vehicles on the server. If the vehicle id is invalid or is not an infernus, it will skip over it, if the vehicle ID in the loop is an infernus, it will add 1 to the count. The function itself will return the number of Infernuses on the server to you.

Also, be sure to place the native at the top of your script, that's for checking if the vehicle id being looped over is valid.

You could do something like,
pawn Код:
if(CountInfernuses() > 9)
And do what you want to do from there.
Reply
#5

Ok,i got it but i have to adjust the CMD so i can make it easier,i can add if vehicleid is [cOwned]=1 so the count will go only on personal vehicles..i will try and come back.
Reply
#6

You'd want to save and declare a variable for how many vehicle slots are CURRENTLY avaliable, NO LOOPING IS NEEDED if you just want to limit the dealership stock:

e.g:

pawn Код:
new gStock[MAX_VEHICLE_MODELS][MAX_VEHICLE_DEALERSHIPS];

// when they buy it
if(gStock[vehiclemodel][dealership] == 0) return SendClientMessage(playerid, -1, "That item is not in stock.");

gStock[vehiclemodel][dealership]--;
However, if you only want 10 infernuses on the whole server you can either keep a variable or query MySQL to see if there are 10 rows / data selections.
Reply
#7

Quote:
Originally Posted by Abagail
Посмотреть сообщение
You'd want to save and declare a variable for how many vehicle slots are CURRENTLY avaliable, NO LOOPING IS NEEDED if you just want to limit the dealership stock:
e.g:
pawn Код:
new gStock[MAX_VEHICLE_MODELS][MAX_VEHICLE_DEALERSHIPS];
// when they buy it
if(gStock[vehiclemodel][dealership] == 0) return SendClientMessage(playerid, -1, "That item is not in stock.");
gStock[vehiclemodel][dealership]--;
However, if you only want 10 infernuses on the whole server you can either keep a variable or query MySQL to see if there are 10 rows / data selections.
This is a bit more logical than what I said, I'd go with it. What I made was simply a quick way to do it considering you posted no code.
Reply
#8

guys i am trying the second one but i dont really know how to do it.

si i-ve put new gInfernusStock[MAX_PLAYERS][InfernusNumbers]; on top of the script
and then i dont know how to continue,how to define the number of infernusnumbers..so ?
Reply
#9

delete this i misread op
Reply
#10

I tried the gStock one i and i get Array index out of bounds.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)