Rat32 Posted February 26, 2015 Share Posted February 26, 2015 Hello everyone! . I making script to create explosion in front of player. But i have a problem. This is creating explosion excluding the rotation. Please help. function test(player) e = player x,y,z=getElementPosition(e) createExplosion(x + 1, y, z, 6) end addCommandHandler("tak", test) Link to comment
JR10 Posted February 26, 2015 Share Posted February 26, 2015 This should work. function getPositionInfrontOfElement(element, meters) local posX, posY, posZ = getElementPosition(element) local _, _, rotation = getElementRotation(element) posX = posX - math.sin(math.rad(rotation)) * meters posY = posY + math.cos(math.rad(rotation)) * meters return posX, posY, posZ end Link to comment
Rat32 Posted February 26, 2015 Author Share Posted February 26, 2015 function funkcja(element, meters) local x,y,z = getElementPosition(element) local _, _, rotation = getElementRotation(element) x = x - math.sin(math.rad(rotation)) * meters y = y + math.cos(math.rad(rotation)) * meters return x, y, z createExplosion(x + 10, y, z, 6) end addCommandHandler("tak", funkcja) This is the edited code. But not work, "attempt to close function at line 1", but is closed Link to comment
Addlibs Posted February 26, 2015 Share Posted February 26, 2015 Line 6, remove return x, y, z Link to comment
Rat32 Posted February 26, 2015 Author Share Posted February 26, 2015 And now don't work script. "attempt to perform arithmetic on local "meters" (a string value) Link to comment
JR10 Posted February 26, 2015 Share Posted February 26, 2015 Try this: function funkcja(element) local x,y,z = getElementPosition(element) local _, _, rotation = getElementRotation(element) x = x - math.sin(math.rad(rotation)) * 3 y = y + math.cos(math.rad(rotation)) * 3 createExplosion(x + 10, y, z, 6) end addCommandHandler("tak", funkcja) Just adjust the number of meter (currently 3 in the script) to adjust the distance. addEventHandler sends two arguments, the player and the command name that was ran. Link to comment
Rat32 Posted February 26, 2015 Author Share Posted February 26, 2015 Work, but does not create the explosion in front of me, but somewhere on the diagonal, ie, do not read this rotation. Link to comment
JR10 Posted February 26, 2015 Share Posted February 26, 2015 Because you didn't remove the offsets. function funkcja(element) local x,y,z = getElementPosition(element) local _, _, rotation = getElementRotation(element) x = x - math.sin(math.rad(rotation)) * 3 y = y + math.cos(math.rad(rotation)) * 3 createExplosion(x, y, z, 6) end addCommandHandler("tak", funkcja) Link to comment
Rat32 Posted February 26, 2015 Author Share Posted February 26, 2015 Now work. Very thanks 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