Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Playerworld Script Uploading Problem (https://forums.graalonline.com/forums/showthread.php?t=134262553)

mrnothersan 03-26-2011 09:00 PM

Playerworld Script Uploading Problem
 
Hello,

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?

Please explain to me how to add a gui from here: http://wiki.graal.net/index.php/Crea...F_Object_Types

Thanks
mrnothersan

WhiteDragon 03-26-2011 09:03 PM

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.

mrnothersan 03-26-2011 09:06 PM

Quote:

Originally Posted by WhiteDragon (Post 1639130)
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.

Thanks
mrnothersan

WhiteDragon 03-26-2011 09:11 PM

Quote:

Originally Posted by mrnothersan (Post 1639133)
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.

Twinny 03-26-2011 09:13 PM

Quote:

Originally Posted by mrnothersan (Post 1639133)
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.

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


You need events to execute your scripts :)

mrnothersan 03-26-2011 09:14 PM

Quote:

Originally Posted by WhiteDragon (Post 1639135)
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;
  
10;
  
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


Thanks

WhiteDragon 03-26-2011 09:36 PM

Quote:

Originally Posted by mrnothersan (Post 1639137)
Where do I put this code:
PHP Code:

function onCreated()
  
this.join("yourclassgoeshere");
//#CLIENTSIDE
function onCreated() {
  
drawGUI(); //calls function in class



In a weapon.

mrnothersan 03-26-2011 09:47 PM

It is not a weapon I need though. I have seen playerworlds that when you enter it just appears with the message in the GuiWindowCtrl.

Thanks

WhiteDragon 03-26-2011 09:59 PM

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.

mrnothersan 03-26-2011 10:05 PM

Hi

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";
}



MN

WhiteDragon 03-26-2011 10:14 PM

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.

mrnothersan 03-26-2011 10:15 PM

Ok will try that..How do I put the script in the weapon? Do I put the weapon in graal editor and add it into the npc?

Twinny 03-26-2011 10:15 PM

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.

You should take a moment to really understand the language before diving into complex operations. Try reading the tutorials section at http://wiki.graal.net/index.php/Creation/Dev/GScript

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.

mrnothersan 03-26-2011 10:16 PM

Thanks Twinny, will research a bit more.
Please look at my ip ranges thread also.

MN

cbk1994 03-26-2011 11:01 PM

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 (Post 1579584)
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.

mrnothersan 03-27-2011 09:53 AM

How do I create a weapon? :)

BioWare 03-27-2011 03:05 PM

Quote:

Originally Posted by mrnothersan (Post 1639293)
How do I create a weapon? :)

Study this

http://i55.tinypic.com/20htsft.png

mrnothersan 04-02-2011 04:06 PM

Hello,

Thanks for all your advice.

This is the code I have in the weapon:

PHP Code:

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

Hope you can give me some advice

Thanks

fowlplay4 04-02-2011 05:20 PM

You need //#CLIENTSIDE in your class script too.

mrnothersan 04-02-2011 07:00 PM

Quote:

Originally Posted by fowlplay4 (Post 1640745)
You need //#CLIENTSIDE in your class script too.

Added that.
My classes script now looks like this:

PHP Code:

//#CLIENTSIDE
public function drawGUI() {
new 
GuiWindowCtrl("Test_Window") {
  
profile GuiBlueWindowProfile;
  
10;
  
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

Deas_Voice 04-02-2011 07:30 PM

Quote:

Originally Posted by mrnothersan (Post 1640766)
HTML 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))


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.

mrnothersan 04-02-2011 07:37 PM

Okay,
So why doesn't my gui appear when I log into my world?

Regards

salesman 04-02-2011 08:01 PM

are you adding the weapon to the player(s)?

mrnothersan 04-02-2011 08:10 PM

Quote:

Originally Posted by salesman (Post 1640778)
are you adding the weapon to the player(s)?

How would I do that?

cbk1994 04-02-2011 08:18 PM

Quote:

Originally Posted by mrnothersan (Post 1640780)
How would I do that?

Add to Control-NPC script:

PHP Code:

function onActionPlayerOnline() { // this is called every time a player logs on
  
player.addWeapon("MyWeaponName");



mrnothersan 04-02-2011 08:25 PM

Quote:

Originally Posted by cbk1994 (Post 1640786)
Add to Control-NPC script:

PHP Code:

function onActionPlayerOnline() { // this is called every time a player logs on
  
player.addWeapon("MyWeaponName");



Great!!
Thanks so much it worked!!
How do I add text inside the GUI?

Regards

cbk1994 04-02-2011 08:33 PM

Quote:

Originally Posted by mrnothersan (Post 1640789)
Great!!
Thanks so much it worked!!
How do I add text inside the GUI?

Regards

Add a GuiTextCtrl (or GuiMLTextCtrl) inside it.

mrnothersan 04-02-2011 08:43 PM

Quote:

Originally Posted by cbk1994 (Post 1640790)
Add a GuiTextCtrl (or GuiMLTextCtrl) inside it.

Thank you.
Last thing, how do I add multiple lines of text?

Thanks

cbk1994 04-02-2011 08:50 PM

Quote:

Originally Posted by mrnothersan (Post 1640792)
Thank you.
Last thing, how do I add multiple lines of text?

Thanks

Use <br> to separate multiple lines inside a GuiMLTextCtrl.

PHP Code:

text "line one<br>line two<br>line three"

\n might also work, I don't recall.

mrnothersan 04-02-2011 08:50 PM

Ahh, yes found that out...thanks for all your help!!!

mrnothersan 04-02-2011 09:04 PM

I have also added a GuiTabCtrl. How do I add text inside the different tabs so each tab is different?

Last question on this, I promise!

fowlplay4 04-02-2011 09:19 PM

Quote:

Originally Posted by mrnothersan (Post 1640796)
I have also added a GuiTabCtrl. How do I add text inside the different tabs so each tab is different?

Last question on this, I promise!

http://wiki.graal.net/index.php/Crea...d_Window_Panes


All times are GMT +2. The time now is 02:57 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.