PDA

View Full Version : OnPlayerEnter SPECIFIC/UNIQUE Vehicle


Adamoneoone
25/06/2018, 08:01 AM
Hey guys, as the titles says, I'm trying to make a system that will allow the player to do certain things (like starting a job or something else) but ONLY when he enters a specific vehicle on the map. For instance, if three bikes (like three NRG-500s) are spawned next to eachother, only the middle one will start a delivery job.
Thanks for your help!

0xDC143CAA
25/06/2018, 08:30 AM
You could perhaps try using "GetPlayerDistanceFromPoint(playerid, Float:X, Float:Y, Float:Z)" and if he is within distance from the point and in the vehicle model you want then the job starts.

Adamoneoone
25/06/2018, 08:31 AM
I would like to make it possible that the player can start the job anywhere he wants, as long as he is in the vehicle. A more appropriate example would be a Cheetah in which you can start the police job.

CodeStyle175
25/06/2018, 08:52 AM
new arrMissionVeh[3];
#define gVeh GetPlayerVehicleID

public OnGameModeInit(){
arrMissionVeh[0]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);
arrMissionVeh[1]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);
arrMissionVeh[2]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate){
new vid=gVeh(playerid);
if( oldstate==PLAYER_STATE_ONFOOT &&
newstate==PLAYER_STATE_DRIVER &&
vid==arrMissionVeh[1]){
//your mission code here
}
return 1;
}

Verc
25/06/2018, 09:00 AM
#define gVeh GetPlayerVehicleID
No,there's no point you redefine a function,****** has said it to you,why are you doing it again? This can cause a lot of confusion if you reopen your script in the future and etc.

Sew_Sumi
25/06/2018, 09:12 AM
No,there's no point you redefine a function,****** has said it to you,why are you doing it again? This can cause a lot of confusion if you reopen your script in the future and etc.

More that when people paste up his code as a fix, then ask "What's gVeh" and someone keeps throwing the stupid define about...

Pretty sure this all originated from whoever thought it was a good idea to abbreviate SendClientMessage to SCM... Stupidest shit ever, and only encourages laziness.

And even with that confusing if statement.... Jesus. Terribly inconsiderate of those who are just learning to script.

CodeStyle175
25/06/2018, 09:15 AM
Verc and Sew_Sumi is alex cole your father ors?
when defines are available why not use them?
its doesn't make your code slower in any way
and you don't need to be so nerdy programmers who really doesn't know how to code

Sew_Sumi
25/06/2018, 09:40 AM
Because defines do nothing...

And by throwing this practice up, even when you've been advised that it's not necessary, you're simply spreading bad coding practice...

and you don't need to be so nerdy programmers who really doesn't know how to code

And this just shows how bad you are at even explaining or debating anything... Seriously, you've been told why this isn't a good idea, and I even showed it...

After all, the amount of threads where people throw up code to people that has the SCM example in it, yet they don't include the SCM define, should show why this isn't a good idea to keep spreading this laziness...


It's LAZY... Like, jesus, most IDEs have autocompletion, so why go the extra step throwing in the define, when you could autocomplete, or even, 'shock horror' use a text replacement option in the IDE itself.


Again, it's bad, it's lazy, and it shows that you don't listen.

Adamoneoone
25/06/2018, 10:09 AM
Alright thanks for your help all! :)
Basically I have to do this?

new arrMissionVeh[3];

public OnGameModeInit(){
arrMissionVeh[0]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);
arrMissionVeh[1]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);
arrMissionVeh[2]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);
return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate){
if( oldstate==PLAYER_STATE_ONFOOT &&
newstate==PLAYER_STATE_DRIVER &&
GetPlayerVehicleID==arrMissionVeh[1]){
//your mission code here
}
return 1;
}

JasonRiggs
25/06/2018, 10:19 AM
Alright, let me sort this out for you..

First, You need to set a specific ID for the car, just like what a person gave you before, like..

arrMissionVeh[0]=CreateVehicle(522, 0.0, 0.0, 0.0,0.0, -1, -1, 60);

And then check if the player's vehicle is the same as this..

cmd:startjob(playerid, params[])
{
new vehicle = GetPlayerVehicleID(playerid);
if(vehicle != arrMissionVeh[0] && vehicle != arrMissionVeh[1] && vehicle != arrMissionVeh[3]) return SendClientMessage(playerid, COLOR_RED, "You are not in job's vehicle!");
//Add your job code here..
}

Sew_Sumi
25/06/2018, 11:19 AM
^^ This fella has the more simplified approach... No need for all the extra crud and confusing structure.

Adamoneoone
25/06/2018, 11:39 AM
Thanks a lot mates :) +rep for you