Jump to content

[HELP] Can't find the error in this teleport script.


Moony

Recommended Posts

First, I began with this:

Spoiler

marker1 = createMarker(934, -1452, 14.5, "arrow", 1.5, 230, 251, 3, 153) 
marker2 = createMarker(934, -1452, 14.5, "arrow", 1.5, 230, 251, 3, 153)  
  
function teleport(player) 
    if (source == marker1 and getElementType(player) == "player") then 
        setElementPosition(player, -354.3, -3786.8000976563, 16.40000038147) 
        setElementFrozen(player, false) 
        setTimer(setElementFrozen, 1000, 1, player, false) 
    elseif (source == marker2 and getElementType(player) == "player") then 
        setElementPosition(player, -354.3, -3786.8000976563, 16.40000038147) 
        setElementFrozen(player, false) 
        setTimer(setElementFrozen, 1000, 1, player, false)   
    end 
end 
addEventHandler("onMarkerHit", root, teleport) 

Source

When entering either marker, you are taken to the specified location.
It works perfectly. Both markers take me to the desired location in San Andreas' map. I moved them around and changed the shape of the marker just to be sure. There were no problems.

Then, I found this:

Spoiler

function motel (thePlayer) 
    setElementInterior ( thePlayer, 0, 2216.3332844, -1150.5032888, 1025.732323227 ) 
    outputChatBox ( "O player ".. getPlayerName(thePlayer) .." Foi para o Motel Vá tambem (/motel)", root, 0, 255, 0 ) 
end 
addCommandHandler ( "motel", motel ) 

Source

This is supposed to teleport you into the specified interior (nº0), and the coordinates next to the interior (x, y, z)
The chatbox outputs the expected message. However, there is no teleporting to the specified place. The function 'setElementInterior' looks good, judging by what the wiki says.

What am I missing? Something tells me it's a very obvious error I'm failing to see.

Link to comment

0 Interior is outside, but your z position is probably too high (1025.732323227) You would end up teleporting somewhere in the sky and then just falling back down to the ground... I don't recall what the Z limit for Interior 0 (Outside) is, but if you were to change below that limit, it would likely teleport you then. Change the Z to 500.0, it will likely work, but you'll also likely fall to your death as well :P

  • Thanks 1
Link to comment
1 hour ago, ReZurrecti0n said:

0 Interior is outside, but your z position is probably too high (1025.732323227) You would end up teleporting somewhere in the sky and then just falling back down to the ground... I don't recall what the Z limit for Interior 0 (Outside) is, but if you were to change below that limit, it would likely teleport you then. Change the Z to 500.0, it will likely work, but you'll also likely fall to your death as well :P

A good example would be The Four Dragons Casino.  The interior spawn point (where you appear when you are teleported by the F1 panel/admin panel) is located at z = 990 (aprox). I had assumed that if I set the interior to the casino, and z to where you spawn, you would be taken there. Likewise, the examples in the wiki (setElementInterior) give values of z higher than 900.
After a few tries. I found the limit between 300 and 400.

Link to comment
16 hours ago, ReZurrecti0n said:

0 Interior is outside, but your z position is probably too high (1025.732323227) You would end up teleporting somewhere in the sky and then just falling back down to the ground... I don't recall what the Z limit for Interior 0 (Outside) is, but if you were to change below that limit, it would likely teleport you then. Change the Z to 500.0, it will likely work, but you'll also likely fall to your death as well :P

I kept experimenting with this.

I found a script that opened a panel with several teleports. They all had crazy x, y, and z values that were being respected. I modified them and got two teleports working (so far): one that takes the player to the entrance of "Four Dragons Casino", and one that takes the player inside the casino. Using setElementInterior, setElementPosition, and setElementRotation worked fine. I managed to obtain the what I had imagined.
I decided to take one more step, and use markers to achieve the same result. As of this moment, there is a marker right next to the entrance of the casino, on the outside. The script looks as such:

infourdragons = createMarker (2019.76953125, 1007.0116577148, 9.7203125, "cylinder", 1, 255, 0, 0, 153) -- Coords for a spot next to the doors of the casino, on the outside.

function enteredDragons(hitElement, matchingDimension) -- I tested the script with no values between parentheses.
    if (source == infourdragons and getElementType (player) == "player") then
    setElementInterior (player, 0)
    setElementPosition (player, 2018.9376220703, 1017.0843505859, 996.875 ) -- Coords for a spot next to the doors of the casino, on the inside.
    setElementRotation (player, 0, 0, 90)
    outputChatbox ("Entraste al Casino 'Four Dragons'", player, true)
    end
end
addEventHandler ("onMarkerHit", root, enteredDragons)

(Translation: "You've entered 'Four Dragons Casino'".

The marker shows up beautifully. I can modify it as desired. Everything else is not working. There is no output and no teleportation.

Where could be the error?

Link to comment

Because you are using player, but player is not defined in this function anywhere.

However, with onMarkerHit(hitElement, matchingDimension), the first parameter is the element that hit the marker which in this case is likely the player:

infourdragons = createMarker (2019.76953125, 1007.0116577148, 9.7203125, "cylinder", 1, 255, 0, 0, 153) -- Coords for a spot next to the doors of the casino, on the outside.

function enteredDragons(hitElement, matchingDimension) -- When anything hits the marker (players, objects, vehicles, etc.) it becomes "hitElement"
    if (source == infourdragons and getElementType (hitElement) == "player") then -- Making sure the element is a player
    setElementInterior (hitElement, 0)
    setElementPosition (hitElement, 2018.9376220703, 1017.0843505859, 996.875 ) -- Coords for a spot next to the doors of the casino, on the inside.
    setElementRotation (hitElement, 0, 0, 90)
    outputChatbox ("Entraste al Casino 'Four Dragons'", hitElement, true)
    end
end
addEventHandler ("onMarkerHit", root, enteredDragons)

There are other options you may take, one is simply just changing that first parameter to player (But this may confuse you down the road because more than just a player can trigger the event)

Another option is using onPlayerMarkerHit(markerHit, matchingDimension), source would then be the player that hit the marker

Edited by ReZurrecti0n
  • Thanks 1
Link to comment
1 hour ago, ReZurrecti0n said:

Because you are using player, but player is not defined in this function anywhere.

However, with onMarkerHit(hitElement, matchingDimension), the first parameter is the element that hit the marker which in this case is likely the player:


infourdragons = createMarker (2019.76953125, 1007.0116577148, 9.7203125, "cylinder", 1, 255, 0, 0, 153) -- Coords for a spot next to the doors of the casino, on the outside.

function enteredDragons(hitElement, matchingDimension) -- When anything hits the marker (players, objects, vehicles, etc.) it becomes "hitElement"
    if (source == infourdragons and getElementType (hitElement) == "player") then -- Making sure the element is a player
    setElementInterior (hitElement, 0)
    setElementPosition (hitElement, 2018.9376220703, 1017.0843505859, 996.875 ) -- Coords for a spot next to the doors of the casino, on the inside.
    setElementRotation (hitElement, 0, 0, 90)
    outputChatbox ("Entraste al Casino 'Four Dragons'", hitElement, true)
    end
end
addEventHandler ("onMarkerHit", root, enteredDragons)

There are other options you may take, one is simply just changing that first parameter to player (But this may confuse you down the road because more than just a player can trigger the event)

Another option is using onPlayerMarkerHit(markerHit, matchingDimension), source would then be the player that hit the marker

Let's go for something much simpler.

infourdragons = createMarker (2019.76953125, 1007.0116577148, 9.7203125, "cylinder", 1, 255, 0, 0, 153)

function saythis (player)
    if (player == infourdragons) then
    outputChatBox ("What are you doing?", player, true)
    end
end
addEventHandler("onHitMarker", player, "saythis")

I know there are a lot of errors and missing functions. I just don't know which.

-Made the marker - Check
-Created the function - Check
-----If a player is in same place as the marker - Check  — — Though I know that that would include a single point, and that is impossible to hit.
-----If the marker is touched, the chatbox will show a message to the player -  Check.
-The event is triggered when the marker is hit by a player -  Check.

What am I missing?

 

Link to comment
infourdragons = createMarker (2019.76953125, 1007.0116577148, 9.7203125, "cylinder", 1, 255, 0, 0, 153)

function saythis (player) -- Should consider adding the 2nd parameter for future use and renaming the player parameter to something more related such as element
    if (player == infourdragons) then -- The player is not infourdragons and never will be, you must be confusing this as checking the player touching infourdragons or something. Instead check if player is an actual player element AND if source (The Marker) is infourdragons
    outputChatBox ("What are you doing?", player, true) -- This would work currently, but what if player is a vehicle instead of a player? Should rename the player parameter for that reason
    end
end
addEventHandler("onHitMarker", player, "saythis") -- onHitMarker is wrong, you meant onMarkerHit. getRootElement() should be used instead of the player parameter, but unsure if player could or even should be used. Never tried, always gone with getRootElement() on all my Handlers

 

  • Thanks 1
Link to comment

How should I look for the explanation to the arguments of a function?

I'm getting extremely confused as to why sometimes the parentheses (function functionName() <-- this) are empty, and sometimes they have more than one argument. I've seen "thePlayer", "elemenet", "hitElement", "matchingDimension", "vehicle", "player", and more. I've even seen handlers that show the function variable with more elements than the beginning of the function.
How do they affect the function? How are they related to the tree of the function?

PS: english is not my first language. I'm good with casual talking, but when it comes to specific stuff, I struggle to find the words and even confuse myself sometimes. If there is anything that you [reader(s)] don't understand, let me know.

 

Link to comment

English seems great to me, haven't even noticed it wasn't your native language...

But as for how to figure out what parameters a event has:

Let's say we want to know what parameters come with the OnPlayerWasted Event

We first look up the event on the wiki: https://wiki.multitheftauto.com/wiki/OnPlayerWasted

Look for where it says: Parameters

You may rename these parameters to anything you want, but will always be the same

So on this example: onPlayerWasted(totalAmmo,killer,killerWeapon,bodypart,stealth)

Let's change the parameter names to be like: onPlayerWasted(candy,bird,sun,rock,tools)

candy will still be the total ammo, bird will be the killer element if any, sun would still be the weapon used for the kill, so on and so forth...

You're going to have to look into this wiki, search these forums and google search Lua to figure everything out. This is how I learned, but every now and then I won't be able to find anywhere on how to do this or that and so I finally make a thread for it

Edited by ReZurrecti0n
  • Thanks 1
Link to comment
6 hours ago, ReZurrecti0n said:

But as for how to figure out what parameters a event has:

Let's say we want to know what parameters come with the OnPlayerWasted Event

We first look up the event on the wiki: https://wiki.multitheftauto.com/wiki/OnPlayerWasted

Look for where it says: Parameters

You may rename these parameters to anything you want, but will always be the same

So on this example: onPlayerWasted(totalAmmo,killer,killerWeapon,bodypart,stealth)

Let's change the parameter names to be like: onPlayerWasted(candy,bird,sun,rock,tools)

candy will still be the total ammo, bird will be the killer element if any, sun would still be the weapon used for the kill, so on and so forth...

You're going to have to look into this wiki, search these forums and google search Lua to figure everything out. This is how I learned, but every now and then I won't be able to find anywhere on how to do this or that and so I finally make a thread for it

Alright. I think I'm getting it.

I just read about the event called 'onClientMarkerHit'. The parameters are 'hitPlayer' and 'matchingDimension'. The function is called "MarkerHit".

Teleport2 = createMarker (2021.76953125, 1007.0116577148, 9.7203125, "cylinder", 1, 255, 0, 0, 153)

function MarkerHit (hitElement, matchingDimension)
	outputChatBox("What are you doing??!")
end
addEventHandler ("onClientMarkerHit", root, MarkerHit)
addCommandHandler ("four2", MarkerHit)

I'm aware it says 'hitElement'.

This works completely.
Seems to me that the 1st argument of 'addEventHandler' ("onClientMarkerHit") is connected to both arguments of the function 'MarkerHit' ('hitElement' and 'matchingDimension'). I also know that the arguments of the function can have any name; regardless, they will be treated the same way. Hold on... When I use the event 'onClientMarkerHit', am I conditioning the system to read the function as such? As if the system would be saying: "This dude added an event handler. Which is it? "onClientMarkerHit"? Alright then, there should be two arguments in the function. Are there two arguments? Yes. That means that this function will surely be about something hitting any marker. Once a marker is hit, I will have to output something into the chatbox".
And if I want to do something to the hitElement, I'd have to tell it to the system in the arguments of the scripts.

Alright. I guess we can celebrate now. I've got the script running, with a message, and even with an 'if' that prohibits players in a vehicle to enter.

This experience is slowly turning into a crazier rollercoaster. Thanks to everyone for such amazing help and guidance!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...