couldn't you use isOwner() then if the owner is PLayerB then se them to be hostile towards them.
Would it be possible to have the NPCs act hostile towards other groups of the same type of NPC? For example, if Player A wanted to create NPCs that were hostile towards all of Player B's NPCs.
Also, npcSetHealth() would be nice.
couldn't you use isOwner() then if the owner is PLayerB then se them to be hostile towards them.
Well, from what I heard, ownership is a bit shady in GMod. There is a GetOwner() function somewhere in the E2 core folder, I could try that out and see how it goes. Anyone else is free to do so also.
npcSetHealth() can be done. I was hoping to have a proper npcKill() function though, so you could kill off weakened troops and spawn new ones, which prevents healing during a war (cheating).
The only thing is, clearing corpses is something I don't know how to do.
If anyone makes either npcSetHealth() or npcKill(), I'll add them.
Well, I could look how isOwner() is done. Probably through the GetOwner() lua function I saw defined somewhere in the core folder. Even then I wouldn't really know how to set an NPC's disposition towards all NPCs owned by a specified person.
I've looked through a lot of lua functions on the Gmod wiki, I didn't find any built-in ways of setting disposition by ownership. Only by entity data or class string (both of which are added).
Perhaps Ents.FindByClass, cycling and having their ownership compared to an input entity, and disposition being set as it goes, inside a for loop. There has to be an easier way though.
Last edited by Bobsymalone; 02-09-2009 at 04:46 PM.
This should apply a relationship to stuff belonging to a specified owner. *Should*. Untested and such, and there might be an easier way of doing it. Adding it to the main file now.Code:registerFunction("npcRelationshipByOwner", "e:esn", "n", function(self,args) local op1, op2, op3, op4 = args[2], args[3], args[4], args[5] local rv1, rv2, rv3, rv4 = op1[1](self,op1), op2[1](self,op2), op3[1](self,op3), op4[1](self,op4) local entity = checkEntity(rv1) local owner = checkEntity(rv2) local disp = NpcDisp(rv3) local prior = rv4 if( !entity:IsNPC() ) then return 0 end local Table = Ents.FindByClass("npc_") if(Table.Count()==0) then return 0 end for i=1,Table.Count() do if(GetOwner(Table[i])==owner) then entity:AddEntityRelationship( Table[i], disp, prior ) end end return Table.Count() end)
EDIT: Should there be a function to apply relationship to all entities in an array? Might be useful, less specialised than this too. I can keep this as well though.
Another EDIT: There was an error generated with one of the new functions. Probably the one in this post. When I have time to debug I'll put them back in (they're just commented out if anyone wants to try them).
Yet another EDIT: added missing "end" - thanks Polymorph/ZeikJT
Last edited by Bobsymalone; 03-10-2009 at 10:54 AM.
You need another 'end' in that function somewhere.
Ah indeed, the:
for i=1,Table.Count() do
Doesn't have an end because the next line with the if conditional stole it.
Against stupidity the Gods themselves contend in vain.
-Friedrich Schiller
The flame puts me in the mood to "Do it!".
-Dart, Legend of Dragoon
Is this ready for the SVN (if you want) or what's the status?
(Same as last time, no npcSpawn-function though)
Last edited by Bobsymalone; 03-23-2009 at 04:29 PM.
It works, feel free to SVN it. I took the npcSpawn() version out. If anyone has any multiplayer bugs to report with this version let me know, but there shouldn't be a problem.
Code for npcSpawn() if anybody wants it:
Code:registerFunction("npcSpawn", "sv", "e", function(self,args) local op1, op2 = args[2], args[3] local rv1, rv2 = op1[1](self,op1), op2[1](self,op2) local entity = ents.Create( rv1 ) if( !entity:IsNPC() ) then return nil end local Vec = Vector( rv2[1], rv2[2], rv2[3] ) entity:SetPos( Vec ) entity:Spawn() entity:Activate() entity:AddRelationship("player", 4, 999) return entity end)
Bookmarks