Jump to content

triggerClientEvent


-.Paradox.-

Recommended Posts

Weapons\client.lua:11: Bad argument @'addEventHandler' [Expected function at argument 3, got nil'

Client:

function weapons( ) 
local icons = getPedWeapon(localPlayer) 
 if icons then 
  dxDrawImage(917, 53, 243, 123, ":Weapons/images/"..icons..".png") 
 end 
end 
  
addEvent("onClientWeaponSwitch", true) 
addEventHandler( "onClientWeaponSwitch", root, 
function() 
        addEventHandler("onClientRender", root, onTest) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, weapons ) 
        end, 3000, 1) 
end) 

Server:

addEvent( "onPlayerWeaponSwitch" , true) 
addEventHandler( "onPlayerWeaponSwitch", getRootElement(), 
function() 
        triggerClientEvent(source,"onClientWeaponSwitch", source) 
end) 

I'm trying to show that image when the player switch weapons.

Link to comment
function weapons( ) 
local icons = getPedWeapon(localPlayer) 
 if icons then 
  dxDrawImage(917, 53, 243, 123, ":Weapons/images/"..icons..".png") 
 end 
end 
  
addEvent("onClientWeaponSwitch", true) 
addEventHandler( "onClientWeaponSwitch", root, 
function() 
        addEventHandler("onClientRender", root, onTest) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, weapons ) 
        end, 3000, 1) 
end) 

This is what Solidsnake ment the first time, your event

addEventHandler("onClientRender", root, onTest) 

Is for "onTest" when it should be like this:

addEventHandler("onClientRender", root, weapons) 

The eventhandler must be linked to your function/function name, so:

function weapons( ) 
local icons = getPedWeapon(localPlayer) 
 if icons then 
  dxDrawImage(917, 53, 243, 123, ":Weapons/images/"..icons..".png") 
 end 
end 
  
addEvent("onClientWeaponSwitch", true) 
addEventHandler( "onClientWeaponSwitch", root, 
function() 
        addEventHandler("onClientRender", root, weapons) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, weapons ) 
        end, 3000, 1) 
end) 

P.S: Castillo, I checked the wiki and there is no client-side event for the weapon switch...

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