Jump to content

GUI wont show


bamby12

Recommended Posts

Posted

i want to show a gui when a player logs in but it dosnt work, heres the code:

server:

  
addEvent("showGUI") 
function onlogin(player) 
triggerClientEvent("showGUI", player) 
end 
addEventHandler("onPlayerLogin",getRootElement(),onlogin) 
  

client:

  
addEvent("showGUI") 
function guishow(player) 
guiSetVisible(GUIEditor_Window[1],true) 
end 
addEventHandler("showGUI",getRootElement(),guishow) 
  

Posted

because first argument passed by "onPlayerLogin" event is player's previous account, not the player element

player element is the source of the event.

and you're not specifying for which player the event should be triggered.

-- server 
function onlogin() 
  triggerClientEvent(source, "showGUI", source) 
end 
addEventHandler("onPlayerLogin", getRootElement(), onlogin) 

and you dont need (player) in client handler.

Posted
i want to show a gui when a player logs in but it dosnt work, heres the code:

server:

  
addEvent("showGUI") 
function onlogin(player) 
triggerClientEvent("showGUI", player) 
end 
addEventHandler("onPlayerLogin",getRootElement(),onlogin) 
  

client:

  
addEvent("showGUI") 
function guishow(player) 
guiSetVisible(GUIEditor_Window[1],true) 
end 
addEventHandler("showGUI",getRootElement(),guishow) 
  

use in Client side

  
function guishow() 
guiSetVisible(GUIEditor_Window[1],true) 
end 
addEventHandler("onClientResourceStart",getRootElement(),guishow) 
  

Posted
use in Client side
  
function guishow() 
guiSetVisible(GUIEditor_Window[1],true) 
end 
addEventHandler("onClientResourceStart",getRootElement(),guishow) 
  

1. if you didn't notice, gui is set to show on player login, not on join.

2. your script will show the window every time ANY resource starts.

Posted

The clientside added event must be allowed to get triggered from serverside, set allowRemoteTrigger to true:

--client 
addEvent("showGUI", true) 

You dont need to add the event serverside btw, you can remove it there.

Posted

agree: D just made a mistake it would be wise to do next / as do not need to use some functions not to do so, simply attach it to the Events button

Posted

1 more think i want a button to set a players team but when i click on the button it dosnt do anything and i dont get errors :P

heres the code:

server:

  
function chooseteam(player) 
setPlayerTeam" class="kw6">setPlayerTeam ( player, getTeamFromName("team") )--i dno why it says class = "kw6" here  
end 
addEvent("setteam",true) 
addEventHandler("setteam", resourceRoot, chooseteam) 
  

client:

  
addEventHandler("onClientGUIClick", GUIEditor_Button[1], clickbutton, false) 
function clickbutton(player) 
triggerServerEvent("setteam",getLocalPlayer()) 
guiSetVisible("GUIEditor_Window[1]", false) 
showCursor(false) 
end 
  

Posted

In the client file, put the addEventHandler under the function. clickbutton must first be defined before you can assign it to an event ;)

In the server file, you're expecting a player variable, but that will just be nil. The source of your event will be the player, so use "source" instead of "player" in setPlayerTeam. Reason: the second argument in triggerServerEvent will be the source.

(that class kw6 is a bug in the forum with setPlayerTeam)

Posted

ok i put the handler into the function that opens the gui on login and now the buttons work but still dont change the players team, any more help is appreciated.

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