Choosing a vehicle model ID
#1

So I am creating this import system, similar to the Single Player. But I have no idea on how would I generate a random vehicle model ID (avoiding selecting an invalid ID, boat, planes, trains)

This is how I coded the Import System.

PHP код:
// Timer 
if(EIsystem[0][gBonusModel])
{
    if(!
EIsystem[0][gGotBonus])
    {
        
format(stringsizeof(string), "[EASTER BASIN]"white" %dx %s hasn't been imported to %s (There are %d still needed %s to get it shipped to %s)."EIsystem[0][gRequiredBonus], GetVehicleNameEx(EIsystem[0][gBonusModel]), EILocations[EIsystem[0][gAssignedLocation]], EIsystem[0][gRequiredBonus] - EIsystem[0][gDeliveredBonus], GetVehicleNameEx(EIsystem[0][gBonusModel]), EILocations[EIsystem[0][gAssignedLocation]]);
        if(!
closestdepot)
        {
            
SendClientMessage(playeridCOLOR_LIGHTGREENstring);
            
SendClientMessage(playerid"[SHIPMENT NOTICE]"white" A new required vehicle imports will arrive shortly, Please wait until furthermore notice.");
        }
        
        
printf("* The shipment of %s from Easter Basin to %s has been cancelled due to lack of %d more %s."GetVehicleNameEx(EIsystem[0][gBonusModel]), EILocations[EIsystem[0][gAssignedLocation]], EIsystem[0][gRequiredBonus] - EIsystem[0][gDeliveredBonus], GetVehicleNameEx(EIsystem[0][gBonusModel]));
        
EIsystem[0][gAssignedLocation] = -1;
        
EIsystem[0][gRequiredBonus] = 0;
        
EIsystem[0][gBonusModel] = 0;
        
EIsystem[0][gBonusMoney] = 0;
        
EIsystem[0][gDeliveredBonus] = 0;
    }
}
else
{
    if(!
closestdepot)
    {
        
EIsystem[0][gAssignedLocation] = random(sizeof(EIlocations));
        
EIsystem[0][gRequiredBonus] = Random(25);
        
EIsystem[0][gBonusModel] = 0;
        
EIsystem[0][gBonusMoney] = 0;
        
EIsystem[0][gDeliveredBonus] = 0;
    
        
format(stringsizeof(string), "[EASTER BASIN]"white" We need volunteers who will give away their %s, We current need %dx of them. ($%s overall reward pot)"GetVehicleNameEx(EIsystem[0][gBonusModel]), EIsystem[0][gRequiredBonus], AddComma(EIsystem[0][gBonusCash]));
        
SendClientMessage(playeridCOLOR_LIGHTGREENstring);
        
format(stringsizeof(string), "* The vehicles are to be imported to %s."EIsystem[0][gRequiredBonus]));
        
SendClientMessage(playerid, -1string);
    }

gBonusModel is where the vehicle model ID is stored.
Reply
#2

I think I know what you mean, maybe you could do like:

pawn Код:
stock RandomVehicle(vehicleid)
{
      switch(random(10))
      {
           case 0:
           {
           vehicleid = 560;
           }//Choose the vehicle id's you want to include
           case 1: // etc.
      }
}

RandomVehicle(EIsystem[0][gBonusModel]);
Just a quick idea, correct me if this wasn't what you meant
Reply
#3

I like the way how you did it but I have something more in mind like it would generate the ID (checking if it is a boat, plane or helicopter/train or if it is an invalid ID before processing it) but yeah I might use your code if none of the users responds.
Reply
#4

You could use random(211) + 400 to generate a model between 400 and 611 and check if the model is OK, if it's not then generate a new model. At least I understood that this is what you want. :P

Something like that I guess:
Код:
new model;

generate_model:
model = random(211) + 400;

if (model == 519) goto generate_model; //if the vehicle is Shamal (just an example) then generate a new model
Not sure if goto is good, because wiki says "The use of gotos is widely discouraged due to their effect on program flow."
Or you could do it like this:
Код:
new model = random(211) + 400;

while (modelid == 519) //it will keep generating a new model if the model is a Shamal
{
   model = random(211) + 400;
}
Reply
#5

I don't know if I'm right or if I misunderstood your idea:
PHP код:
stock IsACar(modelid)
{
    switch(
modelid)
    {
        case 
.. 400611 .. 1000,                                                                                         // Wrong vehicle ID
        
417425447460469476487488497511 .. 513519520548553563577592593,                    // Plane & Helicopters
        
430446452453454472473484483595,                                                                    // Boats
        
435441449450464465501537538539545564569 .. 572583584590591594606607608610 : return false// Others (RC, trailer, etc..)
        
default : return true;
    }
    return 
true;
}
GetRandomModelCar(vehicleid)
{
    static 
a;
    do
    {
        
random(211) + 400
    }
    while(!
IsACar(a));
    return 
a;

Reply
#6

Well try these codes, Thank you @Dayrion and @GoldenLion
Reply
#7

Aight, Since this is still about the model ID thingy. I am gonna post it down here.
For some reason, this won't work

PHP код:
new VehicleNames[212][] = {
    {
"Landstalker"},{"Bravura"},{"Buffalo"},{"Linerunner"},{"Perrenial"},{"Sentinel"},{"Dumper"},
    {
"Firetruck"},{"Trashmaster"},{"Stretch"},{"Manana"},{"Infernus"},{"Voodoo"},{"Pony"},{"Mule"},
    {
"Cheetah"},{"Ambulance"},{"Leviathan"},{"Moonbeam"},{"Esperanto"},{"Taxi"},{"Washington"},
    {
"Bobcat"},{"Mr Whoopee"},{"BF Injection"},{"Hunter"},{"Premier"},{"Enforcer"},{"Securicar"},
    {
"Banshee"},{"Predator"},{"Bus"},{"Rhino"},{"Barracks"},{"Hotknife"},{"Trailer 1"},{"Previon"},
    {
"Coach"},{"Cabbie"},{"Stallion"},{"Rumpo"},{"RC Bandit"},{"Romero"},{"Packer"},{"Monster"},
    {
"Admiral"},{"Squalo"},{"Seasparrow"},{"Pizzaboy"},{"Tram"},{"Trailer 2"},{"Turismo"},
    {
"Speeder"},{"Reefer"},{"Tropic"},{"Flatbed"},{"Yankee"},{"Caddy"},{"Solair"},{"Berkley's RC Van"},
    {
"Skimmer"},{"PCJ-600"},{"Faggio"},{"Freeway"},{"RC Baron"},{"RC Raider"},{"Glendale"},{"Oceanic"},
    {
"Sanchez"},{"Sparrow"},{"Patriot"},{"Quad"},{"Coastguard"},{"Dinghy"},{"Hermes"},{"Sabre"},
    {
"Rustler"},{"ZR-350"},{"Walton"},{"Regina"},{"Comet"},{"BMX"},{"Burrito"},{"Camper"},{"Marquis"},
    {
"Baggage"},{"Dozer"},{"Maverick"},{"News Chopper"},{"Rancher"},{"FBI Rancher"},{"Virgo"},{"Greenwood"},
    {
"Jetmax"},{"Hotring"},{"Sandking"},{"Blista Compact"},{"Police Maverick"},{"Boxville"},{"Benson"},
    {
"Mesa"},{"RC Goblin"},{"Hotring Racer A"},{"Hotring Racer B"},{"Bloodring Banger"},{"Rancher"},
    {
"Super GT"},{"Elegant"},{"Journey"},{"Bike"},{"Mountain Bike"},{"Beagle"},{"Cropdust"},{"Stunt"},
    {
"Tanker"}, {"Roadtrain"},{"Nebula"},{"Majestic"},{"Buccaneer"},{"Shamal"},{"Hydra"},{"FCR-900"},
    {
"NRG-500"},{"HPV1000"},{"Cement Truck"},{"Tow Truck"},{"Fortune"},{"Cadrona"},{"FBI Truck"},
    {
"Willard"},{"Forklift"},{"Tractor"},{"Combine"},{"Feltzer"},{"Remington"},{"Slamvan"},
    {
"Blade"},{"Freight"},{"Streak"},{"Vortex"},{"Vincent"},{"Bullet"},{"Clover"},{"Sadler"},
    {
"Firetruck LA"},{"Hustler"},{"Intruder"},{"Primo"},{"Cargobob"},{"Tampa"},{"Sunrise"},{"Merit"},
    {
"Utility"},{"Nevada"},{"Yosemite"},{"Windsor"},{"Monster A"},{"Monster B"},{"Uranus"},{"Jester"},
    {
"Sultan"},{"Stratum"},{"Elegy"},{"Raindance"},{"RC Tiger"},{"Flash"},{"Tahoma"},{"Savanna"},
    {
"Bandito"},{"Freight Flat"},{"Streak Carriage"},{"Kart"},{"Mower"},{"Duneride"},{"Sweeper"},
    {
"Broadway"},{"Tornado"},{"AT-400"},{"DFT-30"},{"Huntley"},{"Stafford"},{"BF-400"},{"Newsvan"},
    {
"Tug"},{"Trailer 3"},{"Emperor"},{"Wayfarer"},{"Euros"},{"Hotdog"},{"Club"},{"Freight Carriage"},
    {
"Trailer 3"},{"Andromada"},{"Dodo"},{"RC Cam"},{"Launch"},{"Police Car (LSPD)"},{"Police Car (SFPD)"},
    {
"Police Car (LVPD)"},{"Police Ranger"},{"Picador"},{"S.W.A.T. Van"},{"Alpha"},{"Phoenix"},{"Glendale"},
    {
"Sadler"},{"Luggage Trailer A"},{"Luggage Trailer B"},{"Stair Trailer"},{"Boxville"},{"Farm Plow"},
    {
"Utility Trailer"}
};

// Debug Command

CMD:research(playeridparams[])
{
    new 
string[128];

    
EIsystem[1][gAssignedLocation] = random(2);
    
EIsystem[1][gRequiredBonus] = Random(25);
    
EIsystem[1][gBonusModel] = GetRandomModelCar();

    switch(
EIsystem[1][gRequiredBonus])
    {
        case 
2EIsystem[1][gBonusCash] = 10000;
        case 
3EIsystem[1][gBonusCash] = 15000;
        case 
4EIsystem[1][gBonusCash] = 20000;
        case 
5EIsystem[1][gBonusCash] = 25000;
    }

    
EIsystem[1][gDeliveredBonus] = 0;

    
format(stringsizeof(string), "[OCEAN DOCKS]"white" We are current looking for %dx %s which is to be imported @ %s ($%s overall reward pot)"EIsystem[1][gRequiredBonus], VehicleNames[EIsystem[1][gBonusModel]-400], EIlocations[EIsystem[1][gAssignedLocation]], AddComma(EIsystem[1][gBonusCash]));
    
SendClientMessage(playeridCOLOR_LIGHTGREENstring);
    return 
1;

The output is;

Код:
[OCEAN DOCKS]{FFFFFF} We are current looking for 4x 8Liberty City which is to be imported @ Vice City ($20,000 overall reward pot)
Reply
#8

I tested the code there seems to be no problem with the code.
Make sure you are using the code given by Dayrion

Other problem that i can think of is that maybe by mistake you defined EIsystem[1][gBonusModel] as a string or something else but then again that would have given a error/warning while compilation of script, so make sure that there is no such warning.

Try printing the vehicle id returned directly too along with other things.
Reply
#9

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
wiki says "The use of gotos is widely discouraged due to their effect on program flow."
Because it can be replaced with do-while in a lot of cases. The main difference between while and do-while being that do-while always executes at least once because the comparison comes after the loop.

PHP код:
new randModelguard;
do
{
    
randModel minrandom(400611);
}
while(!
isACar(randModel) && ++guard 100); 
Something like that. The "guard" is there so the loop doesn't run potentially infinitely.
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
Because it can be replaced with do-while in a lot of cases. The main difference between while and do-while being that do-while always executes at least once because the comparison comes after the loop.

PHP код:
new randModelguard;
do
{
    
randModel minrandom(400611);
}
while(!
isACar(randModel) && ++guard 100); 
Something like that. The "guard" is there so the loop doesn't run potentially infinitely.
Thank you for explaining. :P
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)