Author Topic: Teleport command with timer  (Read 1430 times)

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Teleport command with timer
« on: March 18, 2015, 09:34:18 pm »
Quote
Hellooooooo Viiiiice Cityyyyy!
Here we go again bugging script bugs >:(. So my aim was to have /goto command behave differently depending if the player is in a vehicle or not, simply because when a remote player teleports while being inside a car often by the time he exits that car every player standing nearby will be crashed. So I added a Player.RemoveFromVehicle() and the result was: the player got teleported together with the car and crashed after some seconds. Following that I added a timer to delay the teleporting after the player is removed from the car, but I have some problems with the arguments and also the variables (*sigh*), here the snippet:

Code: [Select]
else if ( ( cmd == "goto" ) || ( cmd == "go" ) || ( cmd == "teleport" ) || ( cmd == "tp" ) )
{
if ( text )
{
local Id = text.tostring(), gotoplr = GetPlayer( Id );

if ( Id )
{
if ( gotoplr.Spawned )
{
if ( NoGotoArray.Get( gotoplr.Name ) == null )
{
Message( "Mailing " + player + " to " + gotoplr, Colour( 0, 255, 0 ) );

if ( player.Vehicle )
{
player.RemoveFromVehicle();
NewTimer( "Goto", 1000, 1, Id, gotoplr.Pos );
}

else player.Pos = gotoplr.Pos;
}
else MessagePlayer( "*PM* This player doesn't want you near him.", player, Colour( 255, 255, 255 ) );
}
else MessagePlayer( "*PM* This person is currently at the hospital.", player, Colour( 255, 255, 255 ) );
}
else MessagePlayer( "*PM* Can't find anyone with that ID(iot)", player, Colour( 255, 255, 255 ) );
}
else MessagePlayer( "*PM* You must write a name or ID of a player. Example: /goto UnknownPlayer.", player, Colour( 255, 255, 255 ) );
}

So I really have no clue what i should put as timer arguments and what to put in that function called by the timer, here is what I last tried (I've been trying different variables and arguments for the last 2 days):

Code: [Select]
function Goto( Id, pos )
{
local player = FindPlayer( ID );
if ( player ) player.Pos = pos;
}

And here is the console error:

« Last Edit: March 18, 2015, 09:37:06 pm by Theremin »

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Teleport command with timer
« Reply #1 on: March 18, 2015, 10:01:52 pm »
While looking over the snippets, I noticed you are sending a player to his/her own position.

Take a look at the first snippet. You took the value from "text" and assigned it to "Id", and attempted to retrieve a player from it, which you assigned to "gotoplr". Instead of teleporting the player who originally used the command, you teleported the "gotoplr" to their own position, which would have no effect.

In your timer, replace "Id" with "player.ID".

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Teleport command with timer
« Reply #2 on: March 22, 2015, 09:04:05 pm »
I'm still getting the same error... maybe I also need to change something in the function called by the timer?

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Teleport command with timer
« Reply #3 on: March 22, 2015, 10:15:11 pm »
I recreated your Goto function to use a player instance (instead of an ID) and to add optional offset capabilities.

You can view the code using the link provided below (hosted by Pastebin). I think it's too long to display properly in a code tag on this forum.
http://pastebin.com/raw.php?i=DDt6gkwp

If you use my edited version, please note that you don't have to provide an offset if you don't need it. Just leave it out when calling the function. You will need to fix the timer to use the player's instance instead of the ID. It should look something like this:
Code: [Select]
NewTimer( "Goto" , 1000 , 1 , player , gotoplr.Pos );

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: Teleport command with timer
« Reply #4 on: March 26, 2015, 02:46:22 am »
I don't fully understand your snippet Vortrex, and I kinda expected the solution was easier :-\. I like to use only code I fully understand therefore I decided to opt for a different solution for now: Removing the player and message him he can't teleport inside a car. Thanks Vortrex for taking the time to reply each time :)

 

© Liberty Unleashed Team.