Hey dear readers,
im currently working on an Icon that get drawed if a special hook called.
Here the Codes:
[CODE]local generator_pos
local ICON_EXITHELP = Material("icons/icon_exit.png")
local function AddGenerator()
local pos, endtime
pos = net.ReadVector()
if !LocalPlayer():Alive() then return end
generator_pos = pos
end
net.Receive("sls_popularhelp_AddGenerator", AddGenerator)
-- GeneratorIcon
if LocalPlayer():Team() != TEAM_KILLER && generator_pos then
if !GM.ROUND.Active then
generator_pos = nil
else
local pos1 = generator_pos:ToScreen()
surface.SetDrawColor(Color(255, 255, 255))
surface.SetMaterial(ICON_EXITHELP)
surface.DrawTexturedRect(pos1.x - 64, pos1.y - 64, 128, 128)
end
end
[/CODE]
This was the Client File.. The Draw of Material Works
Now My Problem File:
[CODE]util.AddNetworkString("sls_popularhelp_AddGenerator")
local function AddGenerator(pos)
if !GM.ROUND.Active || !IsValid(GM.ROUND.Killer) then return end
net.Start("sls_popularhelp_AddGenerator")
net.WriteVector(pos)
net.Send(GM.ROUND.Survivors)
end
local function GeneratorAppear()
--Icon Generator
AddGenerator(Vector(ents.FindByName( "sls_generator" )))
end
hook.Add("sls_round_StartWaitingPolice", "sls_round_GeneratorIcon", GeneratorAppear)[/CODE]
If this last hook it calls it shows the Icon defined in the client file but not on the position where the entity spawned on the map.
I just need the right Vector from the Entity... The code from the entity here:
[CODE]function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local ent = ents.Create("sls_generator")
ent:SetPos( tr.HitPos + tr.HitNormal )
ent:Spawn()
return ent
end[/CODE]
Thanks for reading this and have a nice evening.
FindByName is to get entities by their target name (set in hammer). If you allow sls_generators to always transmit with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/UpdateTransmitState]ENT:UpdateTransmitState[/url], you can loop through the entities with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/FindByClass]ents.FindByClass[/url] clientside and use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetPos]Entity:GetPos[/url] on them.
Changed to: [CODE]for k, v in pairs( ents.FindByClass( "sls_generator" ) ) do
--Icon Generator
AddGenerator(Vector(v:GetPos()))
end[/CODE]
Now if the hook gets called it shows it
You don't have to have to call the Vector copy-constructor -- GetPos will already return a unique vector.
Oh... ok it works on both ways.. but know i want if a special thing happens the material gets removed automatically did u know how i can handle this? because setting vecotr to 0,0,0 makes it not disappear
Could you describe your issue differently or with code? Your post didn't make much sense.
Hm If the Hook.runs he draws the material on the condition: if I pick one item up the function will run.
But now if the other quest is finished like activating the generator the material should disappear.
Sorry, you need to Log In to post a reply to this thread.