Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Nihongo^ on Nov 18, 2016, 03:10 PM

Title: GOto with move function error
Post by: Nihongo^ on Nov 18, 2016, 03:10 PM
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 );
}
}
Title: Re: GOto with move function error
Post by: KAKAN on Nov 18, 2016, 04:43 PM
Remove the try catch thing and post the error line
Title: Re: GOto with move function error
Post by: Xmair on Nov 19, 2016, 03:28 AM
if( ( x==x1 ) && ( y==y1 ) && ( z==z1 ) ) PGoto( player );function PGoto( playerID, plrID )
Title: Re: GOto with move function error
Post by: MacTavish on Nov 19, 2016, 09:23 AM
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
Title: Re: GOto with move function error
Post by: Nihongo^ on Nov 19, 2016, 09:29 AM
Solved Thanks