Liberty Unleashed
Scripting => Script Help => Topic started by: Theremin on March 18, 2015, 08:34:18 pm
-
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:
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):
function Goto( Id, pos )
{
local player = FindPlayer( ID );
if ( player ) player.Pos = pos;
}
And here is the console error:
(http://i.imgur.com/EwdWm3S.png)
-
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".
-
I'm still getting the same error... maybe I also need to change something in the function called by the timer?
-
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 (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:
NewTimer( "Goto" , 1000 , 1 , player , gotoplr.Pos );
-
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 :)