Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   triggeraction vs player.trigger (https://forums.graalonline.com/forums/showthread.php?t=84459)

Tyhm 03-02-2009 02:04 PM

triggeraction vs player.trigger
 
Here's the thing - I really, really hate the triggeraction(targetx+1.5,targety+1.5,hit,2); technique. What happens if the target's lagging? What happens if he moves between the point that you had him lined up in your sites and took the shot and the point that the action triggers on his spot?

And yet I find myself with a script that's almost finished - except that the previous scripter used triggeraction. I've got a whole beautiful (not elegant, I don't do elegant) subroutine for detecting which players are about to get hit and storing their names, and I've got a whole beautiful loop for picking each one and hitting them...but because I'm not writing (guessing) it Exactly Right, it doesn't do a damn thing.

Here's what I got:

PHP Code:

//#CLIENTSIDE

function onActionMelee() {
  
player.chat=("Hit! "@params[0SPC params[1]);
  
setAni("hurt""");
  if(
this.cooldown<1){
    
triggerserver("gui"this.name"hurt"params[0], params[1]);
    
findWeapon("GUIInventory").trigger("showHUD""");
    
this.cooldown=60;
  }


which works fine (but only for triggeraction x y), and
PHP Code:

          with(findplayer(plr)){
            
//            echo("Found "@plr SPC ani);
            
setAni("hurt""");
            
triggerserver("gui""#HP""hurt""other"temp.dmg);
            
this.findWeapon("#HP").trigger("Melee""other""3");
            
this.findWeapon("#HP").trigger("ActionMelee""other""3");
            
this.findWeapon("#HP").trigger("OnActionMelee""other""3");
            
this.findWeapon("#HP").melee("other""3");
            
this.findWeapon("#HP").Melee("other""3");
            
this.findWeapon("#HP").ActionMelee("other""3");
            
this.findWeapon("#HP").actionmelee("other""3");
            
this.findWeapon("#HP").onactionmelee("other""3");
            
this.findWeapon("#HP").OnActionMelee("other""3");
          } 

(also clientside); to reiterate, isn't there some sort of player.trigger(wossname)?

cbk1994 03-02-2009 02:35 PM

Why are you naming your weapons with a # in front of them, anyway?

Have you debugged and made sure that you're actually reaching the player? It looks like those should work.

Are you getting any errors in NC (e.g. can't access private function)?

If you want I can get on Testbed or wherever you're doing this and try to help you out.

Tyhm 03-03-2009 03:54 AM

I inherited the # signs. Not a lot I can do about it. Got sure I can find it (I forgot some little subroutine to make sure the player was getting called), then the guy I was testing with got quietly kicked offline. Right now I got
PHP Code:

            triggerserver("weapon",this.name,0,temp.sinx,temp.siny,temp.targets,temp.ptargets);
            
temp.ptt=ptargets.tokenize();
            
player.chat=("PTT:"@ptt);
            for(
temp.plrn:ptt){
              
temp.plr=findplayer(plrn);
              
player.chat=("PLR:"@plr SPC this.damage);
              
plr.chat="Fix me";
              
triggeraction(plr.x+1.5plr.y+1.5"melee""other"this.damage);
              
triggeraction(plr.x+1.5plr.y+1.5"tyhm""other"this.damage);
              
triggeraction(plr.x+1.5plr.y+1.5"Tyhm""other"this.damage);
            } 

And it Used to work, but spontaneously stopped. -_-. Curiously, if I comment out the other two triggeractions it works fine...but only out to a certain distance, about 6 tiles. And actionmelee looks like this:
PHP Code:

function onActionMelee() {
  
player.chat=("Hit! "@params[0SPC params[1]);
  
setAni("hurt""");
  if(
this.cooldown<1){
    
triggerserver("gui"this.name"hurt"params[0], params[1]);
    
findWeapon("GUIInventory").trigger("showHUD""");
    
this.cooldown=60;
  }



WhiteDragon 03-03-2009 05:07 AM

Clientside to clientside triggeractions only work for a certain distance.

If you're trying to make a sort of long range hit detection you may want to change your methods (such as storing the data in attr or anis).

Tyhm 03-03-2009 05:19 AM

Quote:

Originally Posted by WhiteDragon (Post 1470826)
Clientside to clientside triggeractions only work for a certain distance.

If you're trying to make a sort of long range hit detection you may want to change your methods (such as storing the data in attr or anis).

...
...
...
...
Thanks, that's great. Hooray Wiki. -_-

Does the old trick of setting a weapon's x and y work? Or is it a fixed distance from the player? Or is a weapon's x and y static?

WhiteDragon 03-03-2009 05:33 AM

Quote:

Originally Posted by Tyhm (Post 1470828)
Does the old trick of setting a weapon's x and y work? Or is it a fixed distance from the player? Or is a weapon's x and y static?

I believe Stefan said it was a fixed distance, but you could always try that since he didn't explicitly say what the engine was determining the distance from.

cbk1994 03-03-2009 06:05 AM

Suggestion: Join the player to a class, then you can call a public function.

PHP Code:

findPlayer("cbk1994").doDamage(1); 

Let me know if you need a better explanation.

Tyhm 03-03-2009 07:28 AM

Might do that, the players already join a class; would that trigger function on doDamage(){, function onDoDamage(){, function doDamage(){, ? The "on"s always throw me.

salesman 03-03-2009 08:22 AM

Quote:

Originally Posted by Tyhm (Post 1470849)
Might do that, the players already join a class; would that trigger function on doDamage(){, function onDoDamage(){, function doDamage(){, ? The "on"s always throw me.

it's just calling
PHP Code:

public function doDamage() {
  ...



Tyhm 03-03-2009 09:13 AM

kkthxz. :-D

Codein 03-03-2009 07:50 PM

Quote:

Originally Posted by WhiteDragon (Post 1470826)
If you're trying to make a sort of long range hit detection you may want to change your methods (such as storing the data in attr or anis).

Thankyou for this suggestion! :D

cbk1994 03-03-2009 10:54 PM

Quote:

Originally Posted by Tyhm (Post 1470849)
Might do that, the players already join a class; would that trigger function on doDamage(){, function onDoDamage(){, function doDamage(){, ? The "on"s always throw me.

"on" is used when you use a trigger.

PHP Code:

npc.trigger("PlayerAttack"player.accountdmg); // calls "onPlayerAttack"
npc.playerAttack(player.accountdmg); // calls "playerAttack" 

The main benefits of using triggers are:
  • They don't interrupt your code (your code continues without waiting for the function to finish)
  • You can trigger any NPC for any function, and even if it doesn't exist, it won't give an error, unlike directly calling the function.

Codein 03-03-2009 11:00 PM

Quote:

Originally Posted by cbk1994 (Post 1471083)
"on" is used when you use a trigger.

PHP Code:

npc.trigger("PlayerAttack"player.accountdmg); // calls "onPlayerAttack"
npc.playerAttack(player.accountdmg); // calls "playerAttack" 

The main benefits of using triggers are:
  • They don't interrupt your code (your code continues without waiting for the function to finish)
  • You can trigger any NPC for any function, and even if it doesn't exist, it won't give an error, unlike directly calling the function.

I, personally, would have liked a trigger to be used for this situation but unfortunately, it didn't work. I don't know if I did something wrong though. However, what I've done to work around the situation works almost as well :)

Inverness 03-03-2009 11:23 PM

Event function names are prefixed with "on" and trigger() is triggering an event, same with scheduleevent().

I also find "doDamage" a silly function name, "damage" works fine.

WhiteDragon 03-04-2009 12:06 AM

Keep in mind that triggers are considerably slower than direct public function calls. However if you do not need quick response time, triggers/events are much more useful, especially because of the interface they provide with functions such as catchevent.

Tyhm 03-04-2009 04:28 AM

It's resolved now, but could you geniuses (not intended sarcastically) give the wiki a page on the modern communication styles? I think the last time I checked it just had a GS1 "triggeraction x, y, name, params;" page. :-P

And yeah, I like the aspect of triggers that is "Mail this data to this player and get on with your life", I just can't stand the "Throw a dart at the board and hope it hits the right player, and you can put the target's name in the parameters and check to make sure the target's right and dismiss it if it's wrong, and maybe you can have the wrong-target forward it to the right-target but there's no guarantee" aspect. I mean, what if jailing scripts had to take the account named, get their X and Y, and trigger on those coordinates iff you're within 6 tiles?! Madness.

Inverness 03-04-2009 04:34 AM

Quote:

Originally Posted by WhiteDragon (Post 1471127)
Keep in mind that triggers are considerably slower than direct public function calls. However if you do not need quick response time, triggers/events are much more useful, especially because of the interface they provide with functions such as catchevent.

catchevent() does not work for scripted triggers on clientside yet :(


All times are GMT +2. The time now is 04:48 PM.

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