DrVrej / VJ-Base

An addon for Garry's mod that contains bunch of bases to make many different types of addons.

Home Page:http://steamcommunity.com/sharedfiles/filedetails/?id=131759821

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Other NPCs always attack VJ NPCs among a group of NPCs

BREEDNKMs opened this issue · comments

In a case where there's a squad which consists of default AI npcs and VJ npcs, enemies always go for VJ NPCs first, default NPCs last, no matter the distance, visibility or amount of other NPCs. For example, when you create a hybrid npc squad which includes both default Combine NPCs and VJ Combine SNPCs, default Rebels always attack VJ Combine SNPCs first, even though there are HL2 Combine Soldiers in front of our rebels.

This is because AddEntityRelationship towards VJ NPCs is always used with a priority of 99 towards VJ NPCs, whereas HL2 always defaults priority to 0, with exception of -1 for poison headcrabs.

Is it possible to decrease D_HT priority towards VJ NPCs down to 0, just like how all other NPCs do?

This isn't a problem for VJ vs. VJ + Engine NPCs because VJ NPCs select other NPCs by itself ignoring whatever is set for "priority".

commented

Hi, you are correct about the priority issue. I have ran tests about this previously, setting the number to many different variations, including 0 and -1. Unfortunately nothing seems to fix the issue, which explains why all scripted NPCs or bases (that I know of) have this issue. From what I have gathered in my testing, the priority value is not properly set when called from the Lua function. I will leave this issue open for now, it doesn't hurt to rerun the tests. If I find anything I will report it here. If tests fail again, then I am positive this has to be from the engine code and nothing we can do through Lua. Feel free to give input if you have ran tests yourself!

I've found out the reason: it is because the "AddEntityRelationship" function isn't working correctly or documented incorrectly; the "priority" field is always set to 1, even when we define some other number.

After preventing the "AddEntityRelationship" call in your code and using "ent_fire engine_npc setrelationship 'vj_npc d_ht 0'" instead, the prioritization issue gets resolved and engine NPCs pick the closest NPC they desire, or some other NPC with a higher priority. Whenever I use "AddEntityRelationship" again, the engine NPC targets VJ NPCs.

I'll open this issue in garrysmod-issues so developers make it work as intended. After when this is fixed, I think you can make a feature out of this, where some VJ NPCs are always high-prioritized or low prioritized, like civilian NPCs among armed NPCs taking less priority.

EDIT: Had wrote two fields in wrong order, corrected them.

commented

Unfortunate that I was right about the function being broken, and please do open an issue, hopefully the developers will resolve this asap. Aside from that, good find on the workaround, but it would definitely be better if the function itself is fixed.

Also I'll keep this issue open until the function is fixed, I will then implement a system for developers to set priority levels. 👍

commented

Update: Function has been fixed, I'll update the base to this change soon.
Reference: Facepunch/garrysmod-issues#5247

commented

Fixed in 842f6e5