Jump to content

[HELP] Teleport System


Recommended Posts

[2018-07-10 00:20:43] WARNING: beach\server.lua:75: Bad argument @ 'setElementPosition' [Expected element at argument 1, got nil]
[2018-07-10 00:20:49] WARNING: beach\server.lua:75: Bad argument @ 'setElementPosition' [Expected element at argument 1, got nil]

errors!

 

Link to comment
  • Discord Moderators

Because it should be client-side, which is dumb.
 

addCommandHandler("gotobeach", 
  	function goToBeach(source)
  		setElementPosition(source, 343.20026, -1780.60388, 5.22299)
	end
)

 

Link to comment
9 hours ago, EH10 said:

addCommandHandler("gotobeach", 
    function()
        spawnPlayer(source, 343.20026, -1780.60388, 5.22299,_,_)
    end
)

 

Idk if this is a troll or not but this is a bad way of moving the player.

Also the source in your code is nil

@Pirulax your code didn't work because you defined a function name for an anon function.

Link to comment
  • Discord Moderators

Happens, I was tired as I said.
Btw, here is the working code then:

addCommandHandler("gotobeach", 
    function(source)
        if (isPedDead(source)) then
      		spawnPlayer(source, 343.20026, -1780.60388, 5.22299)
      	else
      		setElementPosition(source, 343.20026, -1780.60388, 5.22299)
      	end
    end
)

And actually, there is no predefined 'source' variable in addCommandHandler, and why would you spawn a player?

Edited by Pirulax
Link to comment

teleport_s.lua

addCommandHandler("gotobeach", function(player)
if isElement(player) and not isPedDead(player) then
setElementPosition(player, 343.20026, -1780.60388, 5.22299)
outputChatBox("You have been successfully teleported to the beach.", player, 0, 200, 0, false)
else
outputChatBox("You must be alive in order to use this command.", player, 200, 0, 0, false)
end
end)

meta.xml

<meta>
<script src="teleport_s.lua" type="server"/>
</meta>

http://www.mediafire.com/file/kwz7052k8tltfxf/teleport.zip

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...