Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   triggeractions and serverside question (https://forums.graalonline.com/forums/showthread.php?t=65064)

wild8900 03-30-2006 09:05 AM

triggeractions and serverside question
 
1 Attachment(s)
Ive been having trouble with triggeraction and serverside. I know nothing about them. I know I need them in most online npcs though.
I was trieing to make it so on clients side when you say /kick (acc), it warps the acc to OSL, it works but only when you have the weapon equiped.
I attached the script for referance or w/e.

hotrian 03-30-2006 09:59 AM

Im only half awake XD so it may not work
 
1 Attachment(s)
I did it in both Gscripts
Gs1 is on the top,Gs2 is below it

wild8900 03-30-2006 10:55 AM

Thanks :D, aside from a few syntax errors (easy to solve), they worked good!
So, how do these actions work? Whats this #p(0)-4?

ApothiX 03-30-2006 03:56 PM

Hmm, that would not give an accurate representation of where the person has been kicked from. It would only say what level the person who kicked the player was in.

PHP Code:

// #p(0) - Action Type (kick)
// #p(1) - Account Name of player to kick
if(actionserverside) {
  if(
strequals(#a,wild8900)) {
    
if(strequals(#p(0),kick)) {
      
this.online 0;
      
setstring this.adminname,#a;
  
      
with(getplayer(#p(1))) {
        
this.online 1;

        
setstring this.levelname,#L;
        
setlevel2 onlinestartlocal.nw3030;
        
say2 You have been kicked by#s(this.adminname)#bFrom the level: #s(this.levelname);
      
}

      if(
this.online == 1) {
        
say2 #p(1) was successfully kicked.;
      
} else {
        
say2 #p(1) is not online.;
      
}
    }
  }
}

//#CLIENTSIDE
if(playerchats) {
  if(
startswith(/kick,#c)) {
    
triggeraction 0,0,serverside,WEAPONNAME,kick#T(#e(5,-1,#c));
  
}


You can probably combine parts of that, and the one hotrian provided. This one alerts you if the person was actually kicked or not, based on their onlinestatus.

wild8900 03-30-2006 10:00 PM

Ok thanks but how does the script work? I need to understand triggeractions and serverside stuff.

hotrian 03-31-2006 02:26 AM

Quote:

Originally Posted by wild8900
Thanks :D, aside from a few syntax errors (easy to solve), they worked good!
So, how do these actions work? Whats this #p(0)-4?

Are you asking what its for?

Edit: I also did note, I dont script in GS1 anymore, So scripting in it for one script here and there is aquard, Sorry for any syntax errors :P

Edit2: Your right, It doesnt send to nc where the player was kicked from, Only where the kicker was at XD

wild8900 03-31-2006 06:56 AM

Quote:

Your right, It doesnt send to nc where the player was kicked from, Only where the kicker was at XD
What do you mean? isnt that like, the same thing?
The message is Admin has kicked player from level

KuJi 03-31-2006 07:39 AM

Uhm, isn't case a lot better then doing if (params[1] == "blah") { } ?

And why not use substring? And is their any reason why .graal was used, and not .nw?


Here, I did some edits, you don't need to use "" anymore as their is no need for tokens.

If theirs a bug with it, just tell me ;O. I tested, it worked fine:

PHP Code:

function onActionServerSide(action) {
  switch (
action) {
    case 
"kick": {
      
plyr findplayer(params[2]);
      if (
plyr.level == "") return;
      if (
plyr.level == "onlinestartlocal.nw") {
        
plyr.setlevel2("jail.graal",33,31);
        
plyr.say2("You have been kicked from#b" SPC params[2SPC "#bNext time you might be jailed!");
      } else {
        
plyr.setlevel2("onlinestartlocal.nw",30.5,12.6);
        
plyr.say2("You have been kicked from#b" SPC params[2SPC "#bNext time you might be jailed!");
      }
      echo(
"NPC-Server:" SPC params[1SPC "has kicked" SPC plyr.level SPC "from" SPC params[2]@".");
      break;
    }
  }
}

//#CLIENTSIDE
function onWeaponfired(){
  if (
player.account == "wild8900"){
    
say2("Commands:#b/kick \"account\"");
  } else {
    
say2("You should not have this item.");
    
destroy();
  }
}
function 
onPlayerChats(){
  if (
player.chat.starts("/kick")) {
    
triggerserver("gui","WEAPONNAME","kick",player.account,player.chat.substring(6,-4)); 
  }


Also, if you use the above (its GS2) make sure you change WEAPONNAME to the name of the weapon.

*Edit* Alright, I added the check..and yeah, I do not know how to use GS2 return :-(. If anyone wants to post the correction way, you may do so, but I think that works fine.

Also, I took player.level off the params, and made it so you can get the level via findplayer (plyr.level). I also didn't test this version.

xAndrewx 03-31-2006 08:07 AM

add a level check, if the player isn't online you'll get an ugly message in RC.

hotrian 03-31-2006 10:21 AM

Yea, I must of been really tired... I do use case lol...

alissalee 03-31-2006 02:15 PM

this may be off topic but if u make the weapon -Staff/kick it would work still much easyer as i found out in my time scripting but wich i have stoped till i understand gs2 better

ZeroTrack 03-31-2006 03:23 PM

#p() or pramas[] refers to the paramater sent from the the triggeraction to the action.. in this case sending paramaters from clientside to serverside so

gs1 (which you shouldn't be using anymore)
triggeraction 0,0,serverside,Weapon,#a,test1,test2;
#a = the first paramater or #p(0)
test1 = the second paramater or #p(1)
so on and so forth

gs2
triggeraction(0,0,"serverside","Weapon",player.acc ount,"test1","test2");
player.account = the first paramter or params[0]

so on and so forth i am sure you get the idea by now and if your not triggering an action to a weapon the it just starts the first paramater after the action its calling

IE: triggeraction(x,y,"serverside",player.account);

hope that cleared it up a bit better for you

ApothiX 03-31-2006 03:48 PM

Quote:

Originally Posted by KuJi
Uhm, isn't case a lot better then doing if (params[1] == "blah") { } ?

The person did not specify if they were using the old or new engine, so you must assume that they are using the old. There is no such thing as a case statement in the old engine. Also, using a switch-case statement when there will be only one check is unnecessary.

Quote:

Originally Posted by KuJi
And why not use substring?
Here, I did some edits, you don't need to use "" anymore as their is no need for tokens.

Did you not even look at the example I provided? X_x

>> triggeraction 0,0,serverside,WEAPONNAME,kick,#T(#e(5,-1,#c));

KuJi 03-31-2006 10:06 PM

[QUOTE=ApothiX]The person did not specify if they were using the old or new engine, so you must assume that they are using the old. There is no such thing as a case statement in the old engine. Also, using a switch-case statement when there will be only one check is unnecessary.[/QUOTE

I do not assume that they are using the old one, because I haven't seen any private server thats been up for a week or two with GS2 NOT ENABLED.

Quote:

Did you not even look at the example I provided? X_x

>> triggeraction 0,0,serverside,WEAPONNAME,kick,#T(#e(5,-1,#c));
^------- GS1, I used GS2.

heres some help for yourself:
triggerserver("gui","WEAPONNAME","Params","Go","He re");

:-). Use it..it was made for a reason.

Bl0nkt 03-31-2006 10:19 PM

Quote:

Originally Posted by wild8900
Thanks :D, aside from a few syntax errors (easy to solve), they worked good!
So, how do these actions work? Whats this #p(0)-4?

#p(#) (GS1) and params[#] (GS2) are for transfering information from the client -> server.

Here's a GS1 example:

NPC Code:
if (created) setshape 1, 32, 32;

if (actiontest) {
message You said #p(0)!;
}

//#CLIENTSIDE
if (playerchats) {
triggeraction x, y, test, #c;
}



Look in the triggeraction. #c is param 0, or #p(0). One thing you should know is that most things start with a value of 0. These include tokenizing, arrays, etc...

Anyway, param 0 is #c, or the player's chat. It's transfering what the player sayed in the action. So, when the action is recieved on the serverside, it's telling you param 0, or #p(0).

Triggeractions also need a surface to trigger. This can either be a non-transparent surface of an image or a setshape.

Here's an example of how this would work in GS2.

NPC Code:
function onCreated()
setshape(1, 32, 32);

function onActionTest()
message("You said" SPC params[0] @ "!");

//#CLIENTSIDE
function onPlayerChats()
triggerAction(x, y, "test", player.chat);



Not too much different.


All times are GMT +2. The time now is 05:23 PM.

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