/setloc and /teleport
#1

Hey guys, i need help, how i am enable to make these two commands? /Setloc gets the players position and saves it to global /teleport command and than if player writes /teleport it teleports him to the position, which was saved when /setloc was written, thanks.
Reply
#2

Can use this

https://sampwiki.blast.hk/wiki/SetPlayerPos
Reply
#3

are you mean /spos , /lspos?
spos : save play Loction
lspos : back to your loction
Reply
#4

Okay, first you have to think how is it going to work.


How do I get a player's coordinates?
Код:
GetPlayerPos(playerid,floatX,floatY,FloatZ);
Now, this is the main function you're going to use - it will eventually drag you to the whole system.

I got that function now, how do I actually store the particular values?
Код:
// The coordinates (X,Y,Z) are floats, therefore we will need variables. Variables to store the floats inside.
// What are you going to use? An array, an array is like a box made of columns and rows; For the sake of an example, we'll say that the max /teleports server can hold is 100, therefore:

enum someRandomEnum
{
Float:x, 
Float:y,
Float:z,
bool:teleport
}
new T[100][someRandomEnum]; // Remember when I've mentioned they are going to be 100? Here we use it.
/* Now what is this? 
This means, there are going to be 100 columns every one of them will have the following variables:
X
Y
Z
teleport (boolean)

The X is to collect the X coordinate
The Y is to collect the Y coordinate
The Z is to collect the Z coordinate
The teleport boolean is to see whether the teleport is available or not (for later usage)
*/
Now, you think of it as you got variables and you'll play with them. Create your commands to set the values, do what you want to do.

I'll provide you a short example, I will assume you're using Zeek's command processor (ZCMD) and sscanf.
Код:
CMD:createtp(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return 0; // Checking if the player has the authority.
new Float:x,Float:y,Float:z,id;
GetPlayerPos(playerid,x,y,z);
for(new i = 0; i < 100; i ++)
{
    if(T[i][teleport] != true)
    {
     id = i;
     break;
     }
}
// What we did up there is basically obtain a free teleport ID, so then it wont conflict with eachother.
// Now we got the ID we're going to use, got our coordinates and everything we need. Our task is finished, all we need to do now is insert the values into our correct variables.
T[id][x] = x;
T[id][y] = y;
T[id][z] = z;
T[id][teleport] = true; // Assigning this boolean to true so then it won't be detected as an unused teleport. 
SendClientMessage(playerid,-1,"SERVER: You have created a teleport point.");
return 1;
}
CMD:teleport(playerid,params[])
{
new id;
if(sscanf(params,"u",id)) return SendClientMessage(playerid,-1,"SERVER: /teleport [teleport_id]");// Self explanatory.
if(T[id][teleport] != true) return SendClientMessage(playerid,-1,"SERVER: Invalid teleport point."); // Self explanatory.
SetPlayerPos(playerid,T[id][x],T[id][y],T[id][z]); // Teleporting the player to the point.
return 1; // Make sure to return a 1 otherwise you'll recieve "Unknown Command" by the server.
}
Reply
#5

You can also do it with PVars
Код:
CMD:savepos(playerid, params[])
{
	GetPlayerPos(playerid, c2[0], c2[1], c2[2]);
	GetPlayerFacingAngle(playerid, c2[3]);
	SetPVarFloat(playerid, "sp-X", c2[0]);
	SetPVarFloat(playerid, "sp-Y", c2[1]);
	SetPVarFloat(playerid, "sp-Z", c2[2]);
	SetPVarFloat(playerid, "sp-Angle", c2[3]);
	SendClientMessage(playerid, -1, "Position saved.");
	return 1;
}

CMD:loadpos(playerid, params[])
{
	if(GetPVarFloat(playerid, "sp-X") == 0.0 && GetPVarFloat(playerid, "sp-Y") == 0.0 && GetPVarFloat(playerid, "sp-Z") == 0.0)
	    return SendClientMessage(playerid, -1, "You need to save your position first!");
	SetPlayerPos(playerid, GetPVarFloat(playerid, "sp-X"), GetPVarFloat(playerid, "sp-Y"), GetPVarFloat(playerid, "sp-Z"));
	SetPlayerFacingAngle(playerid, GetPVarFloat(playerid, "sp-Angle"));
    SendClientMessage(playerid, -1, "Teleported!");
    return 1;
}
Reply
#6

COMMANDetloc(playerid, params[])
{
if (IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] > 0){

if (PlayerInfo[playerid][pSpawn] == 1){
if (!IsPlayerInAnyVehicle(playerid))
{
new Float:X, Float:Y, Float:Z, Float:A,Interior,World;

GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
Interior = GetPlayerInterior(playerid);
World = GetPlayerVirtualWorld(playerid);

PlayerInfo[playerid][pAdminLastX] = X;
PlayerInfo[playerid][pAdminLastY] = Y;
PlayerInfo[playerid][pAdminLastZ] = Z;
PlayerInfo[playerid][pAdminLastA] = A;
PlayerInfo[playerid][pAdminLastI] = Interior;
PlayerInfo[playerid][pAdminLastW] = World;

SendClientMessage(playerid,COLOR_ADMIN, "Your Last Location Has Been Saved.");

}else{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command From Inside A Vehicle.");
}

}else{
SendClientMessage(playerid, COLOR_ERROR, "You Need To Spawn Before Using This Command.");
}

}else{
SendClientMessage(playerid, COLOR_ERROR, "Unknown Command! Type /cmds For Available Commands.");
}
return 1;
}

COMMAND:teletoloc(playerid, params[])
{
if (IsPlayerAdmin(playerid) || PlayerInfo[playerid][pAdminLevel] > 0){

if (PlayerInfo[playerid][pSpawn] == 1){


if (PlayerInfo[playerid][pJailed] == 1)
{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Teleport When Your In Jail.");
return 1;
}


if (!IsPlayerInAnyVehicle(playerid))
{

SendClientMessage(playerid,COLOR_ADMIN, "You Teleported To Your Saved Location.");
SetPlayerPosEx(playerid,PlayerInfo[playerid][pAdminLastX],PlayerInfo[playerid][pAdminLastY],PlayerInfo[playerid][pAdminLastZ],PlayerInfo[playerid][pAdminLastA],PlayerInfo[playerid][pAdminLastI],PlayerInfo[playerid][pAdminLastW]);

}else{
SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command From Inside A Vehicle.");
}

}else{
SendClientMessage(playerid, COLOR_ERROR, "You Need To Spawn Before Using This Command.");
}

}else{
SendClientMessage(playerid, COLOR_ERROR, "Unknown Command! Type /cmds For Available Commands.");
}
return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)