07.11.2014, 16:09
hey guys whats up , as u know last tutorial was about commands but we really aint done , if u havent seen the previous thread you can see it through here : https://sampforum.blast.hk/showthread.php?tid=545161
So now we're going to make some vehicle cmds , lets start with /repair
so , now lets explain
This part detects wether if the player is in a vehicle or no , if(!IsPlayerInAnyVehicle) the *!* in this sentence means if the player is *NOT* in any vehicle , if we remove the *!* it means if the player is in a vehicle , and if he's not in a vehicle , it just returns this sentence (You're not in a vehicle) which means he cant repair
if & else are 2 important things which we use in scripting , if indicates a situation , if its true then whatever inside if happens , if its false and there's an *else* after it , then the else is true and the computer goes to else then and do what's inside it
RepairVehicle got a job , as well as SendClientMessage SetPlayerPos and SetPlayerHealth , its job is to repair vehicles , and GetPlayerVehicleID gets the vehicle's id which the player is in
now lets move for the 2nd cmd /FLIP
the IsPlayerInAnyVehicle here means if the player is *IN* a vehicle
now we created 2 new subjects , currentveh and angle (Note: angle is created as a float , thats why Float is before it)
currentveh = GetPlayerVehicleID(playerid); this line shows that currentveh is now the same as GetPlayerVehicleID(playerid)
GetVehicleZAngle(Currentveh, angle); ---- GetVehicleZAngle gets the Z angle of the vehicle ,and the currentveh here is acting aswell as the GetPlayerVehicleID cause we already said in code that currentveh = GetPlayerVehicleID(playerid); , and angle is the Float:angle we created up there with *new*
SetVehicleZAngle will set the vehicle's Z angle in the way u want , new Float:angle; means that the new subject (angle) is = 0 , so SetVehicleZAngle(currentveh,angle); currentveh gets the id of the vehicle the player is driving , angle is already = 0 so it'll set the vehicles Z angle to 0 , which means Up right again
the else here is related to the if(IsPlayerInAnyVehicle(playerid)) , condition (else) only becomes true when the if condition is false , which means if the player is not in a vehicle it'll go to condition else and do whats inside it (Send a message *You are not in a vehicle*)
now here's another interesting cmd (/NITRO)
now we created a new subject called (vehicleid) which will be used
vehicleid = GetPlayerVehicleID(playerid) is just the same is in /flip (currentveh)
AddVehicleComponent(vehicleid, 1010); AddVehicleComponent adds a new component to your vehicle , vehicleid is already defined what it means , on the line vehicleid = GetPlayerVehicleID(playerid);
1010 is the Nitro's id
well thats it for now , i'll be posting more whenever something comes in mind , if u r stuck on anything , msg me and i'll reply
Hope you enjoyed my tutorial
So now we're going to make some vehicle cmds , lets start with /repair
pawn Код:
if (strcmp("/repair", cmdtext,true)==0)
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You are not in a vehicle!");
else
{
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, COLOR_YELLOW, "Your vehicle has been repaired!");
}
return 1;
}
pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREEN, "You are not in a vehicle!");
pawn Код:
else
{
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, COLOR_YELLOW, "Your vehicle has been repaired!");
}
RepairVehicle got a job , as well as SendClientMessage SetPlayerPos and SetPlayerHealth , its job is to repair vehicles , and GetPlayerVehicleID gets the vehicle's id which the player is in
now lets move for the 2nd cmd /FLIP
pawn Код:
if(strcmp(cmdtext, "/flip", true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new currentveh;
new Float:angle;
currentveh = GetPlayerVehicleID(playerid);
GetVehicleZAngle(currentveh, angle);
SetVehicleZAngle(currentveh, angle);
SendClientMessage(playerid, COLOR_YELLOW, "Your vehicle has been flipped.");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREEN, "You are not in a vehicle!");
return 1;
}
}
pawn Код:
new currentveh;
new Float:angle;
pawn Код:
currentveh = GetPlayerVehicleID(playerid);
GetVehicleZAngle(currentveh, angle);
SetVehicleZAngle(currentveh, angle);
SendClientMessage(playerid, COLOR_YELLOW, "Your vehicle has been flipped.");
GetVehicleZAngle(Currentveh, angle); ---- GetVehicleZAngle gets the Z angle of the vehicle ,and the currentveh here is acting aswell as the GetPlayerVehicleID cause we already said in code that currentveh = GetPlayerVehicleID(playerid); , and angle is the Float:angle we created up there with *new*
SetVehicleZAngle will set the vehicle's Z angle in the way u want , new Float:angle; means that the new subject (angle) is = 0 , so SetVehicleZAngle(currentveh,angle); currentveh gets the id of the vehicle the player is driving , angle is already = 0 so it'll set the vehicles Z angle to 0 , which means Up right again
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
new currentveh;
new Float:angle;
currentveh = GetPlayerVehicleID(playerid);
GetVehicleZAngle(currentveh, angle);
SetVehicleZAngle(currentveh, angle);
SendClientMessage(playerid, COLOR_YELLOW, "Your vehicle has been flipped.");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREEN, "You are not in a vehicle!");
return 1;
}
now here's another interesting cmd (/NITRO)
pawn Код:
if(strcmp(cmdtext,"/Nitro",true)==0)
{
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
AddVehicleComponent(vehicleid, 1010);
SendClientMessage(playerid,COLOR_YELLOW,"You added NOS to your vehicle.");
return 1;
}
vehicleid = GetPlayerVehicleID(playerid) is just the same is in /flip (currentveh)
AddVehicleComponent(vehicleid, 1010); AddVehicleComponent adds a new component to your vehicle , vehicleid is already defined what it means , on the line vehicleid = GetPlayerVehicleID(playerid);
1010 is the Nitro's id
well thats it for now , i'll be posting more whenever something comes in mind , if u r stuck on anything , msg me and i'll reply
Hope you enjoyed my tutorial