Jump to content

Code doesn't run


Dzakub

Recommended Posts

Hi.

I want to make a simple rules window appearing when player connect. I've got problem when I want to hide the window (or destroy) when player click Accept button. It does nothing :/

Please help me. Here is the code:

button = nil
function createRules()
 
window = guiCreateWindow(372,198,820,611,"Rules",false)
memo = guiCreateMemo(0.0463,0.0753,0.9146,0.7889,"",true,window)
guiMemoSetReadOnly(memo,true)
button = guiCreateButton(0.3085,0.8903,0.361,0.0949,"Accept",true,window)
guiSetVisible ( window, true )
showCursor ( source, true )
end
function hideRules()
destroyElement(window)
showCursor ( source, false )
end
addEventHandler ( "onClientGUIClick", getElementID(button), hideRules )
addEventHandler ("onClientResourceStart", getRootElement(), createRules)

Link to comment

I'm going to be lazy here, but you really should learn why this works instead:

function createRules()
   window = guiCreateWindow(372,198,820,611,"Rules",false)
   memo = guiCreateMemo(0.0463,0.0753,0.9146,0.7889,"",true,window)
guiMemoSetReadOnly(memo,true)
   button = guiCreateButton(0.3085,0.8903,0.361,0.0949,"Accept",true,window)
addEventHandler ( "onClientGUIClick", button, hideRules )  --cannot add an event handler to a nil element, so you add the handler here
guiSetVisible ( window, true )
showCursor ( true )  --clientside showCursor only affects the local client, no player element to be passed
end
 
function hideRules()
removeEventHandler ( "onClientGUIClick", button, hideRules )  --remove the handler before destruction of the element (shouldn't be necessary, but this is tidier)
destroyElement(window)
showCursor ( false )  --clientside showCursor only affects the local client, no player element to be passed
end
 
addEventHandler ("onClientResourceStart", getResourceRootElement(getThisResource()), createRules)  --"onClientResourceStart" attaches to resource root elements, attaching to Root would restart this script when ANY resource started - including maps

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