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 05-14-2013, 09:20 PM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
setlines CONFUSION

This script isnt working, it is getting to onTabSelect function however just not setting the lines, not understanding why and looking for help yet again.
PHP Code:
this.serverName "server";
this.lngArray = {"de","es","fr","it","ne","no","po","sw"};
this.lngNumber 8;
this.fileArray = {null};
this.prevTab 0;

function 
onActionServerside() {
  
temp.filename null;
  for (
temp.=0;i<lngNumber;++i){
    
temp.filename.add("levels/translations/"@serverName@"_"@lngArray[i]@".po");
  }
  if ( 
params[0] == "loadfile" 
  {
    
this.fileArray.lines ={null};
    for ( 
temp.i=0i<lngNumber;++i){
      
temp.lines loadlines(temp.filename[i]);
      
fileArray.add(temp.lines);
    }
    
player.triggerclient("gui",this.name"loaded"fileArray);
  }
  else if (
params[0] == "save")
  {
    
params[1].savelines(temp.filename0);
    
player.triggerclient("gui",this.name"saved");
  }
  
}

//#CLIENTSIDE
function onActionClientSide() {
  if ( 
params[0] == "loaded")
  {
   
temp.lines params[1];
   
EditTextML.setlines(temp.lines[0]);
  }
  else if ( 
params[0] == "saved")
  {
    
player.chat _("SAVED");
  }
}

...
THERE WAS MORE SCRIPT HERE....
    
    new 
GuiTabCtrl("Trans_Tabs") {
      
profile GuiBlueTabProfile;
      
10;
      
56;
      
width 480;
      
height 24;
      
tabwidth 70;
    
      
clearrows();
      
addrow(0,"Dutch");
      
addrow(1,"Spanish");
      
addrow(2,"French");
      
addrow(3,"Italian");
      
addrow(4,"Nederlands");
      
addrow(5,"Norsk");
      
addrow(6,"Portuges");
      
addrow(7,"Svenska");
      
setSelectedRow(0);
      
thiso.catchevent(Trans_Tabs"onSelect""onTabSelect");
    }  


      new 
GuiMLTextEditCtrl("EditTextML") {
        
profile GuiBlueMLTextEditProfile;
        
10;
        
10;
        
width 480;
        
height 60;
          }
      }
  
....
THERE WAS MORE SCRIPT HERE

//ACTIONS
function onTabSelect(){
  
fileArray[prevTab] = EditTextML.getlines();
  
prevTab Trans_Tabs.getselectedid();
  
EditTextML.setlines(fileArray[prevTab]);

Reply With Quote
  #2  
Old 05-15-2013, 12:04 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
The variables are serverside, but you're trying to set them clientside. You can't do that—your script needs to trigger serverside with whatever data is necessary (e.g. the selected language), and then handle that serverside.

Pretend that the //#CLIENTSIDE line splits your script into two separate scripts. Except for a few special exceptions, those scripts can't share data except through triggers.

I see you're using triggers already, so you probably understand most of this, but here's some more reading (and some examples) about clientside/serverside on Graal:

Quote:
Originally Posted by cbk1994 View Post
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.

To communicate between the server and the client you use something called a trigger. In the past this was accomplished with the triggerAction function, but now it's standard practice to use triggerServer and triggerClient. Simply enough, triggerServer is used to send a "trigger", or a message, from clientside (a player's computer) to the NPC-server. Similarly, triggerClient is used to send a "trigger" from the NPC-server to a player's computer.

The simplest trigger from clientside to server would work like so:

PHP Code:
function onActionServerSide() {
  echo(
"Ping received!");
}

//#CLIENTSIDE
function onCreated() {
  
triggerServer("gui"this.namenull);

In your case you would want to send the player's chat serverside. The onPlayerChats event is called on clientside whenever the player chats.

PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  
// code

You can then check if the player's chat starts with "/copy" by using the string function str.starts(str). This would be "true" if the string starts with the parameter given.

PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/copy")) {
    
// code
  
}

Now, you need to send a trigger to the server with the triggerServer command. triggerServer and triggerClient both have three parameters (two on the latest beta of Graal or for triggerClient): script type, script name, param1[, param2...].]

The script types that you can trigger are "gui" or "weapon", which both trigger a weapon script. Scripters have their own personal preference on which to use, but it doesn't really matter. The other script type is "npc", which triggers a database NPC. If you don't know what that is, don't worry about it yet.

Adding the trigger code would look like so:

PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/copy")) {
    
triggerServer("gui"this.namenull);
  }

this.name is simply referring to the current name of the weapon. It's generally preferred to use this instead of typing the weapon name in case the name were to change.

Then, you would need to "tokenize" the player's chat. This is the same as the explode function found in PHP and other languages. It splits the string into different parts at the "delimiter". You can specify a custom delimiter for str.tokenize(str delimiter), but in this case there is no need to.

PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/copy")) {
    
temp.tokens player.chat.tokenize();
    
triggerServer("gui"this.nametokens);
  }

Now you just need to build the serverside portion of the script. This part of the script will need to identify the command given, identify the player wanted, and the property to copy. You would start by adding the onActionServerSide() event. This is always called when using triggerServer. The parameter you specified in the trigger ("tokens") will be in the first parameter for that function.

PHP Code:
function onActionServerSide(tokens) {
  
// code
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/copy")) {
    
temp.tokens player.chat.tokenize();
    
triggerServer("gui"this.nametokens);
  }

You can then check for the command and find the player

PHP Code:
function onActionServerSide(tokens) {
  if (
tokens[0] == "/copy") {
    
temp.pl findPlayerByCommunityName(tokens[1]);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/copy")) {
    
temp.tokens player.chat.tokenize();
    
triggerServer("gui"this.nametokens);
  }

Now all you need to do is identify the property which is to be copied.

PHP Code:
function onActionServerSide(tokens) {
  if (
tokens[0] == "/copy") {
    
temp.pl findPlayerByCommunityName(tokens[1]);
    
    if (
tokens[2] == "body") {
      
player.body pl.body;
    }
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/copy")) {
    
temp.tokens player.chat.tokenize();
    
triggerServer("gui"this.nametokens);
  }

There's a better way to do that involving dynamic variables but I feel like I've already thoroughly confused you with this post. As I said before, it seems like you're jumping in too fast and you're just going to get lost. Focus on the basics first.
Quote:
Originally Posted by cbk1994 View Post
You can trigger either way back and forth as much as you want. You can create an infinite loop if you want:

PHP Code:
function onActionServerSide(cmd) {
  if (
cmd == "ping") {
    
triggerClient("gui"this.name"ping");
  }
}

//#CLIENTSIDE
function onCreated() {
  
triggerServer("gui"this.name"ping"); // start the loop
}

function 
onActionClientSide(cmd) {
  if (
cmd == "ping") {
    
this.counter ++;
    
player.chat "Pings: " this.counter;
    
triggerServer("gui"this.name"ping");
  }

Though obviously you wouldn't want to do something like that in practical scripting

You can also trigger weapons of other players.

PHP Code:
function onActionServerSide(cmdtargetmsg) {
  if (
cmd == "tell") {
    
temp.pl findPlayerByCommunityName(target);
    
    if (
pl == null) {
      return 
player.chat "(player not found)";
    }
    
    
pl.triggerClient("gui"this.name"tell"player.communitynamemsg);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("tell")) { // format is: tell account "message here"
    
temp.tokens player.chat.tokenize();
    
    
temp.acc tokens[1];
    
temp.msg tokens[2];
    
    
triggerServer("gui"this.name"tell"accmsg);
  }
}

function 
onActionClientSide(cmdsendermsg) {
  if (
cmd == "tell") {
    
player.chat sender ": " msg;
  }

To use this you would say: tell cbk1994 "Hi there ugly!"

That would trigger serverside, try to find a player with the community name 'cbk1994', and if found, trigger clientside on the same weapon for that player. Once it receives the trigger clientside, it would set my chat to 'Engine: Hi there ugly!'.

This is a bit of a silly example since you can set players' chat serverside, but it could be used, for example, if you have some kind of GUI window displaying the message.
If you have any questions, feel free to ask. This is one of the most confusing aspects of GScript for new scripters, and I know it gave me a lot of trouble when I first started.
__________________
Reply With Quote
  #3  
Old 05-15-2013, 12:15 AM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
Thanks, i havent implemented to see if that works yet but i will. I have another question, would it be reasonable to declare these variables as global considering the situation, instead of making two sets of the same thing. Eventually im going to just make one object out of them, because i was having trouble figuring out why i couldnt pass objects in triggers but it was cleared up by fp4 i think. That is insanely important and im kinda upset its not in any documentation.
Reply With Quote
  #4  
Old 05-15-2013, 12:22 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 JohnnyChimpo View Post
Thanks, i havent implemented to see if that works yet but i will. I have another question, would it be reasonable to declare these variables as global considering the situation, instead of making two sets of the same thing. Eventually im going to just make one object out of them, because i was having trouble figuring out why i couldnt pass objects in triggers but it was cleared up by fp4 i think. That is insanely important and im kinda upset its not in any documentation.
Not sure what you mean by global variables.

What are you trying to make? Some kind of text editor for po files?

Also note that this isn't doing what you think it is:

PHP Code:
this.fileArray.lines ={null}; 
That's creating an array with one element, null. You want just

PHP Code:
this.fileArray.lines = {}; // or null, but not both 
__________________
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 01:12 AM.


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