Jump to content

attempt to perform arithmetic on local "oldValue"


stefutz101

Recommended Posts

function weaponDelete(dataName,oldValue) 
    if getElementType(source) == "player" then -- check if the element is a player 
        local weapon1 = getElementData(source,"currentweapon_1") 
        local weapon2 = getElementData(source,"currentweapon_2") 
        local weapon3 = getElementData(source,"currentweapon_3") 
        if dataName == weapon1 or dataName == weapon2 or dataName == weapon3 then 
            if getElementData (source,dataName) == 0 then 
                local ammoData,weapID = getWeaponAmmoType(dataName) 
                takeWeapon (source,weapID) 
            end 
        end 
            local weapon1 = getElementData(source,"currentweapon_1") 
            local weapon2 = getElementData(source,"currentweapon_2") 
            local weapon3 = getElementData(source,"currentweapon_3") 
            local ammoData1,weapID1 = getWeaponAmmoType(weapon1) 
            local ammoData2,weapID2 = getWeaponAmmoType(weapon2) 
            local ammoData3,weapID3 = getWeaponAmmoType(weapon3) 
        if dataName == ammoData1 then 
        local newammo = oldValue - getElementData (source,dataName) 
        if newammo == 1 then return end 
            if getElementData (source,dataName) < oldValue then 
                takeWeapon (source,weapID1,newammo)  
                if elementWeaponBack[source] then 
                    detachElementFromBone(elementWeaponBack[source]) 
                    destroyElement(elementWeaponBack[source])    
                    elementWeaponBack[source] = false 
                end  
            elseif getElementData (source,dataName) > oldValue then 
                giveWeapon(source,weapID1,getElementData (source,dataName)-oldValue,true) 
            end 
        end  
        if dataName == ammoData2 then 
        local newammo = oldValue - getElementData (source,dataName) 
        if newammo == 1 then return end 
            if getElementData (source,dataName) < oldValue then 
                takeWeapon (source,weapID2,newammo)  
            elseif getElementData (source,dataName) > oldValue then 
                giveWeapon(source,weapID2,getElementData (source,dataName)-oldValue,false) 
            end 
        end  
        if dataName == ammoData3 then 
        local newammo = oldValue - getElementData (source,dataName) 
        if newammo == 1 then return end 
            if getElementData (source,dataName) < oldValue then 
                takeWeapon (source,weapID3,newammo)  
            elseif getElementData (source,dataName) > oldValue then 
                giveWeapon(source,weapID3,getElementData (source,dataName)-oldValue,false) 
            end  
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),weaponDelete) 

Error : attempt to perform arithmetic on local "oldValue" a nil value at line :

local newammo = oldValue - getElementData (source,dataName) 

How can i fix that ? I think i can put an if like this " if oldValue ~= nil then " but i don't know exactlly where i must put it .

Can I try like this ?

function weaponDelete(dataName,oldValue) 
if oldValue == nil then return end 
--rest of the script 
  

Thanks in advance !

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