Jump to content

[Question] Variable?


Recommended Posts

Problem solved by using custom events and the triggerClientEvent function!

Hello guys,

I made a login script and am busy with a RPG script, but since i'm new to scripting, it's not easy. However, the login script works and i've made a GUI in which you can choose which class (police, medic, criminal) you want to be. The last one is in the RPG script. However, the problem is that both the login window and the class-chooser window show up at the same time, so i'd rather have the player to first login, and then the class-chooser window shows up and the player chooses his class / team.

Does anyone know how i can do this the easiest, because i am not that good in scripting. Maybe some kind of really global variable that can work between different scripts/resources, or something else?

Thanks in advance!

Edited by Guest
Link to comment

Well, if you've read the GUI tutorials (on the wiki, see here and here), you know they add a "guiSetVisible(WindowElement, false)" at the end of the definition of the window, which is loaded when the resource starts.

You can then toggle the visibility of the windows by using the same function (guiSetVisible).

Is this something you've neglected, or are you for some reason going for another kind of solution?

If so, could I have some more details about how you've set things up, so we can look at alternatives?

[EDITed] Added links, fixed typo

Link to comment
Well, if you've read the GUI tutorial, you know they add a "guiSetVisible(WindowElement, false)" at the end of the definition of the window, which is loaded when the resource starts.

You can then toggle the visibility of the windows by using the same function (guiSetVisible).

Is this something you've neglected, or are you for some reason going for another kind of solution?

If so, could I have some more details about how you've set things up, so we can look at alternatives?

Yes, i know that, but i don't know how i could use that. Let me explain my setup a bit:

I have the RPG resource, which show the class chooser when the resource starts. In the meta file of the RPG scripts it includes the login resource, that also shows the login window when that resource starts. So there are 2 windows that start on the start of their resource.

What i would like, is that when a player logs in with the login script, it sets a variable (like playerLoggedIn) to true, and that the RPG script shows the class chooser when that variable is set to true.

Or maybe i could use the event onPlayerLogin, but does that also works when a player logs in through the GUI? And it's a server side-event, and my GUI for choosing the class is a client-side script, so would that work? Or else maybe i could make my own event, but i have know idea how i could do that. Any ideas?

Link to comment

Alright, well, first of all: What RPG resource? o.O

And what login resource, for that matter?

If this login resource utilizes the built-in accounts system, then the onPlayerLogin could work.

You're right, it's a server event, so it wouldn't trigger anything client-side, however, you could trigger a client event on the RPG's server side script when a login occurs, and then only draw the GUI after the login has happened instead of "onResourceStart" or what ever.

So for instance:

RPG server code:

function drawGUIOnLogin()
triggerClientEvent("onPlayerLoginC", source)
end
addEventHandler("onPlayerLogin", getResourceRoot(), drawGUIOnLogin)

client side:

function drawCharacterMenu()
createCharMenu() --this is whatever would usually get called at resource start
end
addEvent("onPlayerLoginC", true)
addEventHandler("onPlayerLoginC", getResourceRoot(), drawCharacterMenu)

OR:

just change the original draw function to include the guiSetVisible(false)

function createCharMenu() -- this is the function that's already there, creating the GUI
-- stuff that creates GUI elements --
guiSetVisible(Wnd, false) -- wnd = the frame element that was just created, just add this line
end
 
function toggleCharWndVisibility()
if guiGetVisible(Wnd) == true then -- Wnd is your character window thingy's element pointer
guiSetVisible(Wnd, false)
else
guiSetVisible(Wnd, true)
end
end
addEvent("onPlayerLoginC", true)
addEventHanlder("onPlayerLoginC", getResourceRoot(), toggleCharWndVisibility)

Now there's no guarantee ANY of this will work, I just kinda winged it, and it's all untested

But you get the idea, right?

[EDIT]

Nevermind anymore, i solved my problem by making a custom event and using the triggerClientEvent function.

Thanks anyway for your help ;).

Ah, well... nvm that then. Glad you got it to work.

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