Jump to content

[HELP] WARNING: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil] and ERROR: Client triggered serverside event, but event is not added serverside


NovaCrew

Recommended Posts

So there are two errors: WARNING: pozarynew/synced_fire.lua:2: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil] 
and ERROR: Client (USAR|Plk.NovaCrew) triggered serverside event doCreateFire, but event is not added serverside.
I'm new so i'm not sure what to do. I've try to fix it on my on but i don't know how. What's wrong and how to fix it?

This is server side:

addEvent("fireExtinguished", true)
addEventHandler("fireExtinguished", root, fireExtinguishedHandler)
local fireModel = 2023
local fires = {}
addEvent("onFireExtinguished",true)
addEvent("onFireCreate",true)

function createFire(x,y,z)
	local fireElem = createObject(fireModel,x,y,z)
	setElementCollisionsEnabled(fireElem,false)
	local col = createColSphere(x,y,z+1,2)
	fires[fireElem] = {fireElem,col}
	addEventHandler("onColShapeHit",col,setFire)
	return fireElem
end

function setFire(elem,dim)
	if not dim then return end
	if not elem or not isElement(elem) then return end
	if getElementType(elem) == "player" then
		setPedOnFire(elem,true)
	end
end

function fireExtinguished(fireElem)	
	triggerEvent("onFireExtinguished",source,fireElem)
	destroyElement(fires[fireElem][1])
	destroyElement(fires[fireElem][2])
	fires[fireElem] = nil
end

and this is client side:

addEvent("makeSmokeAppear",true)

local fireModel = 2023
function applyFire()
    local fire = engineLoadDFF("fire.dff",2023)
    engineReplaceModel(fire,fireModel)
end

addEventHandler("onClientResourceStart",resourceRoot,applyFire)

local allSmokes = {
    "smoke30lit",
    "smoke60lit",
    "smoke50m"
}

addEventHandler("makeSmokeAppear",root,function (obj)
    local x,y,z = getElementPosition(obj)
    for key, value in ipairs(allSmokes) do
        local effect = createEffect( value, x, y, z+0.5,0,0,0,500)
        setElementParent(effect,obj)
end
end)

function createExtinguisher(wep,_,_,hitX,hitY,hitZ)
	if wep == 42 and math.random(1,5)==1 or wep == 24 and math.random(1,2)==1 then
	for k, v in ipairs(getElementsByType("object",resourceRoot)) do
		if getElementModel(v) == fireModel then
			local fX,fY,fZ = getElementPosition(v)
			local dist = getDistanceBetweenPoints2D(hitX,hitY,fX,fY)
			if wep == 42 and dist < 2 or wep == 24 and dist < 10 then
				triggerServerEvent("fireExtinguished",localPlayer,v)
			end
		end
	end
	end
	if wep == 37 and math.random(1,3)==1 then	-- tworzymy ogien!
	  triggerServerEvent("doCreateFire", root, hitX, hitY, hitZ, getElementDimension(localPlayer), getElementInterior(localPlayer))
	end
end
addEventHandler("onClientPlayerWeaponFire",localPlayer,createExtinguisher)


addEventHandler("onClientRender", root, function()
local rootx,rooty,rootz=getCameraMatrix()
for k,col in ipairs(getElementsByType("object",resourceRoot)) do
    if getElementModel(col) == fireModel then
	if not getElementData(col,"fire:Endvalue") then return end
	local x,y,z=getElementPosition(col)
	local sx,sy =getScreenFromWorldPosition(x, y, z+1)
	if sx and sy then
		local distance = getDistanceBetweenPoints3D(rootx,rooty,rootz,x,y,z)
	end
end
end
end)
local waterTick = getTickCount(  )

addEventHandler("onClientRender",root,function ()
    for key, value in ipairs(getElementsByType("vehicle")) do
        if getElementData(value,"waterpouring") then
            if (getTickCount(  )-waterTick)>=500 then
                waterTick = getTickCount()
                local x,y,z = getElementPosition(value)
                local effect = createEffect( "watersplash",x,y,z-3)
                setTimer(function () destroyElement(effect) end, 500,1)
            end
        end
    end
    end)

local watercost = 10

addEventHandler("onClientRender",root,function ()
    if not getPedOccupiedVehicle( localPlayer ) then return end
    if isPedInVehicle( localPlayer ) and getElementModel(getPedOccupiedVehicle( localPlayer ))==512 then
    if button == "left" then
        if state == "down" then
        local plane = getPedOccupiedVehicle( localPlayer )
        if getVehicleController( plane ) and getVehicleController( plane )==localPlayer then
            if getElementData(plane,"waterpouring") then
                local col = getElementData(plane,"watercol")
                for key, value in ipairs(getElementsWithinColShape( col,"colshape" )) do
                    if getElementData(value,"fire") then
                    if not getElementData(value,"ext") then
                        setElementData(value,"ext")
                        setTimer(function () triggerServerEvent("fireExtinguished",localPlayer,getElementParent(value)) end, 3000, 1 )
                    end
                end
            end
        end
    end
end
end
end
end)


addEventHandler("onClientClick",root,function (button,state)
if isPedInVehicle( localPlayer ) and getElementModel(getPedOccupiedVehicle( localPlayer ))==512 then
    if button == "left" then
        if state == "down" then
        local plane = getPedOccupiedVehicle( localPlayer )
        if getVehicleController( plane ) and getVehicleController( plane )==localPlayer then
            if not getElementData(plane,"waterpouring") then
                if getElementData(plane,"waterlevel") >= 10 then
                setElementData(plane,"waterlevel",getElementData(plane,"waterlevel")-10)
                setElementData(plane,"waterpouring",true)
                setTimer(function () setElementData(plane,"waterpouring",false) end,4500,1 )
            end
        end
    end
end
end
end
end)


function enterTruck(veh,seat)
	if getElementModel(veh) ~= 407 or seat > 0 then return end
	if not rendering then
		
      addEventHandler("onClientRender",root,checkTurret)
	
    end
end

addEventHandler("onClientPlayerVehicleEnter",localPlayer,enterTruck)


function exitTruck()
	
if rendering then
		
  removeEventHandler("onClientRender",root,checkTurret)
	
end
end

addEventHandler("onClientPlayerVehicleExit",localPlayer,exitTruck)
addEventHandler("onClientPlayerWasted",localPlayer,exitTruck)

function checkTurret()
	
  if not getControlState("vehicle_fire") and not getControlState("vehicle_secondary_fire") then return end
	

  local veh = getPedOccupiedVehicle(localPlayer)
  if not veh then return end
  local fX,fY,fZ = getElementPosition(veh)
  local turretPosX,turretPosY = getVehicleTurretPosition(veh)
  local turretPosX = math.deg(turretPosX)
	
  if turretPosX < 0 then turretPosX = turretPosX+360 end
  local rotX,rotY,rotZ = getVehicleRotation(veh)
  local turretPosX = turretPosX+rotZ-360
  if turretPosX < 0 then turretPosX = turretPosX+360 end
outputDebugString(fX.."x"..fY)
local firetruckShape = createColSphere(fX,fY,fZ,20)

local burningVehicles = getElementsWithinColShape(firetruckShape,"object")
	
outputDebugString("elementow "..#burningVehicles)
	
  local burningVehicles=getElementsByType("object", resourceRoot, true)
  for k, v in pairs(burningVehicles) do
		
      local bX,bY,bZ = getElementPosition(v)
      if getDistanceBetweenPoints2D(bX,bY,fX, fY)<30 then 
        local neededRot = findRotation(fX,fY,bX,bY)
        if turretPosX > neededRot-10 and turretPosX < neededRot+10 and math.random(1,5)==1 then
          triggerServerEvent("fireExtinguished",localPlayer,v)
		--setTimer	
          break
		
        end
	
      end                                                          
  end
	
destroyElement(firetruckShape)
end





function findRotation(x1,y1,x2,y2)
	local t = -math.deg(math.atan2(x2-x1,y2-y1))
	if t < 0 then t = t+360 end
	return t
end

 

Link to comment
  • Moderators

WARNING: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]
fireExtinguishedHandler function is not exists, so you can't attach an event to this function.
- What can you do?
  1) Create this function.
  2) Remove the addEvent(...) and addEventHandler(...) in 1st and 2nd lines. (of course it's not a real solution, just eliminate the warning message)

ERROR: Client (USAR|Plk.NovaCrew) triggered serverside event doCreateFire, but event is not added serverside.
- Server try to trigger a client sided custom event, doCreateFire. But this event is not exists.
- What can you do?
  1) Make sure this event is exists on client side.

  • Like 1
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...