[Tutorial] Creating Car cmds
#1

In This Tutorial you will learn of to create zcmd and strcmp car cmds

ZCMD
First we are going to need our includes to do this
A samp is used for most of the basic callbacks of the server
CALLBACKS
Код:
This is an overview of all the callbacks available in SA:MP. Callbacks are called in the script by the server when something important happens, something closely related to the name of the callback (e.g. OnPlayerSpawn is called when a player spawns). Most callbacks have playerid as a parameter to indicate the player for whom the event occurred however not all do (as some aren't relevant to a player).

Important: When using these callbacks in a filterscript, make sure you return 1, so it's available in other filterscripts too. When you don't return a value or return 0, other callbacks in filterscripts loaded at a later time aren't executed.
Returning a value doesn't matter in OnFilterScriptInit and OnFilterScriptExit.
OnPlayerCommandText uses the opposite: 1 is indicating "command found" to all scripts, 0 will show "Unknown Command".

https://sampwiki.blast.hk/wiki/Category:Scripting_Callbacks <for more info
next we include zcmd this is a new way of creating commands faster
Код:
#include <a_samp>
#include <zcmd>
now onto the commands
We are gonna create command using cmd using
Код:
CMD:NAMEHERE(playerid,params[]
the params is like the text you want write in with the cmd...... We also use a open bracket to start the function
Код:
CMD:engine(playerid, params[])
{
now we are going to create a new for each of the vehicle parts and the vehicle id
vehicleid is to check to see is its a vehicle
the rest is the parts of the vehicles we can edit
Код:
new engine, lights, alarm, doors, bonnet, boot, objective, vehicleid;
Now we need to get the state of the player to ensure that he is the driver

!= means that if the player isnt the drive he cannot do it also you can add return to send player client message

the colour is white
Код:
if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFFFFFFAA, "You are not driving a vehicle.");
now we ensure the player is in a vehicle and also check the parts of the vehicle to ensure that they on or off
We need to get vehicle params

https://sampwiki.blast.hk/wiki/GetVehicleParamsEx <<<for more info
Код:
	vehicleid = GetPlayerVehicleID(playerid);
	GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
next where gonna check if engine is on or off !represents if it is 1 it would set to another you would see further down into tutorial
Код:
if(!engine)
Remeber we have vehicle id earlier when now we check to see if the player is in a vehicle and turn that vehicle engine on
https://sampwiki.blast.hk/wiki/SetVehicleParamsEx <<<<<<<< a little more info
and open and close curve brackets to support the if to say the if engine iz !engine =status then
true = on
false = off
Код:
{
 SetVehicleParamsEx(vehicleid, true, lights, alarm, doors, bonnet, boot, objective);
}
Now we are going to make a else to say that if the engine iz on then set it off
Код:
else
now we gonna do add if its on then we set it off
NB we use the curve bracks to keep the function with the if so the if this is one way we do this and else if use if its one way or isnt as what the script is suppose to read then do something else
Код:
{
 SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
}
now we are going to set a return value return 1; = true return 0; = false and thats the statement how you want to make a statement if a player does return 0; and does the given its isnt true and return 1; means if he does it, its true so it happens
Код:
return 1;
next we are going to close off the command by adding a curve brack inlined with the first one
Код:
}
Congratz you just did!
What You have Errors!
It is suppose to look something like this
Код:
CMD:engine(playerid, params[])
{
        new engine, lights, alarm, doors, bonnet, boot, objective, vehicleid;
	if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, 0xFFFFFFAA,, "You are not driving a vehicle.");
	vehicleid = GetPlayerVehicleID(playerid);
	GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	if(!engine)
	{
	    SetVehicleParamsEx(vehicleid, true, lights, alarm, doors, bonnet, boot, objective);

	}
	else
	{
	    SetVehicleParamsEx(vehicleid, false, lights, alarm, doors, bonnet, boot, objective);
	}
	return 1;
}
Now if you want to create one for lights,bonnet(hood),or boot(trunk)
Here is what you have to do
replace
with one of the parts above you should only do one params at a time to aviod errors
Код:
if(!nameofvehicleparams)
Also replace you going to have to change which one you want true and which one you one false
True = on
False = off
Код:
SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
IMPORTANTRemember you cannot have the cmd name
You ask what about alarm!
Well i havent fully understand alarm yet so that would be in a updated version of the tut

Now onto Vehicle lock
I explained y above
Код:
CMD:vlock(playerid, params[])
{
Now we are going to float are XYZ position float is to check ingame
for more info visit on XYZ position for we are gonna to have a (new)everything else was explained above
Код:
new engine, lights, alarm, doors, bonnet, boot, objective, vehicleid, Float:vx, Float:vy, Float:vz;
Well now we are gonna get the vehicle xyz position as shown in the new and see if player is in range on of it
playerid = the player
3 = range of how far player is more car like 4-6foot steeps
vx,vy,vz = to XYZ axis of the vehicle so the range can get its distance

MORE INFO
https://sampwiki.blast.hk/wiki/Function:GetVehiclePos
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint

Код:
GetVehiclePos(vehicleid, vx, vy, vz);
if(IsPlayerInRangeOfPoint(playerid, 3, vx, vy, vz))
Explained above
Код:
	 vehicleid = GetPlayerVehicleID(playerid);
	 GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	 if(!doors)
	 {
	    SetVehicleParamsEx(vehicleid, engine, lights, alarm, 1, bonnet, boot, objective);
	 }
	 else
	 {
	    SetVehicleParamsEx(vehicleid, engine, lights, alarm, 0, bonnet, boot, objective);
         }
	 return 1;
}
Yay you can now lock doors

Feature update how to make alarm and cool features for it
It would be in a different tutorial but the link would also be given here

Код:
Comment
post on my wall
Pm me
All fedback i would like to know how i did
Reply
#2

nice tutorial
Reply
#3

Bad tutorial, Organize your code, and the topic it is very messy.
Reply
#4

I admit it looks crazy but read along and you will understand..................... 1tut bad 1 2ndtut messy 3rd wait n see
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)