Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Npc Trigger (https://forums.graalonline.com/forums/showthread.php?t=134264514)

blackbeltben 09-09-2011 08:46 AM

Npc Trigger
 
A while ago i posted a thread on How to set an "if" statement for a onPlayerTouchsMe and check the player gani to see if he is attacking.

Thread:
http://forums.graalonline.com/forums...t=blackbeltben

Thor told me i Should not do my collision like that so i changed it with the script he gave me but it doesnt seem to be working. I put it in a weapon added to the player.
I'm expecting it to trigger the action of "onWasDmg" of the baddie

PHP Code:

function onAttack()
{
  
temp.player.0.5 + (vecx(player.dir) * 2); 
  
temp.player.+ (vecy(player.dir) * 2); 
  
temp.tnpcs findareanpcs(temp.xtemp.y22); 
  for(
temp.temp.tnpcs){ 
    
temp.n.trigger("onWasDmg"player.clientr.power); 
  } 


Mark Sir Link 09-09-2011 12:07 PM

I think you need to remove "on" from the trigger, otherwise it is invoking

ononWasDmg()

blackbeltben 09-09-2011 12:30 PM

still not working :(

cbk1994 09-09-2011 01:19 PM

Quote:

Originally Posted by blackbeltben (Post 1667558)
still not working :(

What have you done to try to make it work? Have you tried seeing what NPCs are being called with an echo?

greggiles 09-09-2011 01:42 PM

Cbk, csn you explain that?

ffcmike 09-09-2011 01:57 PM

Do the NPCs have a setshape or are they using showcharacter?
I believe they require such a shape in order to receive triggers.

If not you probably should include:

PHP Code:

this.setshape(13232); //32 pixels = 2 tiles in width and height 

You also need to make sure that the function is serverside/clientside according to where the area trigger was handled.

blackbeltben 09-09-2011 05:04 PM

the shape was set.
and this line is under the weapon. which is CLIENTSIDE

PHP Code:

  temp.player.0.5 + (vecx(player.dir) * 2); 
  
temp.player.+ (vecy(player.dir) * 2); 
  
temp.tnpcs findareanpcs(temp.xtemp.y22); 
  for(
temp.temp.tnpcs){ 
    
temp.n.trigger("onWasDmg"player.clientr.dmg); 
  } 

And this is the baddie's which is SERVERSIDE

PHP Code:

function onWasDmg()
{
this.chat "hit"


ffcmike 09-09-2011 05:45 PM

Quote:

Originally Posted by blackbeltben (Post 1667579)
the shape was set.
and this line is under the weapon. which is CLIENTSIDE

PHP Code:

  temp.player.0.5 + (vecx(player.dir) * 2); 
  
temp.player.+ (vecy(player.dir) * 2); 
  
temp.tnpcs findareanpcs(temp.xtemp.y22); 
  for(
temp.temp.tnpcs){ 
    
temp.n.trigger("onWasDmg"player.clientr.dmg); 
  } 

And this is the baddie's which is SERVERSIDE

PHP Code:

function onWasDmg()
{
this.chat "hit"


Here's the problem, trigger() does not communicate from Clientside to Serverside in the way that a triggeraction() does.

There are 3 different things you can do:

1. Move the onWasDmg() to Clientside, then specifically trigger to serverside within that NPC. This can be done by triggeraction() for a normal level NPC, otherwise for local NPCs (putnpc2) it's better to store npc.name as an attribute serverside, and use that name for triggerserver().

2. Pass the area trigger data to serverside within the weapon via triggerserver() and trigger area NPCs serverside.

3. As opposed to doing an area trigger, you can directly use triggeraction() within the weapon which can be received both Clientside and Serverside.

The 3 different methods have their advantages and disadvantages.

Method 1 will ensure the NPC receives damage if you see yourself hitting the baddy on your own client. However triggeraction can sometimes be unreliable, both for a moving target having different coordinates between clientside and serverside, and when it comes to there being multiple NPCs in the same position due to it triggering to one NPC on a single point. It would also be inefficient in the event of hitting several NPCs at once. I would only recommend this method if the baddies are local NPCs where you can then use triggerserver(); within the NPC itself.

Method 2 would be more efficient when it comes to hitting multiple NPCs in the same attack, and will avoid such issues as triggeraction() failing or having to make the baddies as local NPCs. The only downside is that with the area trigger occurring Serverside it may not be consistent with what you see on your own client. Players with a higher ping may have some difficulty with timing their hits on moving NPCs.

Method 3 is by far the easiest to implement but is also the most inefficient, not only would the trigger be sent to the server but also other nearby players if within a weapon script. Triggeraction() is a single-point trigger which means hits will be less sensitive than a box trigger. It would also have problem of not being able to damage multiple NPCs or triggering the wrong NPC if there are multiple on the coordinates.

cbk1994 09-09-2011 09:49 PM

Quote:

Originally Posted by ffcmike (Post 1667566)
Do the NPCs have a setshape or are they using showcharacter?
I believe they require such a shape in order to receive triggers.

If not you probably should include:

PHP Code:

this.setshape(13232); //32 pixels = 2 tiles in width and height 

You also need to make sure that the function is serverside/clientside according to where the area trigger was handled.

Objects definitely don't need to have a shape to receive triggers via obj.trigger() :oo:

ffcmike 09-09-2011 09:51 PM

Quote:

Originally Posted by cbk1994 (Post 1667608)
Objects definitely don't need to have a shape to receive triggers via obj.trigger() :oo:

This may well be the case now but I recall they did at some point, I think it was necessary for serverside NPCs.

cbk1994 09-09-2011 09:53 PM

Quote:

Originally Posted by ffcmike (Post 1667610)
This may well be the case now but I recall they did at some point, I think it was necessary for serverside NPCs.

I highly doubt it. trigger doesn't use coordinates at all; you can trigger weapons, TStaticVars, players, or any other object.

ffcmike 09-09-2011 09:55 PM

Quote:

Originally Posted by cbk1994 (Post 1667613)
I highly doubt it. trigger doesn't use coordinates at all; you can trigger weapons, TStaticVars, players, or any other object.

I'm referring to the ability to find an object via findareanpcs();.

blackbeltben 09-10-2011 01:02 PM

Alright, for the baddie, under //#CLIENTSIDE, it reconizes the attack. but it does not perform the trigger on the CLIENTSIDE function to properly decrease the baddie's HP

ffcmike 09-10-2011 04:03 PM

Quote:

Originally Posted by blackbeltben (Post 1667695)
Alright, for the baddie, under //#CLIENTSIDE, it reconizes the attack. but it does not perform the trigger on the CLIENTSIDE function to properly decrease the baddie's HP

What are you doing to communicate serverside?

blackbeltben 09-10-2011 04:08 PM

Im using when it triggers serverside from the attack, i tried to use SetTimer(), scheduleEvent(), Trigger, all that stuff. I dont know what the proplem is. What would you use?


All times are GMT +2. The time now is 07:41 AM.

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