Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-16-2014, 04:45 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
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

Reply With Quote
  #2  
Old 05-16-2014, 06:24 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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)
__________________
MEEP!
Reply With Quote
  #3  
Old 05-16-2014, 06:48 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by callimuc View Post
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?
Reply With Quote
  #4  
Old 05-16-2014, 08:27 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by i8bit View Post
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
__________________
MEEP!
Reply With Quote
  #5  
Old 05-16-2014, 09:45 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
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?
Reply With Quote
  #6  
Old 05-16-2014, 09:52 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by i8bit View Post
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
__________________
MEEP!
Reply With Quote
  #7  
Old 05-17-2014, 02:59 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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;

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #8  
Old 05-22-2014, 10:08 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by Tigairius View Post
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!



Graal forums are so kind to me
Reply With Quote
  #9  
Old 05-22-2014, 06:25 PM
Fulg0reSama Fulg0reSama is offline
Extrinsical Anomaly
Fulg0reSama's Avatar
Join Date: Sep 2009
Location: Ohio
Posts: 3,049
Fulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant future
Quote:
Originally Posted by Tigairius View Post
-Explaination-
So that's what will call the black cat back, eh?
__________________

Careful, thoughts and opinions here scare people.
Reply With Quote
  #10  
Old 05-27-2014, 11:08 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
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]??
Reply With Quote
  #11  
Old 05-28-2014, 12:20 AM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 353
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
hello!

if you mean within the receiving event function then yes, you can access whatever you define as a parameter by using params[0]
__________________
This signature has been deleted by Darlene159.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:33 PM.


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