[Tutorial] Creating /s and /l commands
#1

Brief speech
Hello fellow learns (or Calgon & [HiC]Thekiller)
I'll be teaching you how to make the commands /s and /l.
/s will stand for save
/l will stand for load.
So you can simply /s so you won't lose your current position and then later on /l

Creating the necessary stuff
First of all lets include the samp "include"
pawn Code:
#include <a_samp>
Under that, lets create our vars.
pawn Code:
enum PlayerPosition
{
Float:XPos,//Creating the x array. In a float, because it's the x position.
Float:YPos,//Creating the y array. In a float, because it's the z position.
Float:ZPos,//Creating the z array. In a float, because it's the z position.
Float:PAngle,//Creating the PAngle array. In a float, because it's the angle.
SavedPosition//It's just a simply int array. So we can check if the player has already /s, so he won't go to 0,0,0
}
new PPosition[MAX_PLAYERS][PlayerPosition];//Instead of creating indevidualy all the vars, lets just create them all in 1. Thats why we created that enum.

So now under OnPlayerConnect add this:
pawn Code:
PPosition[playerid][SavedPosition] = 0;
That is setting SavedPosition to 0, so when you do /l you won't go to the last player's position nor to 0,0,0.

Creating the commands
Ok now the most importante step.
Creating the commands.
So in your command processor (we will use the common strcmp even tho it's not a command processor) add the following:

pawn Code:
if(strcmp(cmdtext,"/s") == 0) //Comparing the command string to /s and checking if they match
{
new Float:x,Float:y,Float:z,Float:angle;//Creating the vars, so we can store our info.
if(IsPlayerInAnyVehicle(playerid))//Checking if the player is in any vehicle, so we can retrieve the vehicle's position
{
GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);//Storing the vehicle's position into x,y,z;
GetVehicleZAngle(GetPlayerVehicleID(playerid),angl e);//Storing the vehicle's angle to "angle".
PPosition[playerid][XPos] = x;//Storing the x value to XPos array, where we previously created.
PPosition[playerid][YPos] = y;//Storing the y value to YPos array, where we previously created.
PPosition[playerid][ZPos] = z;//Storing the z value to ZPos array, where we previously created.
PPosition[playerid][PAngle] = angle;//Storing the angle value to PAngle array, where we previously created.
SendClientMessage(playerid,-1,"Position saved! Type /l to load!");
}
else
{
GetPlayerPos(playerid,x,y,z);//Storing the player's position into x,y,z;
GetPlayerFacingAngle(playerid,angle);//Storing the player's angle to "angle".
PPosition[playerid][XPos] = x;//Storing the x value to XPos array, where we previously created.
PPosition[playerid][YPos] = y;//Storing the y value to YPos array, where we previously created.
PPosition[playerid][ZPos] = z;//Storing the z value to ZPos array, where we previously created.
PPosition[playerid][PAngle] = angle;//Storing the angle value to PAngle array, where we previously created.
SendClientMessage(playerid,-1,"Position saved! Type /l to load!");
}
PPosition[playerid][SavedPosition] = 1;
return 1;
}
if(strcmp(cmdtext,"/l") == 0)
{
if(PPosition[playerid][SavedPosition] == 0) return SendClientMessage(playerid,-1,"You don't have any position saved! (/s)");
if(IsPlayerInAnyVehicle(playerid))//Checking if the player is in any vehicle, so we can retrieve the vehicle's position
{
SetVehiclePos(GetPlayerVehicleID(playerid),PPositi on[playerid][XPos],PPosition[playerid][YPos],PPosition[playerid][ZPos]);//Setting the vehicle's position with the stored one.
SetVehicleZAngle(GetPlayerVehicleID(playerid),PPos ition[playerid][PAngle]);//Setting the vehicle's Z angle with the stored one.
SendClientMessage(playerid,-1,"Position loaded!");
}
else
{
SetPlayerPos(playerid,PPosition[playerid][XPos],PPosition[playerid][YPos],PPosition[playerid][ZPos]);//Setting the player's position with the stored one.
SetPlayerFacingAngle(playerid,PPosition[playerid][PAngle]);//Setting the player's facing angle with the stored one.
SendClientMessage(playerid,-1,"Position loaded!");
}
return 1;
}
If you compiled and no errors came up, then try it in game! (:
Good luck.
-Firecat
Reply
#2

Simple but Nice!
Good Job
Reply
#3

Quote:
Originally Posted by Kostas'
View Post
Simple but Nice!
Good Job
Lol thanks!
Reply
#4

Useful for beginners.

Good Job.
Reply
#5

Good work.
Reply
#6

Simple, but hard;
P.S.: I just found out that you're a fucking krawd; Would you stop lying to me?!?!
Reply
#7

Thanks all!

Quote:
Originally Posted by [MWR]Blood
View Post
Simple, but hard;
P.S.: I just found out that you're a fucking krawd; Would you stop lying to me?!?!
Gtfo prawd :>:>:>:>:>
(Small joke of ours)
Reply
#8

Quote:
Originally Posted by FireCat
View Post
Thanks all!



Gtfo prawd :>:>:>:>:>
(Small joke of ours)
Joke? What the fuck are you talking about?! Post reported...






Joking :>
Reply
#9

Hey please don't go off topic..
Reply
#10

Sorry for not being first, but good job! I still want to see the goats...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)