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 08-19-2012, 01:59 AM
Bleachlover551 Bleachlover551 is offline
Soul Reaper
Bleachlover551's Avatar
Join Date: Jul 2012
Location: Brunswick
Posts: 34
Bleachlover551 is an unknown quantity at this point
AP Changer Script :)

Hope You Like

PHP Code:
//Script By Toshi!
//#CLIENTSIDE
function onCreated() {
  new 
GuiTextCtrl("MyGUI_TextEdit1") {
    
profile GuiBlueTextProfile;
    
81;
    
5;
    
height 20;
    
text "";
  }
}
function 
onMouseDown(mode) {
  if (
mode == "Left") {
    for (
plplayers) {
      if ( 
mousex in pl.0.5pl.2.5| && mousey in pl.ypl.3|) {
        if (
pl != NULL) {
           new 
GuiWindowCtrl("MyGUI_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "115,126";

    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "AP Changer";
    
100;

    new 
GuiButtonCtrl("MyGUI_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Ap = 0";
      
width 115;
    }
    new 
GuiButtonCtrl("MyGUI_Button2") {
      
profile GuiBlueButtonProfile;
      
text "Ap = 50";
      
width 115;
      
29;
    }
    new 
GuiButtonCtrl("MyGUI_Button3") {
      
profile GuiBlueButtonProfile;
      
text "Ap = 100";
      
width 115;
      
58;
    }
    new 
GuiTextEditCtrl("MyGUI_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 115;
      
0;
      
106;
      
MyGUI_TextEdit1.text player.nick;
    }
      new 
GuiTextEditCtrl("MyGUI_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 115;
      
0;
      
88;
      
MyGUI_TextEdit2.text player.ap;
    }
  }
}
}
function 
MyGUI_Button1.onAction() {
player.ap "0";
}

function 
MyGUI_Button2.onAction() {
player.ap "50";
}

function 
MyGUI_Button3.onAction() {
player.ap "100";
}
        }
      }
    } 
Reply With Quote
  #2  
Old 08-19-2012, 02:02 AM
PeterGraal PeterGraal is offline
Server Developer
Join Date: Jul 2012
Location: USA
Posts: 4
PeterGraal is on a distinguished road
<3 Thanks. Is this the default one, or your own version?
Reply With Quote
  #3  
Old 08-19-2012, 02:08 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
This is completely wrong, you're modifying the normal player object rather than the target player. AP is not possible to properly modify Clientside, you need to trigger to Serverside or else it will not save or appear to other players.
Reply With Quote
  #4  
Old 08-19-2012, 02:23 AM
Bleachlover551 Bleachlover551 is offline
Soul Reaper
Bleachlover551's Avatar
Join Date: Jul 2012
Location: Brunswick
Posts: 34
Bleachlover551 is an unknown quantity at this point
ah i see hangs on....wait....so would look like something like

Example: This?

triggerserver("gui",this.name,"ap=50",MyGUI_TextEd it1.text)

Quote:
Originally Posted by ffcmike View Post
This is completely wrong, you're modifying the normal player object rather than the target player. AP is not possible to properly modify Clientside, you need to trigger to Serverside or else it will not save or appear to other players.
Reply With Quote
  #5  
Old 08-19-2012, 02:29 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 Bleachlover551 View Post
ah i see hangs on....wait....so would look like something like

Example: This?

triggerserver("gui",this.name,"ap=50",MyGUI_TextEd it1.text)
No:

Quote:
Originally Posted by cbk1994 View Post
Ehh...not really.

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.
I'm pretty sure I've pointed you towards these before, and I know I've pointed you toward Jer's scripting guide before.

Also, name your GUI controls properly.
__________________
Reply With Quote
  #6  
Old 08-19-2012, 02:29 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by Bleachlover551 View Post
Example: This?

triggerserver("gui",this.name,"ap=50",MyGUI_TextEd it1.text)
Assigning variables doesn't work like this, you just need to pass 50 as a parameter, and then do something like:

PHP Code:
function onActionServerSide(temp.aptemp.account){
  
temp.pl findplayer(temp.account);
  if(
temp.pl != NULL){
    
temp.pl.ap temp.ap;
  }

Reply With Quote
  #7  
Old 08-19-2012, 11:45 AM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
I would try using a slider in this case, which would allow having more AP options without having to create multiple buttons, then trigger server to actually set it as Chris stated.
PHP Code:
new GuiSliderCtrl("AP_Slider") {
  
profile GuiBlueSliderProfile;
  
10;
  
10;
  
width 160;
  
height 20;
  
range = {0,100};
  
value 30;
  
ticks 10;

__________________
Reply With Quote
  #8  
Old 08-21-2012, 08:48 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Quote:
Originally Posted by Tim_Rocks View Post
I would try using a slider in this case, which would allow having more AP options without having to create multiple buttons, then trigger server to actually set it as Chris stated.
PHP Code:
new GuiSliderCtrl("AP_Slider") {
  
profile GuiBlueSliderProfile;
  
10;
  
10;
  
width 160;
  
height 20;
  
range = {0,100};
  
value 30;
  
ticks 10;

Good idea.
Also I know it's been pointed out already, but changing AP clientside doesn't work.
If you want a simple method of a triggerserver already done then here ya go.
On the clientside when you set the ap.
Which means below //#CLIENTSIDE
PHP Code:
triggerserver("weapon"this"AP"AP_Slider.value); 
Then above //#CLIENTSIDE put this.
PHP Code:
function onActionServerSide(){
  if(
params[0] == "AP"){
    
player.ap params[1];
  }

Probably should of used switch and case but meur.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #9  
Old 08-21-2012, 10:01 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 Gunderak View Post
Probably should of used switch and case but meur.
There's no reason to use a switch statement here.
__________________
Reply With Quote
  #10  
Old 08-21-2012, 12:29 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
There's no reason to use a switch statement here.
Personal preference and that's about it <3
Reply With Quote
  #11  
Old 08-21-2012, 12:38 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Using a switch for params is always a great idea. The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics permit) also offering the potential for faster execution through easier compiler optimization in many cases. Has very little to do with personal preference, and more to do with optimization.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #12  
Old 08-21-2012, 01:58 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xXziroXx View Post
Using a switch for params is always a great idea. The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics permit) also offering the potential for faster execution through easier compiler optimization in many cases. Has very little to do with personal preference, and more to do with optimization.
Not going to use a switch statement for only one or two possibilities.
__________________
Reply With Quote
  #13  
Old 08-21-2012, 02:20 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by Crow View Post
Not going to use a switch statement for only one or two possibilities.
Personally, I always use it regardless of how many possibilities I have <3 It just looks cleaner to me.
Reply With Quote
  #14  
Old 08-21-2012, 07:42 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
PHP Code:
triggerserver("weapon"this"AP"AP_Slider.value); 
While using 'this' works, it is incorrect as it's a reference to the weapon object rather than the name of the weapon, it should be 'this.name'.
Reply With Quote
  #15  
Old 08-21-2012, 10:18 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 xXziroXx View Post
Using a switch for params is always a great idea. The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics permit) also offering the potential for faster execution through easier compiler optimization in many cases. Has very little to do with personal preference, and more to do with optimization.
Personal preference and code readability (clarity) are the only things that matter here. The difference in performance between a switch statement and an if-statement for a couple of conditions is going to be ridiculously trivial and totally negligible.

With that said, I have nothing against switch statements, I just didn't want OP to feel that they were needed every time you need to check a condition.

edit: in fact, at 100,000 iterations, an if loop just barely wins (this is repeatable):

Quote:
if: 0.023976087
switch: 0.026674032
PHP Code:
this.maxlooplimit 100000;
temp.foo "foo";

// test if
temp.start timevar2;

for (
temp.0temp.this.maxlooplimittemp.++) {
  if (
temp.foo == "bar") {
    
// bar
  
} else if (temp.foo == "foo") {
    
// foo
  
} else {
    
// neither
  
}
}

echo(
"if: " @ (timevar2 temp.start));

// test switch
temp.start timevar2;

for (
temp.0temp.this.maxlooplimittemp.++) {
  switch (
temp.foo) {
    case 
"bar":
      
// bar
    
break;
    
    case 
"foo":
      
// foo
    
break;
    
    default:
      
// neither
    
break;
  }
}

echo(
"switch: " @ (timevar2 temp.start)); 
...but again, these differences are completely negligable.
__________________
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:32 AM.


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