Jump to content

Trigger a client side event handler


..:D&G:..

Recommended Posts

Posted

How do I trigger this event:

addCommandHandler("showhud", 
function () 
if handler  then 
removeEventHandler("onClientRender",root,renderHud) 
handler = false 
else 
addEventHandler("onClientRender",root,renderHud) 
handler = true 
end 

So its handler = false like

ONLY AN EXAMPLE:

triggerEvent("hideHud", getLocalPlayer()) 

Or do I need to make an event?

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!''

  • Moderators
Posted
  
local handler = false 
function myHudFunction () 
if handler  then 
removeEventHandler("onClientRender",root,renderHud) 
handler = false 
else 
addEventHandler("onClientRender",root,renderHud) 
handler = true 
end 
end 
  
addCommandHandler("showhud",myHudFunction) 
  
addEvent("hideHud",true) 
addEventHandler("hideHud",root,myHudFunction) 
  

    triggerEvent("hideHud", getLocalPlayer()) 

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Doesn't work :/

Here is what I did in the other script that triggers the event

function hideInterfaceComponents() 
    triggerEvent("hideHud", getLocalPlayer()) 
     
    loadSettings() 
    saveLanguageInformation() 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), hideInterfaceComponents) 
  

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
  
addEvent ( "hideHud", true ) 
addCommandHandler("showhud", 
function () 
if handler  then 
removeEventHandler("onClientRender",root,renderHud) 
handler = false 
else 
addEventHandler("onClientRender",root,renderHud) 
handler = true 
end 
addEventHandler ( "hideHud", root, myHudFunction ) 
  

  
triggerEvent ( "hideHud", root, getLocalPlayer() ) 
  

  • Moderators
Posted

[quote name=..:D&G:..]Doesn't work :/

Here is what I did in the other script that triggers the event

function hideInterfaceComponents() 
    triggerEvent("hideHud", getLocalPlayer()) 
     
    loadSettings() 
    saveLanguageInformation() 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), hideInterfaceComponents) 
  

1 That other script was already running before you triggered the event?

2 And what happens when you do:

triggerEvent("hideHud", getLocalPlayer()) 
triggerEvent("hideHud", root) 

3 Both are 100% clientside?

4 And what will happen when you put the event in the same script?

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