Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-19-2013, 06:54 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Triggering Functions on other Players

I'm looking to trigger an action on another player for the combat system I am making.
How do I trigger the hurt function in the other player. (Need help where the // is)

-system/hurt
PHP Code:
//#CLIENTSIDE
function onHurt(){
 
player.chat "Hurt!";

-system/combat
PHP Code:
function onActionServerSide(){ 
 if (
params[0] == "attack"){
  
//trigger onHurt in the -system/hurt weapon of the player right in front of you
  
}
}

//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "s"){
  
player.chat "Attack!";
  
triggerserver("weapon"this.name"attack");
 }

side note:
Is triggering a serverside function in an NPC similar to triggering another player?
I need to trigger the onHurt() with the baddies too.
Reply With Quote
  #2  
Old 08-20-2013, 03:54 AM
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
To trigger back the clientside, you can do

player.triggerClient("gui", weaponNameHere, "parameter", "parameter", ...)

then on the clientside part you can have something like
PHP Code:
function onActionClientSide() {
  
//do any checks you want, then trigger your deserved function

And no, you cant just do triggerServer()/triggerClient() within NPCs as I remember. You would need to use triggerAction(x, y, "Test", "Hello") which can be seen by using
PHP Code:
function onActionTest() {
  
this.chat params[0];

make sure to set a shape (setshape() or setshape2())to the NPC when using triggerAction(), else it wont work
__________________
MEEP!
Reply With Quote
  #3  
Old 08-20-2013, 04:08 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
player.triggerClient("gui", weaponNameHere, "parameter", "parameter", ...)
And what should I put in the params to target the player right in front of me?

So essentially, I don't even need to trigger serverside to trigger a clientside function in another player?
Reply With Quote
  #4  
Old 08-20-2013, 01:37 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by i8bit View Post
And what should I put in the params to target the player right in front of me?
You don't do anything with the params, you need to call that on the appropriate player. The typical approach is to loop through the players near you and check if any of them are in the attack radius. If they are, attack them, either by triggering one of their weapons clientside or handling the attack serverside (preferred).

(I think I recall Stefan adding a better way to find players in a certain radius/area? The forums search isn't working as usual so not sure)

Quote:
So essentially, I don't even need to trigger serverside to trigger a clientside function in another player?
You can do it this way but it's quite unreliable and in my opinion the approach of triggering serverside and allowing the server to handle attacks (which is what you were doing in your first post) is much more reasonable. Point triggers are very unreliable and you can end up with cases where attacks don't hit for a number of hard-to-find reasons.

The approach you were using before avoids all of those and gives you much more flexibility (for example, instead of point attacks which are very limited you are free to use your own attack radii, or even special attack patterns for different weapons). You also get the benefit of handling things serverside which is inherently more reliable.

edit: I read callimuc's post wrong, he was only talking about for NPCs. You can use point triggers for that but they are still very unreliable. A preferred solution would be to handle NPCs the same way as players (loop through them and use the same attack/hitbox logic; use something like npc.trigger("hurt", player, damage); to call onHurt in an NPC).
__________________
Reply With Quote
  #5  
Old 08-20-2013, 04:11 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 cbk1994 View Post
(I think I recall Stefan adding a better way to find players in a certain radius/area? The forums search isn't working as usual so not sure)
You mean findAreaPlayers()?

Scripthelp: TServerLevel.findareaplayers(float, float, float, float) - returns object - returns an array of all players in the specified rectangle (x,y,width,height), uses the blocking rectangle of players (0.5,1,2,2) instead of (0,0)

Quote:
Originally Posted by cbk1994 View Post
edit: I read callimuc's post wrong, he was only talking about for NPCs. You can use point triggers for that but they are still very unreliable. A preferred solution would be to handle NPCs the same way as players (loop through them and use the same attack/hitbox logic; use something like npc.trigger("hurt", player, damage); to call onHurt in an NPC).
yea true, that would be the better way of damaging NPCs
__________________
MEEP!
Reply With Quote
Reply


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 06:20 PM.


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