request for a flashlight script that would run out of power just like in Half Life 2.
also can you leave comments as well on how its put together to work. hope I am not asking for to much.
I imagine this wouldn't be too difficult, it's just a script that contains a variable like 100 that slowly counts down in a loop. I haven't done Gmod programming for ages, but I'll look into it tomorrow
when it counts down to 0 how do you stop the player from turning it on again ?
[QUOTE=gravelhunter;39116842]when it counts down to 0 how do you stop the player from turning it on again ?[/QUOTE]
return false
I'd love to write this but I'm a novice coder; I do have an idea how it would work though:
[code]OnPlayerSpawn set FlashlightPower to 100
If impulse 100 = true then subtract 1 from FlashlightPower every 3 seconds
If impulse 100 = false then wait 2 seconds and add 1 to FlashlightPower every 1 second[/code]
This is just pseudocode but it seems like that general idea would work.
that would work . if only someone made it
Basically, the only thing you need in this: [url]http://wiki.garrysmod.com/page/Hooks/Base/PlayerSwitchFlashlight[/url]
will i got this set up but i now but idk how to pause the curtime
[lua]
hook.Add( "Think", "FlashlightPower", function()
for k, v in pairs( player.GetAll() ) do
if v:Alive() then
if v:FlashlightIsOn() then
if v.flashlightbattery < CurTime() then
v:Flashlight( false )
v:AllowFlashlight( false )
v.flashlightbattery = CurTime()
end
else
v.flashlightbattery = CurTime() + 5
//v:AllowFlashlight( true )
end
end
end
end)
[/lua]
That's a bad and laggy method.
[QUOTE=Wizard of Ass;39124217]That's a bad and laggy method.[/QUOTE]
well how would you do it then ?
I posted the hook you need above.
Rather than checking all players every frame, just use the hook.
i keep getting a stack overflow on player:flashlight()
[lua]
local function flashlightpower( ply )
if ply:FlashlightIsOn() then
if ply.flashlightbattery < CurTime() then
ply:Flashlight()
ply:AllowFlashlight( false )
end
else
ply.flashlightbattery = CurTime() + 5
ply:AllowFlashlight( true )
end
end
hook.Add( "PlayerSwitchFlashlight", "flashlightpower", flashlightpower )
[/lua]
bump?
I'm also interested in this; it would be a good thing to have implemented in my gamemode.
[url]http://www.garrysmod.org/downloads/?a=view&id=85659[/url]
This has what you're looking for.
Sorry, you need to Log In to post a reply to this thread.