23.08.2014, 06:35
Introduction
Hello Everyone, i am DarkSkull, and this is my first ever Tutorial. In this tutorial we will be creating a vehicle repair system where when pressed a button, it will repair the vehicle for you.
P.S: I am a Newbie, So please forgive if i make any mistakes.
So, Let's get started.!
Assigning a Key
We want to make it so that when the player presses the button, we will trigger the function.
So to make that work, we will use the OnPlayerKeyStateChange() function.
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
Scripting the Function
Now, Let's get started on the function itself. So, we want to check if the player press our key, So,
PHP код:
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)){
}
PHP код:
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)){
if(IsPlayerInAnyVehicle(playerid)){
}
}
PHP код:
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)){
if(IsPlayerInAnyVehicle(playerid)){
RepairVehicle(GetPlayerVehicleID(playerid));
}
}
More Stuffs
If you want, you can even send a message and play a sound, when the vehicle is being repaired like so.
PHP код:
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)){
if(IsPlayerInAnyVehicle(playerid)){
RepairVehicle(GetPlayerVehicleID(playerid));
PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
SendClientMessage(playerid, 0x33AA33AA, "[INFO]: Your vehicle has been repaired");
}
}
PHP код:
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)){
if(IsPlayerInAnyVehicle(playerid)){
RepairVehicle(GetPlayerVehicleID(playerid));
PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
SendClientMessage(playerid, 0x33AA33AA, "[INFO]: Your vehicle has been repaired");
}else {
SendClientMessage(playerid, 0xFF0000FF, "[ERROR: You're not in a vehicle]");
}
}
Final Tutorial Code
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION)){
if(IsPlayerInAnyVehicle(playerid)){
RepairVehicle(GetPlayerVehicleID(playerid));
}
}
return 1;
}
If you want to read more about OnPlayerKeyStateChange(), then check out the Wiki.
Credits
SA:MP Wiki - OnPlayerKeyStateChange()
SA:MP Wiki - SoundID