[Help]Teleport command
#1

Hello everybody

I need help with my teleport commands.

I want it so that a player can type /dm and teleport to 1 of these positions
2536 -1603 18
2641 -1621 20
2611 -1612 26
2516 -1610 22
2511 -1620 28
2556 -1606 19

but i want it to be random.
They will type /dm and will be teleported to 1 of those positions
Pls reply asap
Reply
#2

This is what you need, read in the wiki if you dont know how to use it:
OnPlayerCommandText
strcmp
random
switch - case
SetPlayerPos
Reply
#3

So first off, you'll need to shove them coordinates in a Float array, perhaps with an enum to keep it tidy:

pawn Код:
// .. Enumeration for data for DM teleports.
enum DATA_DM_TPS
{
    Float:X,
    Float:Y,
    Float:Z,
}

// .. Constant array of coordinates for teleports for /dm.
stock const Float:aDMTeles[ ][ DATA_DM_TPS ] =
{
    { 2536.0, -1603.0, 18.0 },
    { 2641.0, -1621.0, 20.0 },
    { 2611.0, -1612.0, 26.0 },
    { 2516.0, -1610.0, 22.0 },
    { 2511.0, -1620.0, 28.0 },
    { 2556.0, -1606.0, 19.0 }
};
And then, for the /dm command - put this in OnPlayerCommandText:

pawn Код:
if( !strcmp(cmdtext, "/dm") )
{
    //If they typed /dm, create a new random variable ranging from 0 to the
    //size of the array of coordinates.
    new nRand = random(sizeof aDMTeles);
   
    //Set the player's position to one of the random entries within the array.
    SetPlayerPos( playerid, aDMTeles[nRand][X], aDMTeles[nRand][Y], aDMTeles[nRand][Z] );
   
    //Return true.
    return 1;
}
Reply
#4

Quote:
Originally Posted by blewert
Посмотреть сообщение
So first off, you'll need to shove them coordinates in a Float array, perhaps with an enum to keep it tidy:

pawn Код:
// .. Enumeration for data for DM teleports.
enum DATA_DM_TPS
{
    Float:X,
    Float:Y,
    Float:Z,
}

// .. Constant array of coordinates for teleports for /dm.
stock const Float:aDMTeles[ ][ DATA_DM_TPS ] =
{
    { 2536.0, -1603.0, 18.0 },
    { 2641.0, -1621.0, 20.0 },
    { 2611.0, -1612.0, 26.0 },
    { 2516.0, -1610.0, 22.0 },
    { 2511.0, -1620.0, 28.0 },
    { 2556.0, -1606.0, 19.0 }
};
And then, for the /dm command - put this in OnPlayerCommandText:

pawn Код:
if( !strcmp(cmdtext, "/dm") )
{
    //If they typed /dm, create a new random variable ranging from 0 to the
    //size of the array of coordinates.
    new nRand = random(sizeof aDMTeles);
   
    //Set the player's position to one of the random entries within the array.
    SetPlayerPos( playerid, aDMTeles[nRand][X], aDMTeles[nRand][Y], aDMTeles[nRand][Z] );
   
    //Return true.
    return 1;
}
what do i put for aDMTeles? im new to this soz
Reply
#5

Quote:
Originally Posted by DrSega69
Посмотреть сообщение
what do i put for aDMTeles? im new to this soz
Put the enum and aDMTeles outside of a callback. Like this:

pawn Код:
// .. Enumeration for data for DM teleports.
enum DATA_DM_TPS
{
    Float:X,
    Float:Y,
    Float:Z,
}

// .. Constant array of coordinates for teleports for /dm.
stock const Float:aDMTeles[ ][ DATA_DM_TPS ] =
{
    { 2536.0, -1603.0, 18.0 },
    { 2641.0, -1621.0, 20.0 },
    { 2611.0, -1612.0, 26.0 },
    { 2516.0, -1610.0, 22.0 },
    { 2511.0, -1620.0, 28.0 },
    { 2556.0, -1606.0, 19.0 }
};

public OnPlayerCommandText(playerid, cmdtext[])
{
    if( !strcmp(cmdtext, "/dm") )
    {
        //If they typed /dm, create a new random variable ranging from 0 to the
        //size of the array of coordinates.
        new nRand = random(sizeof aDMTeles);

        //Set the player's position to one of the random entries within the array.
        SetPlayerPos( playerid, aDMTeles[nRand][X], aDMTeles[nRand][Y], aDMTeles[nRand][Z] );

        //Return true.
        return 1;
    }
}
Reply
#6

ty so much!!!! +1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)