Jump to content

Fire scripting help


Fuentes

Recommended Posts

Posted

create fire position fX fY fZ

function startTheFire (fX,fY,fZ) 
  
setElementData(fire, "x", fX) 
setElementData(fire, "y", fY) 
setElementData(fire, "z", fZ) 
  
    setTimer ( function() 
     
        createFire(fX,fY,fZ,60) 
    end, 420000, 1) 
    
     
    local Soundone = playSound3D( "files/firealarm.mp3",fX,fY,fZ, false ) 
    setSoundMinDistance(Soundone, 25) 
    setSoundMaxDistance(Soundone, 70) 
     
    local Soundtwo = playSound3D( "files/firealarmsecond.mp3",-2039.7060546875 ,78.998046875 ,28.397680282593, false ) 
    setSoundMinDistance(Soundtwo, 25) 
    setSoundMaxDistance(Soundtwo, 70) 
     
     
     --setSoundVolume( Sound, 1 ) 
  
    local fire = engineLoadDFF("fire.dff",1) 
    engineReplaceModel(fire,fireModel) 
end 
addEvent("startTheFire",true) 
addEventHandler( "startTheFire", getRootElement(), startTheFire) 

Problem:

function firelost(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if (weapon==42) then 
        local team = getPlayerTeam(getLocalPlayer()) 
        local ftype = getElementData(getLocalPlayer(), "faction") 
         
  
        if (ftype==4)  then 
            if not (hitElement) or (getElementType(hitElement)~="player") then  
                 
                if not cooldown then 
                    if (ammoInClip>10) and (weapon==42) then 
                local x, y, z = hitX, hitY, hitZ 
         
    local x2 = getElementData(fire, "x") 
    local y2 = getElementData(fire, "y") 
local z2 = getElementData(fire, "z") 
    if getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) > 10  then 
                            outputChatBox("Are not fire.", 255, 0, 0) 
                            count = 0 
                            cooldown = setTimer(resetCooldown, 5000, 1, false) 
                        else 
            count = count + 1 
                             
                            if (count==20) then 
                                count = 0 
                                cooldown = setTimer(resetCooldown, 30000, 1, false) 
            triggerServerEvent("cancelrandomfires", localPlayer)  
    end 
    end 
    end 
    end 
    end 
    end 
    end 
    end 
    addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(),firelost) 

error:

Bad argument @ 'getDistanceBetweenPoints3D' [Expected vector3 at argument 4, got boolean]

Thank You

Posted

You're hitting an element that is not a player but neither a fire (hence x2, y2 and z2 are false, a boolean value). You should check

if x2 and y2 and z2 then 

before proceeding to getDistanceBetweenPoints3D.

Previously known as MrTasty.

Posted
function firelost(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if (weapon==42) then 
        local team = getPlayerTeam(getLocalPlayer()) 
        local ftype = getElementData(getLocalPlayer(), "faction") 
        ---outputChatBox("." ..hitX.." "..hitY.." "..hitZ, 255, 0, 0) 
  
        if (ftype==4)  then 
            if not (hitElement) or (getElementType(hitElement)~="player") then -- Didn't attack someone 
                 
                if not cooldown then 
                    if (ammoInClip>10) and (weapon==42) then 
                local x, y, z = hitX, hitY, hitZ 
         
    local x2 = getElementData(fire, "x") 
    local y2 = getElementData(fire, "y") 
local x2 = getElementData(fire, "x") 
    if x2 and y2 and z2 then 
                            outputChatBox("Not are fire.", 255, 0, 0) 
                            count = 0 
                            cooldown = setTimer(resetCooldown, 5000, 1, false) 
                        else 
            count = count + 1 
                             
                            if (count==20) then 
                                count = 0 
                                cooldown = setTimer(resetCooldown, 30000, 1, false) 
            triggerServerEvent("cancelrandomfires", localPlayer)  
    end 
    end 
    end 
    end 
    end 
    end 
    end 
    end 
    addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(),firelost) 

Bad argument @ 'getElementData' [Expected element at argument 1, got nil]

Posted
if x2 and y2 and z2 then 
     if getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) > 10  then 
         outputChatBox("Are not fire.", 255, 0, 0) 
         count = 0 
         cooldown = setTimer(resetCooldown, 5000, 1, false) 
     else 
         count = count + 1 
         if (count==20) then 
             count = 0 
             cooldown = setTimer(resetCooldown, 30000, 1, false) 
             triggerServerEvent("cancelrandomfires", localPlayer) 
        end 
    end 
end 

Previously known as MrTasty.

Posted

Bad argument @ 'getElementData' [Expected element at argument 1, got nil]

local x2 = getElementData(fire, "x")

local y2 = getElementData(fire, "y")

local x2 = getElementData(fire, "x")

Posted

local x, y, z = hitX, hitY, hitZ

local x2 = getElementData(hitElement, "x")

local y2 = getElementData(hitElement, "y")

local x2 = getElementData(hitElement, "x")

if x2 and y2 and z2 then

bad argument getelementdata

Posted
local x, y, z = hitX, hitY, hitZ

local x2 = getElementData(hitElement, "x")

local y2 = getElementData(hitElement, "y")

local x2 = getElementData(hitElement, "x")

if x2 and y2 and z2 then

bad argument getelementdata

Did you set it as well? setElementData(hitElement, "x", value)

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

  • Moderators
Posted

if not (hitElement) or (getElementType(hitElement)~="player") then -- Didn't attack someone 
if hitElement and getElementType(hitElement) ~= "player" then -- Didn't attack someone 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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