Selecting random vehicle with conditions
#1

Hey there

I've making a new vehicle system that I have to implement to my mission system too.
What method do you recommend to select random vehicles for missions?

For example:

I use bitflags and there are some vehicles with flag TRAILERS.
How I can select random id from theese vehicles?

Thanks in advance
Reply
#2

dunno thing about bitflags, so is there a function in that bitflag which checks a vehicle if it's a trailer or not? for one vehicle.
Reply
#3

Quote:
Originally Posted by Mugala
Посмотреть сообщение
dunno thing about bitflags, so is there a function in that bitflag which checks a vehicle if it's a trailer or not? for one vehicle.
Yes. if(GetVehicleFlag(vehicleid, VEHICLE_FLAG_TRAILER)) { ... }
Reply
#4

bump
Reply
#5

Код:
new const Float:RandomCars[][] = 
{
// Random ids here
    {456}, // 0
    {478}, // 1
    {567}, // 2
}
Reply
#6

Quote:
Originally Posted by TokicMajstor
Посмотреть сообщение
Код:
new const Float:RandomCars[][] = 
{
// Random ids here
    {456}, // 0
    {478}, // 1
    {567}, // 2
}
Uhm, what's the second array dimension for? These are not strings, ...

Код:
new const RandomCars[] = {
    456,
    478,
    567
};
Reply
#7

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
Uhm, what's the second array dimension for? These are not strings, ...

Код:
new const Float:RandomCars[] = {
    456,
    478,
    567
};
I was just typing fast like how he can do "random" but anyway thanks for that
Reply
#8

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
Uhm, what's the second array dimension for? These are not strings, ...

Код:
new const Float:RandomCars[] = {
    456,
    478,
    567
};
Don't forget that vehicle ids aren't floats either, so no need to specify it as a float value.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Is every trailer a valid target? Does every trailer have that flag set? And if so, could you use the model ID instead? Regardless, you could add them to an iterator when creating them and use Iter_Random. The other code is either totally hard coded to IDs, which is a bad idea, or merely selects a model, not an instance.
Model id will doesn't matter becouse I'll set other type of flags for the missions (Vehicles that the player have to tow, stole, etc)

It will be easier if I can add theese vehicles to an iterator but the problem is what I said before. I've only can add theese "Mission vehicles" to an iterator like MissionVehicles where it will be faster to loop throught. But I won't able to select a random id with conditions.
Reply
#10

bunp
Reply
#11

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
I think you need a two phase system then. Loop through once to count the number of valid vehicles, select a random number in that range, then loop through again until you hit that number.
So there’s no any method. Maybe this will be fine. Thanks for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)