Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GUI Help (https://forums.graalonline.com/forums/showthread.php?t=134262618)

kingcj 03-30-2011 08:59 AM

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

MrOmega 03-30-2011 09:03 AM

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?

kingcj 03-30-2011 09:12 AM

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();
    }
  }



MrOmega 03-30-2011 09:14 AM

Your last function needs to be outside of onweaponfired

kingcj 03-30-2011 09:20 AM

Alight, but still didn't fix it? The way I call Params[1], is that ok?

MrOmega 03-30-2011 09:22 AM

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]; 



kingcj 03-30-2011 09:26 AM

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?

MrOmega 03-30-2011 09:36 AM

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.

kingcj 03-30-2011 09:47 AM

Gotta spread some around....

Twinny 03-30-2011 10:57 AM

Quote:

Originally Posted by MrOmega (Post 1640066)
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.

cbk1994 03-30-2011 11:00 AM

Quote:

Originally Posted by MrOmega (Post 1640066)
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.

Twinny 03-30-2011 11:33 AM

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 :)

kingcj 03-30-2011 05:52 PM

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!

fowlplay4 03-30-2011 06:07 PM

Quote:

Originally Posted by kingcj (Post 1640091)
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");



kingcj 03-30-2011 07:08 PM

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?

Twinny 03-30-2011 07:55 PM

Quote:

Originally Posted by kingcj (Post 1640098)
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.

kingcj 03-30-2011 09:47 PM

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.

Twinny 03-30-2011 10:00 PM

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.

fowlplay4 03-30-2011 10:01 PM

Quote:

Originally Posted by kingcj (Post 1640138)
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.

cbk1994 03-30-2011 10:01 PM

Quote:

Originally Posted by kingcj (Post 1640138)
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

kingcj 03-30-2011 10:06 PM

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!

kingcj 03-31-2011 12:39 AM

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


All times are GMT +2. The time now is 09:45 PM.

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