[Tutorial] How to make a Simple "/Goto" command !
#1

Introduction:


- Hello, today I'm gonna show you today how to make a simple /Goto Command .
- After start, you need to have SSCANF and ZCMD.



Let's start:


- After downloaded and put includes in "pawno/include" folder, we can start scripting. So we need to add that includes, at the top of script:

pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf>

- Then, after adding includes, we scroll down, down, and we there we will made /goto command !

pawn Code:
CMD:goto(playerid,params[]) // This it's /Goto command. You can change in your wanted command !
{ // We open brackelet
    new ID; // This it's player's ID wich we will teleport !
    new Float:X; // This it's position X position of that player !
    new Float:Y; // This it's position Y position of that player !
    new Float:Z;  // This it's position z position of that player !
    new Float:A;  // This the Facing Angle position of that player !
    if(sscanf(params,"i", ID)) return SendClientMessage(playerid,-1,"{FF0000}AdmUsage: {15FF00}/Goto [PlayerID]"); // He will saw this on screen, if he write just /Goto . Will show to him Correct Usage !
    GetPlayerPos(ID, X,Y,Z); // Will get that player Position X,Y,Z !
    GetPlayerFacingAngle(ID, A); // Will get that player Facing Angle position !
    SetPlayerPos(playerid, X,Y,Z); // Will set the player who type /Goto [ID] to specified player !
    SetPlayerFacingAngle(playerid, A); // Will set exactlly that Facing Angle of specified player !
    SendClientMessage(playerid, -1, "{FF0000}Cmd: {15FF00}You teleported to specified player !"); // He will saw a message. "You teleported to specified player"
    return 1; // Return value !
} // Close brackelet to show we finished command !
All Code:


pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf>

CMD:goto(playerid,params[])
{
    new ID;
    new Float:X;
    new Float:Y;
    new Float:Z;
    new Float:A;
    if(sscanf(params,"i", ID)) return SendClientMessage(playerid,-1,"{FF0000}AdmUsage: {15FF00}/Goto [PlayerID]");
    GetPlayerPos(ID, X,Y,Z);
    GetPlayerFacingAngle(ID, A);
    SetPlayerPos(playerid, X,Y,Z);
    SetPlayerFacingAngle(playerid, A);
    SendClientMessage(playerid, -1, "{FF0000}Cmd: {15FF00}You teleported to specified player !");
    return 1;
}
Reply
#2

Nice one
Reply
#3

Failing to ensure the smooth operation of this code, if your parameter is in another world or interior would not make it to their destination, With your code could go to a player invalid, could cause problems, i think this would work better:

pawn Code:
command(goto, playerid, params[])
{
    if(sscanf(params, "u", params[0])) return SendClientMessage(playerid, -1, "/goto [playerid/name].");
    if(IsPlayerConnected(params[0]) && params[0] != INVALID_PLAYER_ID)
    {
        if(params[0] != playerid)
        {
            new Float:cords[3];
            SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(params[0]));
            SetPlayerInterior(playerid, GetPlayerInterior(params[0]));
            GetPlayerPos(params[0], cords[0], cords[1], cords[2]);
            SetPlayerPos(playerid, cords[0], cords[1], cords[2]);
        }
        else
        {
            SendClientMessage(playerid, -1, "You can't go toward yourself.");
        }
    }
    else
    {
        SendClientMessage(playerid, -1, "Player not connected.");
    }
    return true;
}
Reply
#4

A Bit Nice..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)