14.01.2016, 13:05
Okay, first you have to think how is it going to work.
How do I get a player's coordinates?
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?
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.
How do I get a player's coordinates?
Код:
GetPlayerPos(playerid,floatX,floatY,FloatZ);
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) */
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. }