Visma Posted January 30, 2015 Share Posted January 30, 2015 I am trying to learn how to script i have read the wiki and trying to make my first script. The script i am trying to make is if you use the command /teleport it will teleport you 5 in the x direction. It gives me an error on line 2 argument 1 and line 3 "attempt to perform arithmetic on local "x" (a boolean value) function spawnPlayer(thePlayer, command) local x,y,z = getElementPosition(thePlayer) x = x + 5 local spawnedPlayer = spawnPlayer(x,y,z) if (spawnedPlayer == true) then outputChatBox("You have teleported",thePlayer) end end addCommandHandler("teleport", spawnPlayer) Please do not just fix it, explain it to me. Thanks in advance. Link to comment
SkatCh Posted January 30, 2015 Share Posted January 30, 2015 You can use : setElementPosition also you don't need to wirite this x = x +5 simply you can do it like this : function spawnPlayer(thePlayer, command) if not isElement(thePlayer) then return end local x,y,z = getElementPosition(thePlayer) setElementPosition(thePlayer,x+5,y,z) end addCommandHandler("teleport", spawnPlayer) Link to comment
Gallardo9944 Posted January 30, 2015 Share Posted January 30, 2015 setElementPosition will cause a lot of problems if you don't use spawnPlayer before it at least once. Also, your function has name spawnPlayer so it will override original MTA spawnPlayer function. Code in the first post will cause stack overflow (self-call unlimited times) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now