Jump to content

Problem with the explosion script.


Rat32

Recommended Posts

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

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

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 xD

Link to comment

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

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

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