PDA

View Full Version : Triggering action in other player


i8bit
05-16-2014, 04:45 PM
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
//#CLIENTSIDE
function onKeyPressed(code, key){
if (key == "s"){
setAni("sword", NULL);
//trigger action "onHit" in the weapon "DamageSystem" to the player right in front
}
}

//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
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
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
//#CLIENTSIDE
function onKeyPressed(code, key){
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
//#CLIENTSIDE
function onKeyPressed(code, key){
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:

//#CLIENTSIDE
// triggeraction(hit x, hit y, action name, action parameter(s))
triggeraction(player.x + 1.5 + vecx(player.dir) * 1.5, player.y + 2 + 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/showthread.php?p=1649547

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

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

i8bit
05-22-2014, 10:08 AM
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:

//#CLIENTSIDE
// triggeraction(hit x, hit y, action name, action parameter(s))
triggeraction(player.x + 1.5 + vecx(player.dir) * 1.5, player.y + 2 + 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/showthread.php?p=1649547

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

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
-Explaination-

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

i8bit
05-27-2014, 11:08 PM
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]