Quote:
Originally Posted by blackbeltben
the shape was set.
and this line is under the weapon. which is CLIENTSIDE
PHP Code:
temp.x = player.x + 0.5 + (vecx(player.dir) * 2);
temp.y = player.y + 1 + (vecy(player.dir) * 2);
temp.tnpcs = findareanpcs(temp.x, temp.y, 2, 2);
for(temp.n : 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.