SA-MP Forums Archive
Making command only available on specific vehicle? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Making command only available on specific vehicle? (/showthread.php?tid=643021)



Making command only available on specific vehicle? - insus100 - 11.10.2017

Hello!
So I'm a noob on scripting, and I made a not optimized command to load drugs into the Bobcat (ID: 422)
This is the code:
The thing is that I want to make those commands (cargardroga and descargardroga) only available for one vehicle, in this case the Bobcat.


PHP код:
new drug1drug2drug3drug4drug5drug6drug7drug8drug9drug10drug11drug12drug13drug14drug15drug16drug17drug18drug19coche
PHP код:
    if(strcmp(cmdtext,"/cargardroga",true)==0)
    {
        
coche GetPlayerVehicleID(playerid);
        
drug1 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug2 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug3 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug4 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug5 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug6 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug7 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug8 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug9 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug10 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug11 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug12 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug13 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug14 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug15 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug16 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug17 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug18 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug19 CreateObject(1575,0,0,-1000,0,0,0,100);
        
AttachObjectToVehicle(drug1coche, -0.449999,-0.674999,-0.299999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug2coche, -0.449999,-0.974999,-0.299999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug3coche, -0.449999,-0.675000,-0.149999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug4coche, -0.449999,-0.974999,-0.149999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug5coche0.075000,-0.675000,-0.299999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug6coche0.599999,-0.675000,-0.299999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug7coche0.599999,-0.675000,-0.149999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug8coche0.599999,-0.974999,-0.299999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug9coche0.599999,-0.974999,-0.149999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug10coche0.075000,-0.675000,-0.149999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug11coche0.075000,-0.974999,-0.299999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug12coche0.075000,-0.974999,-0.149999,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug13coche0.075000,-0.600000,0.000000,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug14coche, -0.449999,-0.600000,0.000000,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug15coche0.599999,-0.600000,0.000000,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug16coche0.599999,-0.899999,0.000000,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug17coche0.075000,-0.899999,0.000000,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug18coche, -0.449999,-0.899999,0.000000,0.000000,0.000000,0.000000);
        
AttachObjectToVehicle(drug19coche, -0.449999,-1.350000,-0.149999,2.700001,35.100006,0.000000);
        return 
1;
    }
    if(
strcmp(cmdtext,"/descargardroga",true)==0)
    {
        
DestroyObject(drug1);
        
DestroyObject(drug2);
        
DestroyObject(drug3);
        
DestroyObject(drug4);
        
DestroyObject(drug5);
        
DestroyObject(drug6);
        
DestroyObject(drug7);
        
DestroyObject(drug8);
        
DestroyObject(drug9);
        
DestroyObject(drug10);
        
DestroyObject(drug11);
        
DestroyObject(drug12);
        
DestroyObject(drug13);
        
DestroyObject(drug14);
        
DestroyObject(drug15);
        
DestroyObject(drug16);
        
DestroyObject(drug17);
        
DestroyObject(drug18);
        
DestroyObject(drug19);
        return 
1;
    } 
I know it may hurt to see this, but I'm starting, thank you for your help.


Re: Making command only available on specific vehicle? - n00blek - 11.10.2017

put array for amount of vehicles you can put drugs in for example
define DRUG_CARS 69
new DrugCars[DRUG_CARS];
then you have to create vehicle like
DrugCars[0] = AddStaticVehicleEx(info of car); //Bobcat
....
DrugCars69] = AddStaticVehicleEx(info of car); //Bobcat this 69 is number of vehicle(69+0=70 strange math i know)
then when youre making command you must put in like if is vehicle DrugCars do this and if it isnt do this
get it?


Re: Making command only available on specific vehicle? - whadez - 11.10.2017

Quote:
Originally Posted by n00blek
Посмотреть сообщение
put array for amount of vehicles you can put drugs in for example
define DRUG_CARS 69
new DrugCars[DRUG_CARS];
then you have to create vehicle like
DrugCar[0] = AddStaticVehicleEx(info of car); //Bobcat
....
DrugCar[69] = AddStaticVehicleEx(info of car); //Bobcat this 69 is number of vehicle(69+0=70 strange math i know)
then when youre making command you must put in like if is vehicle DrugCars do this and if it isnt do this
get it?
Код:
new DrugCar[2];
DrugCar[0] = AddStaticVehicleEx(info of car); // 10
. // 11 
. // 12
. // 13
DrugCar[1] AddStaticVehicleEx(info of car); // 14

new i=(DrugCar[0]-1);
for(;++i<DrugCar[1];) {
printf("id - %i", i); // Will print from 10 to 14
}
Almost precized nooblek


Re: Making command only available on specific vehicle? - n00blek - 11.10.2017

xdddd


Re: Making command only available on specific vehicle? - Kraeror - 11.10.2017

You can do it using GetVehicleModel, but use it only if you want all bobcats to be with drug!
So here are the created variables: (just removed coche from them)
PHP код:
new drug1drug2drug3drug4drug5drug6drug7drug8drug9drug10drug11drug12drug13drug14drug15drug16drug17drug18drug19
And here are the commands:
PHP код:
    if(strcmp(cmdtext,"/cargardroga",true)==0)
    {
        
drug1 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug2 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug3 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug4 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug5 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug6 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug7 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug8 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug9 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug10 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug11 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug12 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug13 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug14 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug15 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug16 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug17 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug18 CreateObject(1575,0,0,-1000,0,0,0,100);
        
drug19 CreateObject(1575,0,0,-1000,0,0,0,100);
        for(new 
0<= MAX_VEHICLESv++)
        {
            if(
GetVehicleModel(v) == 422)
            {
                
AttachObjectToVehicle(drug1v, -0.449999,-0.674999,-0.299999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug2v, -0.449999,-0.974999,-0.299999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug3v, -0.449999,-0.675000,-0.149999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug4v, -0.449999,-0.974999,-0.149999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug5v0.075000,-0.675000,-0.299999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug6v0.599999,-0.675000,-0.299999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug7v0.599999,-0.675000,-0.149999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug8v0.599999,-0.974999,-0.299999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug9v0.599999,-0.974999,-0.149999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug10v0.075000,-0.675000,-0.149999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug11v0.075000,-0.974999,-0.299999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug12v0.075000,-0.974999,-0.149999,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug13v0.075000,-0.600000,0.000000,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug14v, -0.449999,-0.600000,0.000000,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug15v0.599999,-0.600000,0.000000,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug16v0.599999,-0.899999,0.000000,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug17v0.075000,-0.899999,0.000000,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug18v, -0.449999,-0.899999,0.000000,0.000000,0.000000,0.000000);
                
AttachObjectToVehicle(drug19v, -0.449999,-1.350000,-0.149999,2.700001,35.100006,0.000000);
            }
        }
        return 
1;
    }
    if(
strcmp(cmdtext,"/descargardroga",true)==0)
    {
        for(new 
0<= MAX_VEHICLESv++)
        {
            if(
GetVehicleModel(v) == 422)
            {
                
DestroyObject(drug1);
                
DestroyObject(drug2);
                
DestroyObject(drug3);
                
DestroyObject(drug4);
                
DestroyObject(drug5);
                
DestroyObject(drug6);
                
DestroyObject(drug7);
                
DestroyObject(drug8);
                
DestroyObject(drug9);
                
DestroyObject(drug10);
                
DestroyObject(drug11);
                
DestroyObject(drug12);
                
DestroyObject(drug13);
                
DestroyObject(drug14);
                
DestroyObject(drug15);
                
DestroyObject(drug16);
                
DestroyObject(drug17);
                
DestroyObject(drug18);
                
DestroyObject(drug19);
            }
        }
        return 
1;
    } 



Re: Making command only available on specific vehicle? - insus100 - 11.10.2017

After where should I put those codes? And with info of car you mean ID and coordinates?
If I spawn a car with a menu or whatever, will it be possible to work the same?
Thank you guys


Re: Making command only available on specific vehicle? - Kraeror - 11.10.2017

Quote:
Originally Posted by insus100
Посмотреть сообщение
After where should I put those codes? And with info of car you mean ID and coordinates?
If I spawn a car with a menu or whatever, will it be possible to work the same?
Thank you guys
My method should works if you are spawning the vehicle with command or whatever you want!
But before you type: /cargardroga the vehicle needs to be created!
+1 REP me if I helped


Re: Making command only available on specific vehicle? - n00blek - 11.10.2017

define DRUG_CARS 69
and
new DrugCars[DRUG_CARS];
put everywhere in script ABOVE COMMAND
new i=(DrugCar[0]-1);
for(;++i<DrugCar[1] {
printf("id - %i", i); // Will print from 10 to 14
}
is basicly in your command
and
DrugCar[0] = AddStaticVehicleEx(info of car); //Bobcat
must be in in OnGameModeInit


Re: Making command only available on specific vehicle? - insus100 - 11.10.2017

+1 Rep to all guys thx