• Gmod FindInSphere
    7 replies, posted
So I'm making a code for capturing flags and I have no clue on how to do this and just wan to know if I can get some links to other threads What I want to do : If players enters sphere it will say in chat [Player] is capturing [Sphere] and if it gets captured (time table of like 10secs) it changes to a color and it will say in chat [Player] Captured [Sphere] Codes right now : cl_init.lua [QUOTE]include('shared.lua') function ENT:Draw() self.BaseClass.Draw(self) self:DrawModel() render.SetColorMaterial() render.DrawSphere( self:GetPos(), 350, 80, 80, Color( 0, 175, 175, 100 ) ) end[/QUOTE] init.lua [QUOTE]AddCSLuaFile( "cl_init.lua" ) -- Make sure clientside AddCSLuaFile( "shared.lua" ) -- and shared scripts are sent. include('shared.lua') function ENT:Initialize() self:SetModel( "models/props_docks/dock01_pole01a_128.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics self:SetSolid( SOLID_VPHYSICS ) -- Toolbox local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end function ENT:Use( activator, caller ) return end function ENT:Think() -- We don't need to think, we are just a prop after all! end [/QUOTE] Shared.lua [QUOTE]ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName= "A Flag" ENT.Author= "Javs" ENT.Contact= "" ENT.Purpose= "" ENT.Instructions= "" ENT.Spawnable = true ENT.AdminSpawnable = false[/QUOTE]
First - Wrap your code in [CODE] or [lua] tags, not [QUOTE] tags :snip:
It doesnt have to be a sphere, no. Ill try
You can use a sphere or a box. Between two checks, use ents.FindInSphere/Box and store the return the calls. If a player exists in the old table but not the new, send the leaving message. If a player doesn't exist in the old table but exists in the new one, send the entering message.
Im not the best at coding, ive started only 1month ago, do you have any tips of how to do that
[QUOTE=code_gs;52396548]You can use a sphere or a box. Between two checks, use ents.FindInSphere/Box and store the return the calls. If a player exists in the old table but not the new, send the leaving message. If a player doesn't exist in the old table but exists in the new one, send the entering message.[/QUOTE] You can avoid using ents.FindIn completely by defining another entity and using StartTouch and EndTouch. Similar to how timer zones are made in bhop: [lua]-- Taken from Flow's bhop code function ENT:Initialize() local BBOX = (self.max - self.min) / 2 self:SetSolid( SOLID_BBOX ) self:PhysicsInitBox( -BBOX, BBOX ) self:SetCollisionBoundsWS( self.min, self.max ) self:SetTrigger( true ) self:DrawShadow( false ) self:SetNotSolid( true ) self:SetNoDraw( false ) self.Phys = self:GetPhysicsObject() if self.Phys and self.Phys:IsValid() then self.Phys:Sleep() self.Phys:EnableCollisions( false ) end end function ENT:StartTouch( ent ) -- Do shit end function ENT:EndTouch( ent ) -- Do shit end[/lua]
Thanks <3 [editline]24th June 2017[/editline] Doesnt work for some reason with [CODE] PrintMessage( HUD_PRINTTALK, "I'm new here." )[/CODE]
[QUOTE=JasonMan34;52396597]You can avoid using ents.FindIn completely by defining another entity and using StartTouch and EndTouch. Similar to how timer zones are made in bhop:[/QUOTE] Having an entity manage it is going to be more expensive overall I believe since its physics and tick simulation have to constantly be maintained over a simple loop func.
Sorry, you need to Log In to post a reply to this thread.