Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggering Functions on other Players (https://forums.graalonline.com/forums/showthread.php?t=134268640)

i8bit 08-19-2013 06:54 PM

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.

callimuc 08-20-2013 03:54 AM

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

i8bit 08-20-2013 04:08 AM

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?

cbk1994 08-20-2013 01:37 PM

Quote:

Originally Posted by i8bit (Post 1721867)
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).

callimuc 08-20-2013 04:11 PM

Quote:

Originally Posted by cbk1994 (Post 1721871)
(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 (Post 1721871)
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


All times are GMT +2. The time now is 05:24 PM.

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