• Invincible NPCs?
    7 replies, posted
If I have an NPC like this: [CODE]local NPC = { Name = "Drug Dealer", Class = "npc_eli", Model = "models/Humans/Group03/male_08.mdl", Health = "999999999999999999999999999999999999999999999999999999999", Category = "Sethxi" } list.Set( "NPC", "npc_drugdealer2", NPC ) concommand.Add("testautorunluafile", asd) [/CODE] How would I make it so it can't die? I'm making a drug dealer..
Make it so nothing happens when they take damage? Is logic really this hard for some people...?
[lua] function ENT:OnTakeDamage() return false end [/lua]
[QUOTE=ben434;40274979][lua] function ENT:OnTakeDamage() return false end [/lua][/QUOTE] where the fuck am I supposed to put that if I'm using the local NPC = {}
[QUOTE=Sethxi;40280231]where the fuck am I supposed to put that if I'm using the local NPC = {}[/QUOTE] Filter out classes and put it on the Gamemode hook?
[QUOTE=Lerpaderp;40280427]Filter out classes and put it on the Gamemode hook?[/QUOTE] tried that. didnt work. Now I'm having trouble even spawning the fucking npc. I can spawn it from the spawnmenu and gm_spawnnpc npc_drugdealer2 But ents.Create("npc_drugdealer2"), it says NULL entity?
[lua]list.Set( "NPC", "npc_drugdealer2", NPC ) [/lua] Does not register the entity class 'npc_drugdealer2'. It adds an NPC to the NPC Spawn list with the specified table of data, which I don't even think uses the values 'Health' or 'Model'. In other words; [B]you're doing it wrong.[/B] Here's a really really [b]reallly[/b] basic NPC that does literally nothing but stand there and look pretty. [lua]AddCSLuaFile(); ENT.Base = "base_nextbot"; function ENT:Initialize( ) self:SetModel( "models/Humans/Group03/male_08.mdl" ); self:StartActivity( ACT_IDLE ); end function ENT:RunBehaviour( ) -- Nothnig. end list.Set( "NPC", "YOUR NPC CLASS HERE", { Name = "Custom NPC", Class = "YOUR NPC CLASS HERE", Category = "Custom NPCs" } ); [/lua] That is basically a 'shared' file, so you can either put it inside the entities/ folder as '[b]class_name.lua[/b]' or '[b]entities/class_name/shared.lua[/b]'. [sub](Before anyone asks, I used nextbot as a base just in-case he wants to make the npc walk around or some shit.)[/sub]
Here's another way which doesn't require editing the actual NPC entity: [lua]// // // function GM:ScaleNPCDamage ( victim, HitGroup, DmgInfo ) if ( victim:GetClass( ) == "mynpc" ) then DmgInfo:ScaleDamage( 0 ) end end[/lua] or as a hook if you're already using ScaleNPCDamage and don't want to override it: [lua]// // // hook.Add("ScaleNPCDamage", "ProtectorOfMyNPC", function( victim, HitGroup, DmgInfo ) if ( victim:GetClass( ) == "mynpc" ) then DmgInfo:ScaleDamage( 0 ) end end )[/lua]
Sorry, you need to Log In to post a reply to this thread.