• NextBot Or SNPC?
    5 replies, posted
So what i am trying to do is make a manhack for ttt that follows the player that spawned it and attacks anyone who attack that player. naturally these manhacks are very....... violent..... and i have been trying and trying to get them to pretty much not think for themselves, and im wondering if i should do this with nextbot or npc. here is what i have so far. [CODE] if SERVER then AddCSLuaFile("shared.lua") end ENT.Type = "anim" ENT.Base = "ttt_basegrenade_proj" ENT.Model = Model("models/props/de_tides/vending_turtle.mdl") --Change these values to modify damage proporties ENT.ExplosionDamage = 0 ENT.ExplosionRadius = 0 ENT.TurtleCount = 1 TurtleNPCClass = "npc_manhack" TurtleInnocentDamage = 15 TurtleTraitorDamage = 20 TurtleDetectiveDamage = 0 AccessorFunc( ENT, "radius", "Radius", FORCE_NUMBER ) AccessorFunc( ENT, "dmg", "Dmg", FORCE_NUMBER ) function ENT:Initialize() print("hi there!") self:SetCollisionGroup( COLLISION_GROUP_WEAPON ) --self:SetMoveType(0) --self:SetColor( Color( 200, 255, 200 ) ) if not self:GetRadius() then self:SetRadius(256) end if not self:GetDmg() then self:SetDmg(0) end --print(self:GetThrower()) self.BaseClass.Initialize(self) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:SetMass(1000) end ExplodePos = self:GetPos() if SERVER then timer.Create( "UniqueName", 4, 1, function() if SERVER then self:Ignite(30) end end ) timer.Create( "Stay Put", 0.5, 15, function() --self:SetVelocity( Vector( 0, 0, 500 ) ) self:SetPos(ExplodePos) end) end end function ENT:Explode(tr) --self:GetThrower()) --print("hi") Friend = self:GetThrower() --[[print(Friend) print(player.GetByID(1)) if Friend == player.GetByID(1) then print("YES") end ]] if SERVER then self.Entity:SetNoDraw(true) self.Entity:SetSolid(SOLID_NONE) local pos = self.Entity:GetPos() -- pull out of the surface if tr.Fraction ~= 1.0 then self.Entity:SetPos(tr.HitPos + tr.HitNormal * 0.6) end --[[if util.PointContents(pos) == CONTENTS_WATER then self:Remove() return end]]-- local effect = EffectData() effect:SetStart(pos) effect:SetOrigin(pos) effect:SetScale(self.ExplosionRadius * 0.3) effect:SetRadius(self.ExplosionRadius) effect:SetMagnitude(self.ExplosionDamage) if tr.Fraction ~= 1.0 then effect:SetNormal(tr.HitNormal) end util.Effect("Explosion", effect, true, true) util.BlastDamage(self, self:GetThrower(), pos, self.ExplosionRadius,self.ExplosionDamage)--self.ExplosionRadius, self.ExplosionDamage) self:SetDetonateExact(0) TotalTurtles = self.TurtleCount for i=1,self.TurtleCount do local spos = pos+Vector(math.random(-75,75),math.random(-75,75),math.random(0,50)) local contents = util.PointContents( spos ) local _i = 0 while i < 10 and (contents == CONTENTS_SOLID or contents == CONTENTS_PLAYERCLIP) do _i = 1 + i spos = pos+Vector(math.random(-125,125),math.random(-125,125),math.random(-50,50)) contents = util.PointContents( spos ) end local headturtle = SpawnNPC(self:GetThrower(),spos, TurtleNPCClass) headturtle:SetNPCState(2) --timer.Create("timer1", 10, 1, function() headturtle:SetPos(Vector(Friend:GetPos())) end) local turtle = ents.Create("prop_dynamic") turtle:SetModel("models/props/de_tides/vending_turtle.mdl") turtle:SetPos(spos) turtle:SetColor(Color( 75, 75, 255, 200 )) turtle:SetAngles(Angle(0,-90,0)) turtle:SetParent(headturtle) headturtle:SetNWEntity("Thrower", self:GetThrower()) --headturtle:SetName(self:GetThrower():GetName()) headturtle:SetNoDraw(true) headturtle:SetHealth(1000) --headturtle:SetParent(self:GetThrower()) --headturtle:AddEntityRelationship(Friend, D_LI, 99 ) print("yep, made it here") end self:Remove() else local spos = self.Entity:GetPos() local trs = util.TraceLine({start=spos + Vector(0,0,64), endpos=spos + Vector(0,0,-128), filter=self}) util.Decal("Scorch", trs.HitPos + trs.HitNormal, trs.HitPos - trs.HitNormal) self:SetDetonateExact(0) end --print(Friend) end --From: gamemodes\sandbox\gamemode\commands.lua --TODO: Adjust for TTT. function SpawnNPC( Player, Position, Class ) --for i = 1 ,2 do --print(Friend) Attacked = false TurtleExist = true FirstAttack = true local NPCList = list.Get( "NPC" ) local NPCData = NPCList[ Class ] -- Don't let them spawn this entity if it isn't in our NPC Spawn list. -- We don't want them spawning any entity they like! if ( !NPCData ) then if ( IsValid( Player ) ) then Player:SendLua( "Derma_Message( \"Sorry! You can't spawn that NPC!\" )" ); end return end local bDropToFloor = false -- -- This NPC has to be spawned on a ceiling ( Barnacle ) -- if ( NPCData.OnCeiling && Vector( 0, 0, -1 ):Dot( Normal ) < 0.95 ) then return nil end if ( NPCData.NoDrop ) then bDropToFloor = false end -- -- Offset the position -- -- Create NPC local NPC = ents.Create( NPCData.Class ) --local NPC2 = NPC --print(NPC2) if ( !IsValid( NPC ) ) then return end --NPC:AddEntityRelationship(player.GetByID(1), D_LI, 99 ) NPC:SetPos( Position ) -- -- This NPC has a special model we want to define -- if ( NPCData.Model ) then NPC:SetModel( NPCData.Model ) end -- -- Spawn Flags -- local SpawnFlags = bit.bor( SF_NPC_FADE_CORPSE, SF_NPC_ALWAYSTHINK) if ( NPCData.SpawnFlags ) then SpawnFlags = bit.bor( SpawnFlags, NPCData.SpawnFlags ) end if ( NPCData.TotalSpawnFlags ) then SpawnFlags = NPCData.TotalSpawnFlags end NPC:SetKeyValue( "spawnflags", SpawnFlags ) -- NPC:SetKeyValue( "Squad Name" , "player_squad" ) -- if ( NPCData.KeyValues ) then for k, v in pairs( NPCData.KeyValues ) do NPC:SetKeyValue( k, v ) end end -- -- This NPC has a special skin we want to define -- if ( NPCData.Skin ) then NPC:SetSkin( NPCData.Skin ) end -- -- What weapon should this mother be carrying -- --if Player:Nick() == "RichyRocker423" then Creator = Player else Creator = false end Creator = false NPC:Spawn() NPC:SetHealth(25) local colBlack = Color( 0, 0, 0, 255 ) -- Creates a black color NPC:SetColor( colBlack ) NPC:Activate() print(Player) for k, v in pairs(player.GetAll()) do NPC:AddEntityRelationship(v, D_LI, 50 ) print(v:Nick().. ": " ..NPC:Disposition(v)) end NPC:AddEntityRelationship(Player, D_LI, 99 ) NPC:SetColor( colBlack ) print(NPC:GetMoveType()) --NPC:SetMoveType(0) Waiting = false function TurtleIdle() print("idle") if Creator ~= false then Creator:ChatPrint("Idling the turtle.") end Idle = true waiting = false TurtleAttack = false NPC:ClearEnemyMemory() defend(Player, Player, 100, 0, false, true) end function TurtleWait() if Creator ~= false then Creator:ChatPrint("Turtle waiting") end Idle = true TurtleAttack = false NPC:ClearEnemyMemory() WaitPos = NPC:GetPos( ) Waiting = true NPC:StopMoving( ) NPC:SetLastPosition(WaitPos) NPC:SetSchedule( SCHED_FORCED_GO ) NPC:SetMoveType(0) end function TurtleDied( target, dmginfo ) if TurtleExist then if target == NPC or dmginfo:GetAttacker() == NPC then if Idle then print("idle is true") else print("idle is false") end if target == NPC then if NPC:Health() > 25 then NPC:SetHealth(25) end if Creator ~= false then Creator:ChatPrint("Turtle damage taken: " ..dmginfo:GetDamage().. ". Turtle Health: " ..(NPC:Health() - dmginfo:GetDamage()).."/" ..NPC:GetMaxHealth().. ".") end if dmginfo:GetDamage() >= NPC:Health() then if Creator ~= false then Creator:ChatPrint("The turtle died") end TurtleExist = false end if Creator ~= false then Creator:ChatPrint("Damage hook activated") end end if target:I
You should make it as an entity, not NPC, NPCs are forced to be on ground.
isnt an NPC an entity?
Yes it is, but it is a special type of entity. You won't be able to make a NextBot or SNPC fly afaik.
so what is it right now? because i have it flying.
Oh. If you already have done what you wanted to do, why you are here?
Sorry, you need to Log In to post a reply to this thread.