I am trying to upload a GUI to my playerworld (Dev mrnothersan). I am trying to add GuiWindowCtrl. I have tried adding a new class and naming it "gui" and then putting the script from here: http://wiki.graal.net/index.php/Crea.../GuiWindowCtrl in there but when I log into my playerworld, it doesn't work.
The script I have added in Classes is:
NPC Code:
new GuiWindowCtrl("Test_Window") {
profile = GuiBlueWindowProfile;
x = 10;
y = 10;
width = 160;
height = 80;
text = "Window";
}
I have not touched anything else. Do I have to upload the PNG image of it or something?
You need to actually make that code run. Putting code in a class doesn't do anything by itself.
Put this in a weapon:
PHP Code:
//#CLIENTSIDE
function onWeaponFired() {
player.chat = "Whoa, 'tis workin'!";
}
And add that weapon to your player. When you fire the weapon your chat should change.
Now, just replace that line in the middle with your GUI-creating code, and it should create.
Hi
Thanks for your reply.
It is not a weapon we want to add. We would like to add the GuiWindowCtrl GUI to our playerworld so when you log into the playerworld it opens automatically with some "Welcome" text in.
It is not a weapon we want to add. We would like to add the GuiWindowCtrl GUI to our playerworld so when you log into the playerworld it opens automatically with some "Welcome" text in.
Then simply change onWeaponFired to onCreated, and make sure everyone gets that weapon when they login.
Putting code in a class doesn't do anything at all. To use a class, you need to join the class to a weapon or NPC. You can think of your classes as a library of useful snippets of code.
Basically, you need to start everything in a weapon or NPC, and you can pull stuff from classes inside the weapon or NPC.
Thanks for your reply.
It is not a weapon we want to add. We would like to add the GuiWindowCtrl GUI to our playerworld so when you log into the playerworld it opens automatically with some "Welcome" text in.
Thanks
mrnothersan
You will still need an event to run it...
For the class, put that code in a function like
PHP Code:
public function drawGUI() { //that code goes here }
then, have a weapon every player has. You can use it's clientside onCreated to draw the gui,
PHP Code:
function onCreated() this.join("yourclassgoeshere"); //#CLIENTSIDE function onCreated() { drawGUI(); //calls function in class }
Then simply change onWeaponFired to onCreated, and make sure everyone gets that weapon when they login.
Putting code in a class doesn't do anything at all. To use a class, you need to join the class to a weapon or NPC. You can think of your classes as a library of useful snippets of code.
Basically, you need to start everything in a weapon or NPC, and you can pull stuff from classes inside the weapon or NPC.
Hey
This is the code I have in Classes:
PHP Code:
public function drawGUI() { new GuiWindowCtrl("Test_Window") { profile = GuiBlueWindowProfile; x = 10; y = 10; width = 160; height = 80; text = "Window"; }
Where do I put this code:
PHP Code:
function onCreated() this.join("yourclassgoeshere"); //#CLIENTSIDE function onCreated() { drawGUI(); //calls function in class }
Weapon scripts run without firing the weapon. It just depends on what function the code is in. If the code is in onCreated it will run whether you fire the weapon manually or not.
Thanks for your reply.
I don't really understand what you mean. Can you tell me in simple terms how to add this Gui: http://wiki.graal.net/index.php/File...rol_window.png to my playerworld so it appears when everyone logs into it.
I have gone onto the wiki and found this script for that gui:
NPC Code:
new GuiWindowCtrl("Test_Window") {
profile = GuiBlueWindowProfile;
x = 10;
y = 10;
width = 160;
height = 80;
text = "Window";
}
See my first reply to the thread. If you can figure out how to make it pop up when you fire the weapon, it's very easy to change it so it always pops up when you login.
OK so, in order for that code to be executed, you need a function/event. Functions and events need to be called.
Say you want to have this executed,'
PHP Code:
echo("I'm a snippet!");
You can place this in an event. Events are called when certain criteria are met. For instance, function onCreated() is called when the script is first created. For clients, this is every time you login. There are others like function onWeaponFired() which is called whenever you press D while the weapon is selected.
Classes, unlike weapons, cannot operate by themselves. They need to be joined to an object in order to function. This can things like weapons, temporary NPCs or even the player object. This is why we say you need a weapon. A weapon is truly the easiest way for your GUI to work. It's possible to have the class join the player object (thus negating the need for the weapon) but it seems this is quite beyond your technical level at the moment.
To utilise the weapon method, create a weapon in RC and add the GUI script to the onCreated event. Next, add an entry in the onActionPlayerOnline to check whether the player has the weapon. If not, add it to them.
A weapon is not necessarily a weapon. In most cases you will have system "weapons" in addition to normal weapons.
Weapons whose names start with a dash aren't shown in the player's inventory (if you have a custom inventory, you can name them differently, of course).
Assuming you don't have a custom inventory, you'll want to create a weapon named something like -LoginWindow and place this code in it:
PHP Code:
//#CLIENTSIDE
function onCreated() {
new GuiWindowCtrl("MyWindow") {
profile = GuiBlueWindowProfile;
width = 200;
height = 200;
text = "Window";
}
}
Now if you open your player's attributes and add -LoginWindow to yourself, you'll see that every time you login the window opens automatically.
Classes are a freak of GScript. I don't know a way to compare them to any other language. Since GS2 doesn't have actual class support (inheritance, custom objects, etc), classes allow you to reuse code. When you join a class to a weapon, it's essentially copying and pasting the code inside the class into the weapon so you can use any of the code in the class in that weapon.
The only way to actually run code on clientside (excepting level NPCs and DB NPCs) is with a weapon. Since DB NPCs and level NPCs are stuck to a single level, if you want to do anything clientside you will want to use a weapon.
An explanation of clientside/serverside:
Quote:
Originally Posted by cbk1994
There are essentially two different ways you script: on serverside, or on clientside. If a script is serverside, it means that the NPC-server interprets and performs the code. The advantage to this is that you know the code can't be tamperered with. If the code is clientside, it means that it is ran on the computer of the player. This has the advantage of being faster and not requiring communication with the server, but has the disadvantage of being less secure.
Since serverside is not performed for a specific player it cannot display interface graphics (HUDs, etc). It also can't handle player chat events, among others.
If you haven't seen it already, this video can be helpful in explaining NC a bit:
There are a lot of things I would change in the video now but it might be useful. Maybe I should do a follow-up of it.
Let me know if there's anything you don't understand.
function onCreated() this.join("testgui"); //#CLIENTSIDE function onCreated() { drawGUI(); }
This is the code I have in the class:
PHP Code:
public function drawGUI() { new GuiWindowCtrl("Test_Window") { profile = GuiBlueWindowProfile; x = 10; y = 10; width = 160; height = 80; text = "Window"; } }
What I want it to do is the Gui Control Window to appear when I log into my playerworld.
I have uploaded the image of the gui to levels/images and set the weapon icon to the gui filename.
Added that.
My classes script now looks like this:
PHP Code:
//#CLIENTSIDE
public function drawGUI() {
new GuiWindowCtrl("Test_Window") {
profile = GuiBlueWindowProfile;
x = 10;
y = 10;
width = 160;
height = 80;
text = "Window";
}
}
It is giving errors also in Remote Control.
Here are the errors
NPC Code:
Script testgui updated by mrnothersan
Script: Function addtiledef not found at line 3 in script of npcs[2] (in level building_edittest.nw at pos (33, 40))
Script: Function putnpc not found at line 3 in script of npcs[1] (in level building_edittest.nw at pos (3, 29))
Please advise on what I am doing wrong.
Thanks
Dominic
Script testgui updated by mrnothersan
Script: Function addtiledef not found at line 3 in script of npcs[2] (in level building_edittest.nw at pos (33, 40))
Script: Function putnpc not found at line 3 in script of npcs[1] (in level building_edittest.nw at pos (3, 29))
you doinng nothing wrong, those are errors from level-npcs.
if you read what it is saying, it's pretty clear and common'sense to assume it's a levelnpc error
somehow, i'm doubting that you are learning anything from this, if your posting every little thing that you think is wrong, stop relying on others to fix your issues if you want to learn anything.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!