• Can't have 2 of the same entity
    2 replies, posted
So I have made a weapon, that when used spawns in a rotating 'ghost' smoke grenade that after a certain amount of time becomes solid, and can be picked up by any player on team 2 or 4. But if I increase the amount of players who has this weapon over the default of 1, placing a second one simply stops the first one from functioning. The older one stops rotating, and does not become solid. I'm pretty sure there has to be some 'local' here and there, but I've tried putting that everywhere I see logical, yet the same result. Can anyone see what's going on here? [CODE] local smokeSpawned = false function SWEP:SecondaryAttack() local ground = self.Owner:GetGroundEntity() if ground:IsWorld() == false then self.Owner:PrintMessage(HUD_PRINTTALK, "You need to stand on a static part of the world to place the smoke spawnpoint!") elseif ground:IsWorld() == true then if SERVER then -- Spawns the Smoke Spawnpoint entity! local smokepoint=ents.Create("sent_smokespawn") smokepoint:SetPos(self.Owner:GetPos() + Vector(0,0,15)) smokepoint:Spawn() local smokespawn=ents.Create("prop_dynamic") smokespawn:SetModel("models/props_junk/trafficcone001a.mdl") smokespawn:SetMaterial("models/props_combine/portalball001_sheet") smokespawn:SetPos(self.Owner:GetPos() + Vector(0,0,15)) smokespawn:SetAngles(Angle(180, 0, 0)) smokespawn:Spawn() smokespawn:SetMoveType(MOVETYPE_NONE) smokespawn:DrawShadow( false ) smokespawn:SetName("smokespawnpoint") smokespawn:SetCollisionGroup(COLLISION_GROUP_WEAPON) local smokeghost=ents.Create("prop_dynamic") smokeghost:SetModel("models/weapons/w_grenade.mdl") smokeghost:SetPos(self.Owner:GetPos() + Vector(0,0,35)) smokeghost:SetAngles(Angle(45, 0, 0)) smokeghost:SetMaterial("models/wireframe") smokeghost:Spawn() --smokeghost:SetMoveType(MOVETYPE_NONE) smokeghost:DrawShadow( false ) smokeghost:SetName("smokeghostpoint") smokeghost:SetCollisionGroup(COLLISION_GROUP_WEAPON) --smokeghost:SetCustomCollisionCheck( true ) smokeghost:EmitSound("weapons/sentry_spot_client.wav", 100, 100) umsg.Start("hassmokespawn", self.Owner) umsg.Bool(false) umsg.End() function Spin() if IsValid( smokeghost ) then smokeghost:SetAngles(smokeghost:GetAngles() + Angle(0,3,0)) for k, v in pairs(player.GetAll()) do if smokeSpawned == true then if v:GetPos():Distance(smokeghost:GetPos()- Vector(0,0,30)) < 20 and (v:Team() == 2 or v:Team() == 4) then if not v:HasWeapon("cr_smokegrenade") then v:Give("cr_smokegrenade") umsg.Start("hassmoke", v) umsg.Bool(true) umsg.End() smokeSpawned = false smokeghost:SetMaterial("models/wireframe") timer.Start("SmokeSpawnTime") end end end end end end hook.Add("Tick","Spinner", Spin) timer.Create("SmokeSpawnTime", GetConVar( "cr_smokedelay" ):GetFloat() * ((team.NumPlayers(2) + team.NumPlayers(4) + team.NumPlayers(3)) / (team.NumPlayers(1) + team.NumPlayers(5))), 0, function() --print("TIMER FIRED ") if smokeSpawned == false then smokeghost:SetMaterial("") smokeSpawned = true timer.Stop("SmokeSpawnTime") end end) timer.Start("SmokeSpawnTime") self.Owner:PrintMessage(HUD_PRINTTALK, "Smoke Spawnpoint successfully placed!") end if SERVER then self.Owner:StripWeapon("cr_smokespawn") end if CLIENT then RunConsoleCommand("use", "cr_hands") end else if SERVER then self.Owner:PrintMessage(HUD_PRINTTALK, "An unknown error occured ... what the fuck?") end end end[/CODE]
First things first: - timer.Create starts instantly after it's creation, doesn't require timer.Start() to be executed, timer.Start() is only used when you pause a timer. - You are overriding the timer each time a smoke is spawned, your best bet would be to make a dynamic timer name, use [code] "SmokeSpawnTime" .. smokeghost:EntIndex() [/code] for the name. - timer.Stop() isn't needed either, timer will delete itself after all repetitions were done.
[QUOTE=Netheous;45337110]First things first: - timer.Create starts instantly after it's creation, doesn't require timer.Start() to be executed, timer.Start() is only used when you pause a timer. - You are overriding the timer each time a smoke is spawned, your best bet would be to make a dynamic timer name, use [code] "SmokeSpawnTime" .. smokeghost:EntIndex() [/code] for the name. - timer.Stop() isn't needed either, timer will delete itself after all repetitions were done.[/QUOTE] I did not know that you can have anything other than strings as part of the name lol, thanks for it! You fixed the issue with the timer, and that combined with renaming the hook.Add the same way, and making the Spin function local made it work! Awesome ;D
Sorry, you need to Log In to post a reply to this thread.