08.11.2011, 18:07
(
Last edited by FireCat; 11/11/2012 at 05:58 PM.
)
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>
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;
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;
}
Good luck.
-Firecat