I made a custom flashlight to make sure the light in firstperson is the same as in thirdperson, but it does not work. I have tried spawning the entity separately and it works perfectly.
Here is the code:
[code]
local lighton = 0
function LampOn()
local lamp = ents.Create( "gmod_lamp" )
local pos = ply:GetPos()
if ( !IsValid( lamp ) ) then return end
lamp:SetModel( "models/maxofs2d/lamp_flashlight.mdl" )
lamp:SetModelScale(0)
lamp:SetFlashlightTexture( "effects/flashlight001" )
lamp:SetLightFOV( 65 )
lamp:SetRenderMode( RENDERMODE_TRANSALPHA )
lamp:SetColor( Color( 255, 255, 255, 255 ) )
lamp:SetDistance( 450 )
lamp:SetBrightness( .3 )
lamp:Switch( true )
lamp:SetToggle( true )
lamp:SetPos( Vector( pos.x, pos.y, pos.z+30 ) )
lamp:SetParent( ply, 4 )
lamp:Spawn()
lamp:SetCollisionGroup( 10 )
lamp:SetAngles( Angle( ply:GetAngles().x-10, ply:GetAngles().y, ply:GetAngles().z ) )
end
function FlashlightBind( ply, bind, pressed )
if not pressed then return false end
if (bind == "impulse 100") then
if lighton == 1 then -- If lamp is turned on, turn it off (Remove it)
lighton = 0
ply:ChatPrint("Turned off the active light")
ply:EmitSound("buttons/combine_button1.wav")
lamp:Remove()
return true
else -- Else turn on the lamp
lighton = 1
ply:ChatPrint("Turned on the light")
ply:EmitSound("buttons/button9.wav")
LampOn()
return true
end
end
end
hook.Add( "PlayerBindPress", "Turnoo", FlashlightBind )
[/code]
When I turn it on/off it gives me this:
[code]
Turned on the light
[ERROR] addons/betterflashlight/lua/autorun/betterflashlight.lua:5: attempt to call field 'Create' (a nil value)
1. LampOn - addons/betterflashlight/lua/autorun/betterflashlight.lua:5
2. fn - addons/betterflashlight/lua/autorun/betterflashlight.lua:42
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
Turned off the active light
[ERROR] addons/betterflashlight/lua/autorun/betterflashlight.lua:36: attempt to index global 'lamp' (a nil value)
1. fn - addons/betterflashlight/lua/autorun/betterflashlight.lua:36
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:110
[/code]
You are running ents.create in clientside
[QUOTE=gonzalolog;52084985]You are running ents.create in clientside[/QUOTE]
I tried making it all serverside but then nothing worked and no errors either.
PlayerBindPress is clientside only -- you'll have to network it. Also, you are referencing lamp outside of the local scope
[QUOTE=code_gs;52085016]PlayerBindPress is clientside only -- you'll have to network it. Also, you are referencing lamp outside of the local scope[/QUOTE]
Awesome, got it to work. Thanks! :D
Sorry, you need to Log In to post a reply to this thread.