Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2011, 08:59 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
GUI Help

Ok so I've never tried to script with a GUI and am just trying to mess around with it a little bit. I want to change a player's name from the GUI Edit Text box, but when I try nothing happens. I can get the player to chat what has been typed in the box when I hit enter, but not change the player's name. I have also tried to send it severside just in case it works like that, but with no luck. I've looked at the Graal Bible and it has the best documentation on GUIs, but like I said I've never messed with GUIs before and need a little help. Thanks as always
- Zie
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #2  
Old 03-30-2011, 09:03 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
script snippets of what your doing would allow me to help better, but player.nick needs to changed serverside.

Try to echo the the text on serverside after it is received, anything?
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #3  
Old 03-30-2011, 09:12 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Here it's not really anything special lol

PHP Code:
function onActionSeverSide() {
  if (
params[0] == "namer") {
    
params[1] = player.nick;
    echo(@ 
params[1]);
  }
}
      
//#CLIENTSIDE
function onWeaponFired() {
  new 
GuiWindowCtrl("Name_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "316,157";

    
canclose false;
    
canmaximize false;
    
canminimize false;
    
canmove false;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Your Name";
    
359;
    
228;

    new 
GuiTextEditCtrl("Name_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
21;
      
40;
    }
    new 
GuiTextCtrl("Name_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "What's Your Name?";
      
width 96;
      
19;
      
9;
    }
    function 
Name_TextEdit1.onAction() {
      
triggerserver("gui",this.name,"namer",Name_TextEdit1.text);
      
Name_Window1.destroy();
    }
  }

__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #4  
Old 03-30-2011, 09:14 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Your last function needs to be outside of onweaponfired
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #5  
Old 03-30-2011, 09:20 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Alight, but still didn't fix it? The way I call Params[1], is that ok?
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #6  
Old 03-30-2011, 09:22 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
Ah, look at your OnActionServerside

Also it should be player.nick = params[ 1];

Another thing, your way may work but I usually send the the players account in a param and then reference it to that to change player vars. More thurough I suppose.

Eg
PHP Code:
triggerserver"gui"name"Foo""Bar"player.account); 
Then serverside do

PHP Code:
function onActionServerside()
{
  if (
params[0] == "Foo")
    
findplayerparams[2]).nick params[1]; 

__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #7  
Old 03-30-2011, 09:26 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Thanks...... sorry bout that just a little tired at 0225. Also is there a command for limiting the amount of characters allowed to be typed in this box?
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #8  
Old 03-30-2011, 09:36 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
No problem, just rep if it helped ya.

As for your other question, there is no command, the workaround I haved used involves you having to use GUI.onTextChanged() and check with GUI.text.length(), then modify GUI.text if its too long.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #9  
Old 03-30-2011, 09:47 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Gotta spread some around....
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #10  
Old 03-30-2011, 10:57 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by MrOmega View Post
Another thing, your way may work but I usually send the the players account in a param and then reference it to that to change player vars. More thurough I suppose.
Completely unnecessary as the only thing is does it bloat the trigger up. On actionServerSide() will always reference the player who called it. Please don't teach anyone this habit

Also,

PHP Code:
function Name_TextEdit1.onAction()
  
player.nick Name_TextEdit1.text
Should work but make sure you don't write that function inside another function.
Reply With Quote
  #11  
Old 03-30-2011, 11:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by MrOmega View Post
Ah, look at your OnActionServerside

Also it should be player.nick = params[ 1];

Another thing, your way may work but I usually send the the players account in a param and then reference it to that to change player vars. More thurough I suppose.
No, no, no, no, no!

Not only is it completely unnecessary but it's also a huge security risk. A memory editor could change their account on their end to mimic another player's and carry out actions as them.
__________________
Reply With Quote
  #12  
Old 03-30-2011, 11:33 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
So, I thought the object might have a maxchars variable to limit the amount of characters typed but apparently it doesn't. Anyhoo,

PHP Code:
function onActionServerSide() {
  if (
params[0] == "changenick") {
    
player.nick params[1];
    
player.chat "Your nick has been changed";
  }
}

//#CLIENTSIDE
function onCreated() {
  if (
test_window != NULLtest_window.destroy();
  new 
GuiWindowCtrl("test_window") {
    
profile GuiBlueWindowProfile;
    
resize(1,1,200,100);
    
text "blah";
  
    new 
GuiTextEditCtrl("nicknametext") {
      
profile GuiBlueTextEditProfile;
      
resize(10,45,160,30);
      
text "Type here!";
    }
  }
  
//onDebug(nicknametext);
}

function 
nicknametext.onMouseDown() {
  if (!
nicknametext.clickedonce) {
    
nicknametext.text "";
    
nicknametext.clickedonce true;
  }
}

function 
nicknametext.onTextChanged() {
  if (
nicknametext.text.length() > 10)
    
nicknametext.text nicknametext.text.substring(0,10);
}

function 
nicknametext.onAction()
  
triggerserver("gui"this.name"changenick"nicknametext.text);
  


/* Debug method
  Press f2 after calling this function */
function onDebug(obj) {
  
say2("Press f2 to read output!");
  echo(
"\nFUNCTIONS");
  for (
obj.getfunctions())
    echo(
f);
  echo(
"\nVARIABLES");
  for (
obj.getvarnames())
    
printf("%s=%s"fobj.(@f));
  echo(
"\nPROFILE VARS");
  for (
fobj.profile.getvarnames())
    
printf("%s=%s"fobj.profile.(@f));

If you uncomment the onDebug() line, you can run that script then press F2 in game and it will show you all the functions/variables available for that object which can be useful to determine what the object is capable of. Can change it to onDebug(test_window) or even onDebug(player) to see the different functions/variables for objects
Reply With Quote
  #13  
Old 03-30-2011, 05:52 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Ok so don't use params[1] because onActionServerside() references the player that used it, and it's a security risk? Thanks for the help!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #14  
Old 03-30-2011, 06:07 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by kingcj View Post
Ok so don't use params[1] because onActionServerside() references the player that used it, and it's a security risk? Thanks for the help!
If you're just changing your own player's data, you don't need to pass their account to the server because your player object is accessible.

Scenario: Changing your own player's chat. (Ignore the fact that you can do it on the client-side...)

BAD:

PHP Code:
function onActionServerside() {
  
// Potentially allowing hackers to make people laugh uncontrollably.
  
with (findplayer(params[1])) {
    
player.chat "haha";
  }
}
//#CLIENTSIDE
function onCreated() {
  
// A hacker could change the player.account variable that's being sent.
  
triggerserver("gui"this.name"example"player.account); 

GOOD:

PHP Code:
function onActionServerside() {
  
player.chat "haha";
}
//#CLIENTSIDE
function onCreated() {
  
triggerserver("gui"this.name"example");

__________________
Quote:
Reply With Quote
  #15  
Old 03-30-2011, 07:08 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Ok but now it won't change the nick to the input from the Edit text for some reason? I would still need to send that severside and use it, but how would I safely do that?
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #16  
Old 03-30-2011, 07:55 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by kingcj View Post
Ok but now it won't change the nick to the input from the Edit text for some reason? I would still need to send that severside and use it, but how would I safely do that?
My example above was a working script. It successfully changed a players nick serverside.
Reply With Quote
  #17  
Old 03-30-2011, 09:47 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Yes it does, however, you send the text and use params[1] as well, which is what I was under the impression was unsafe. I don't understand how yours is more secure is what I was trying to say.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #18  
Old 03-30-2011, 10:00 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
The unsafe part was sending the account name through the trigger since hackers could manipulate it to affect someone else. Sending a new nickname doesn't have the same safety concerns. There are ways to protect it but completely unnecessary.
Reply With Quote
  #19  
Old 03-30-2011, 10:01 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by kingcj View Post
Yes it does, however, you send the text and use params[1] as well, which is what I was under the impression was unsafe. I don't understand how yours is more secure is what I was trying to say.
The 'unsafe' part was sending the account that you wanted to change the nickname for. Sending player input was fine however.
__________________
Quote:

Last edited by fowlplay4; 03-30-2011 at 10:01 PM.. Reason: oh forums...
Reply With Quote
  #20  
Old 03-30-2011, 10:01 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by kingcj View Post
Yes it does, however, you send the text and use params[1] as well, which is what I was under the impression was unsafe. I don't understand how yours is more secure is what I was trying to say.
The issue is not with using the params array. Do you understand how parameters work?

PHP Code:
function onCreated() {
  
myFunction("one""two""three");
}

function 
myFunction() {
  echo(
params[0] @ ", " params[1] @ ", " params[2]);

is exactly the same as

PHP Code:
function onCreated() {
  
myFunction("one""two""three");
}

function 
myFunction(p1p2p3) {
  echo(
p1 ", " p2 ", " p3);

When you put variable names inside the parentheses like that, you're assigning the parameter values to those variables.

The security problem I referenced was in relation to sending the player's account. The script Twinny posted is fine, as was yours.

edit: wow way too slow
__________________
Reply With Quote
  #21  
Old 03-30-2011, 10:06 PM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Ah I see now! You were all talking about Mr. Omega's response not my script. And Yes I believe I know how parameters work, also, Thanks for the help!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #22  
Old 03-31-2011, 12:39 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Ok so looking over the GUI controls agian I'm Curious as how to get rows and columns into a GUI. The Graal Bible has some commands, but do you place them in like multi line text? I'm confused on exactly how to implement them
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:37 AM.


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