SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 10/02/2019, 06:24 PM   #1
m4karow
Huge Clucker
 
Join Date: Oct 2015
Posts: 295
Reputation: 20
Default Selecting random vehicle with conditions

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
m4karow is offline   Reply With Quote
Old 10/02/2019, 09:56 PM   #2
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 867
Reputation: 43
Default Re: Selecting random vehicle with conditions

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.
__________________
here to help
Mugala is offline   Reply With Quote
Old 11/02/2019, 05:45 AM   #3
m4karow
Huge Clucker
 
Join Date: Oct 2015
Posts: 295
Reputation: 20
Default Re: Selecting random vehicle with conditions

Quote:
Originally Posted by Mugala View Post
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)) { ... }
m4karow is offline   Reply With Quote
Old 11/02/2019, 05:21 PM   #4
m4karow
Huge Clucker
 
Join Date: Oct 2015
Posts: 295
Reputation: 20
Default Re: Selecting random vehicle with conditions

bump
m4karow is offline   Reply With Quote
Old 11/02/2019, 07:47 PM   #5
TokicMajstor
Big Clucker
 
TokicMajstor's Avatar
 
Join Date: Oct 2018
Location: Bosnia And Herzegovina
Posts: 177
Reputation: 1
Default Re: Selecting random vehicle with conditions

Code:
new const Float:RandomCars[][] = 
{
// Random ids here
    {456}, // 0
    {478}, // 1
    {567}, // 2
}
__________________


If Iam better than you = you're noob
If you're better than me = you're cheater
If everyone is better than me = I have lags
#Logic
TokicMajstor is offline   Reply With Quote
Old 11/02/2019, 07:59 PM   #6
Freaksken
Huge Clucker
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 497
Reputation: 363
Default Re: Selecting random vehicle with conditions

Quote:
Originally Posted by TokicMajstor View Post
Code:
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, ...

Code:
new const RandomCars[] = {
    456,
    478,
    567
};
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work

Last edited by Freaksken; 12/02/2019 at 05:23 PM. Reason: Fixed stupid mistake, thnx DTV
Freaksken is offline   Reply With Quote
Old 11/02/2019, 09:04 PM   #7
TokicMajstor
Big Clucker
 
TokicMajstor's Avatar
 
Join Date: Oct 2018
Location: Bosnia And Herzegovina
Posts: 177
Reputation: 1
Default Re: Selecting random vehicle with conditions

Quote:
Originally Posted by Freaksken View Post
Uhm, what's the second array dimension for? These are not strings, ...

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


If Iam better than you = you're noob
If you're better than me = you're cheater
If everyone is better than me = I have lags
#Logic
TokicMajstor is offline   Reply With Quote
Old 12/02/2019, 02:46 AM   #8
DTV
Gangsta
 
DTV's Avatar
 
Join Date: Dec 2010
Posts: 545
Reputation: 125
Default Re: Selecting random vehicle with conditions

Quote:
Originally Posted by Freaksken View Post
Uhm, what's the second array dimension for? These are not strings, ...

Code:
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.
__________________

DTV is offline   Reply With Quote
Old 12/02/2019, 05:32 AM   #9
m4karow
Huge Clucker
 
Join Date: Oct 2015
Posts: 295
Reputation: 20
Default Re: Selecting random vehicle with conditions

Quote:
Originally Posted by ****** View Post
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.
m4karow is offline   Reply With Quote
Old 14/02/2019, 05:47 AM   #10
m4karow
Huge Clucker
 
Join Date: Oct 2015
Posts: 295
Reputation: 20
Default Re: Selecting random vehicle with conditions

bunp
m4karow is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting random player per round Pokemon64 Scripting Help 8 05/02/2017 03:43 PM
Selecting someone random from team XStreeter Scripting Help 12 16/12/2015 09:29 PM
selecting random online player Lukasz56 Scripting Help 1 07/11/2015 08:07 AM
[REP+]random bots when selecting on a menu niels44 Scripting Help 0 11/10/2012 05:42 PM
Random Selecting Numbers Kyle Help Archive 2 09/08/2010 02:11 PM


All times are GMT. The time now is 07:23 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.