My addon/entity is a "Disguise Box" that allows players to temporarily change thier playermodel to be "disguised."
I want to draw HUD on the player that has used by addon's screen, to inform them that they are "Disguised." I want this HUD to only appear on thier screen for the duration they are disguised (Currently 5s).
init.lua
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/props/CS_militia/footlocker01_closed.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if( phys:IsValid() ) then
phys:Wake()
end
end
function ENT:Use(activator, caller)
if caller.PlayerDisguised == true then
caller:PrintMessage( 3, "Already disguised!" )
else
caller.PlayerDisguised = true
local InitialModel = caller:GetModel()
PossiblePModels = {
"models/player/alyx.mdl",
"models/player/barney.mdl",
"models/player/breen.mdl",
"models/player/eli.mdl",
"models/player/gman_high.mdl"
}
caller:SetModel( table.Random(PossiblePModels) )
timer.Simple(5, function()
caller:SetModel(InitialModel)
caller.PlayerDisguised = false
end )
self:Remove()
end
end
[/lua]
cl_init.lua
[lua]
include("shared.lua")
function ENT:Draw()
self:DrawModel()
local Ang = self:GetAngles()
Ang:RotateAroundAxis(self:GetAngles():Forward(), 0)
Ang:RotateAroundAxis(self:GetAngles():Up(), 90)
cam.Start3D2D(self:LocalToWorld( Vector(-3,-17,13) ), Ang, 0.2)
draw.WordBox(2, 5, -30, "Disguise Box", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
// draw.WordBox(0, 5, 30, "owner", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
cam.End3D2D()
end
[/lua]
Drawing to the HUD has to be done on the client. Change caller.PlayerDisguised to a NetworkVar so the client can read it.
Then on the client add a callback whenever the NetworkVar is changed. According the wiki NetworkVarNotify doesn't work on the client if the NetworkVar is updated on the server. This means you'll have to use NW2Var's and SetNWVarProxy.
In the callback if the NWVar is changed to true then create a HUDPaint hook. If the NWVar is changed to false then remove the hook therefore removing the message on the hud.
[url]http://wiki.garrysmod.com/page/Entity/SetNWVarProxy[/url]
[url]http://wiki.garrysmod.com/page/GM/HUDPaint[/url]
Sorry, you need to Log In to post a reply to this thread.