Jump to content

triggerClientEvent


Recommended Posts

Posted

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.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Your function name at addEventHandler: "onTest", your real function name: "weapons".

P.S: Why you need a server side script? there's a client side event for when player switch weapons.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

What is it?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Read what I said again, the problem is that you're using a wrong function name.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

Posted

Actually there is, And i asked Castillo to tell me what is it, and he thought i'm talking about the error but i was talking about the event.

Anyway, here is the event, onClientPlayerWeaponSwitch

Thanks by the way.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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