i am trying to create goto function which canceled teleport if player move but i got an error
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi66.tinypic.com%2Fdctzm0.png&hash=3bec9c246b15715da4f285cdab3b6ec02c244e80)
Command
else if ( cmd == "goto" )
{
try{
if( !text ) MessagePlayer( "[#40FF00][COMMAND] - [#F7FE2E]/goto <player/ID>", player );
else if( !player.IsSpawned ) MessagePlayer( "[#FF0000][ERROR] - [#F7FE2E]You haven't spawned.", player );
else
{
local plr = GetPlayer( GetTok( text, " ", 1 ) );
if( !plr ) MessagePlayer( "[#FF0000][ERROR] - [#F7FE2E]Unknown player/ID.", player );
else if( !plr.IsSpawned ) MessagePlayer( "[#FF0000][ERROR] - [#F7FE2E]The player you are trying to teleport has not spawned yet.", player );
else if( status[ plr.ID ].ngoto ) MessagePlayer( "[#FF0000][ERROR] - [#F7FE2E]The player you want to teleport to has nogoto on.", player );
else
{
MessagePlayer( "[#40FF00][COMMAND] - [#F7FE2E]You wont be Teleport if you move within 4 secs to prevent from death evade.", player );
NewTimer( "going", 300, 1, player.ID, plr.ID, player.Pos.x, player.Pos.y, player.Pos.z );
}
}
}
catch(e) print( "error goto: " + e)
}
Function
function going( playerID, x, y, z )
{
local player = FindPlayer(playerID);
if(player)
{
local x1 = player.Pos.x;
local y1 = player.Pos.y;
local z1 = player.Pos.z;
if( ( x==x1 ) && ( y==y1 ) && ( z==z1 ) ) PGoto( player );
else MessagePlayer( "[#FF0000][ERROR] - [#F7FE2E]You have been moved so you haven't been healed.", player);
}
}
function PGoto( playerID, plrID )
{
local player = FindPlayer(playerID), plr = FindPlayer(plrID);
if(player && plr)
{
player.Pos = plr.Pos;
MessagePlayer( "[#40FF00][COMMAND] - [#F7FE2E]Successfully teleported to " + plr + "." , player );
}
}
Remove the try catch thing and post the error line
if( ( x==x1 ) && ( y==y1 ) && ( z==z1 ) ) PGoto( player );
function PGoto( playerID, plrID )
simply use this :)
function going( playerID, plrID)
{
local player = FindPlayer(playerID), target=FindPlayer(plrID);
if(player && target)
{
player.Pos = Vector(target.Pos.x, target.Pos.y, target.Pos.z);
else MessagePlayer( "[#FF0000][ERROR] - [#F7FE2E]You have been moved to the target", player);
}
else print("The player or target has left the server");
}
Replace timer with NewTimer( "going", 2000, 1, player.ID, plr.ID);
duration changed from 300ms with 2000ms
Solved Thanks