Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggering action in other player (https://forums.graalonline.com/forums/showthread.php?t=134269217)

i8bit 05-16-2014 04:45 PM

Triggering action in other player
 
I am trying to stay away from Serverside functions.

How would I trigger an action in a Weapon on a player in front of me..

For example:
Player swinging sword
PHP Code:

//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "s"){
  
setAni("sword"NULL);
  
//trigger action "onHit" in the weapon "DamageSystem" to the player right in front
 
}


PHP Code:

//Damage system
//#CLIENTSIDE
function onHit(){
 
//what ever actions I want to take place



callimuc 05-16-2014 06:24 PM

You will need the serverside part anyway. In the attack, you can do triggerAction() on clientside and then use the triggered function on serverside inside the health script I believe (not too sure)

i8bit 05-16-2014 06:48 PM

Quote:

Originally Posted by callimuc (Post 1727263)
You will need the serverside part anyway. In the attack, you can do triggerAction() on clientside and then use the triggered function on serverside inside the health script I believe (not too sure)

How does the client find the player in front of your player?

callimuc 05-16-2014 08:27 PM

Quote:

Originally Posted by i8bit (Post 1727266)
How does the client find the player in front of your player?

the triggerAction() will already trigger the named function on all objects on clientside and serverside at the given position (as long as setshape is set or its related to a player). once you've received the triggerAction(), you can make a check using findAreaPlayers() to figure whos around the player that got hit

i8bit 05-16-2014 09:45 PM

PHP Code:

//#CLIENTSIDE 
function onKeyPressed(codekey){ 
 if (
key == "s"){ 
  
setAni("sword"NULL); 
  
findAreaPlayers();
  
triggerAction("weapon""DamageSystem""onHit"); 
 } 


is this right? If not, what modifications or errors need to be fixed?

callimuc 05-16-2014 09:52 PM

Quote:

Originally Posted by i8bit (Post 1727269)
PHP Code:

//#CLIENTSIDE 
function onKeyPressed(codekey){ 
 if (
key == "s"){ 
  
setAni("sword"NULL); 
  
findAreaPlayers();
  
triggerAction("weapon""DamageSystem""onHit"); 
 } 


is this right? If not, what modifications or errors need to be fixed?

No, try to make your own researches about findAreaPlayers() and triggerAction(). I'm pretty sure you will find enough stuff about that in the NPC section on here, else you're not looking properly ;)

Tigairius 05-17-2014 02:59 PM

I don't post on the Graal forums anymore and I shouldn't care, but I was just checking in and it irked me that such a simple question wasn't fully answered yet. There's several ways to do this. As Callimuc mentioned, one of the nicer ways is using a triggeraction.

Clientside, you'll specify a x,y as well as an "action" name (for when the object/player gets hit) and the action's parameters.

Example:
PHP Code:

//#CLIENTSIDE
// triggeraction(hit x, hit y, action name, action parameter(s))
triggeraction(player.1.5 vecx(player.dir) * 1.5player.vecy(player.dir) * 1.5"Hit"player.account); 

Here, the "hitter" will "trigger an action" on anything that is at the specified hit x and hit y. In this case, it is directly in front of the hitter. We should also pass the hitter's account to the object/player being hit.
For an explanation on vecx and vecy and how they work in the above example, see a post of mine from a couple of years ago: http://forums.graalonline.com/forums....php?p=1649547

Now, the object being hit can expect to have the following to handle the action:
PHP Code:

function onActionHit(acct) {
  
this.chat "I've been hit by " acct;



i8bit 05-22-2014 10:08 AM

Quote:

Originally Posted by Tigairius (Post 1727283)
I don't post on the Graal forums anymore and I shouldn't care, but I was just checking in and it irked me that such a simple question wasn't fully answered yet. There's several ways to do this. As Callimuc mentioned, one of the nicer ways is using a triggeraction.

Clientside, you'll specify a x,y as well as an "action" name (for when the object/player gets hit) and the action's parameters.

Example:
PHP Code:

//#CLIENTSIDE
// triggeraction(hit x, hit y, action name, action parameter(s))
triggeraction(player.1.5 vecx(player.dir) * 1.5player.vecy(player.dir) * 1.5"Hit"player.account); 

Here, the "hitter" will "trigger an action" on anything that is at the specified hit x and hit y. In this case, it is directly in front of the hitter. We should also pass the hitter's account to the object/player being hit.
For an explanation on vecx and vecy and how they work in the above example, see a post of mine from a couple of years ago: http://forums.graalonline.com/forums....php?p=1649547

Now, the object being hit can expect to have the following to handle the action:
PHP Code:

function onActionHit(acct) {
  
this.chat "I've been hit by " acct;




TIG!! Thank you so much sir. You are a big help to new scripties like myself trying to learn. You explain very well!

:cool:

Graal forums are so kind to me :D

Fulg0reSama 05-22-2014 06:25 PM

Quote:

Originally Posted by Tigairius (Post 1727283)
-Explaination-

So that's what will call the black cat back, eh?

i8bit 05-27-2014 11:08 PM

Quote:

Clientside, you'll specify a x,y as well as an "action" name (for when the object/player gets hit) and the action's parameters.
So would the parameters at the end be params[0]??

Jakov_the_Jakovasaur 05-28-2014 12:20 AM

hello!

if you mean within the receiving event function then yes, you can access whatever you define as a parameter by using params[0]


All times are GMT +2. The time now is 10:03 AM.

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