I can't use flashlights in my custom gamemode, so I've been trying to find a way to enable them (Yes, they do work on other gamemodes). After some searching I found the CanUseFlashlight and AllowFlashlight functions, but not a set way to use them. I've been tinkering around with them and so far nothing.
I've seen and/or tried it the following ways;
ply:AllowFlashlight( boolean canFlashlight ) (you insert true or false for boolean, right?)
ply:AllowFlashlight( canFlashlight (boolean) ) (you insert true or false for boolean, right?)
ply:AllowFlashlight( class.CanUseFlashlight ) (what does class mean?)
ply:CanUseFlashlight( true )
ply:CanUseFlashlight( true )
return true
CLASS.CanUseFlashlight = true (this was put under a local class function)
I've also tried setting both allowflashlight and canuseflashlight to true at the same time. Thus far I've been dropping these function sin the init_lua (usually under player spawn). I've also tried giving the player suits and used the mp_flashlight command. Zilch.
Obviously, I'm a bit confused. Could anyone shed light on the situation? (Pun not intended)
Also, how can I set the aux power to limited again? I want the flashlights to have a limited battery. I tried the console command but no dice.
ply:AllowFlashlight(true)?
[QUOTE=Lerpaderp;40383683]ply:AllowFlashlight(true)?[/QUOTE]
In the dev console, I get a message saying that it's a nil value.
[QUOTE=Animyr;40386218]In the dev console, I get a message saying that it's a nil value.[/QUOTE]
Did you set the "ply" to something? Like: ply = player.GetAll()[1].
You can't just throw this in "ply:AllowFlashlight(true)" without telling what "ply" stands for.
[lua]
--Example that will allow all people to use the flashlight
for k, v in pairs(player.GetAll()) do
v:AllowFlashlight(true)
end
[/lua]
or if you're in a singleplayer-game
[lua]
player.GetAll()[1]:AllowFlashlight(true)
[/lua]
Is there a better solution?
Yes .. if you haven't disabled the players flashlight you can do:
[lua]
function GM:PlayerSwitchFlashlight(ply, SwitchOn)
return true
end
[/lua]
[QUOTE=Nak;40387154]Did you set the "ply" to something? Like: ply = player.GetAll()[1].
You can't just throw this in "ply:AllowFlashlight(true)" without telling what "ply" stands for.
[/QUOTE]
Well, no. I've been using all sorts of equations like ply:SetWalkSpeed( number )
ply:SetModel
ply:Give( "weapon_crowbar" )
And so on. I was given to understand that as long as I kept the phrase before the colon the same, garry's mod would understand. I was also given to understand that the allowflashlight function was similar (it had the same format). Is it different, after all? Should I define ply anyway? In what file would I define it?
Anyways, I'll look into your suggestions (though I have tried Switchflashlight code before, actually).
Well since you're making a gamemode and not an addon. I'll suggest you use the:
[lua]
function GM:PlayerSwitchFlashlight(ply, SwitchOn)
return true
end[/lua]
In the init.lua file as I said.
This should allow anyone to use the flashlight, since I'm using that function for my own gamemode.
Are you deriving your game mode from sandbox or base for one? If you are deriving it from sandbox then you have some rendering problems because sandbox auto enables it. On the flip side if your deriving base then use the following to enable it. Put this in server side code such as the init.lua. This is tested and it working!
[CODE]
hook.Add("PlayerInitialSpawn", "Flashlight", function(ply)
if(!ply:CanUseFlashlight())then
ply:AllowFlashlight(true)
end
end)
[/CODE]
[QUOTE=Lordgunner58;40390173]Are you deriving your game mode from sandbox or base for one? [/QUOTE]
Good question. I'm not sure. How can I check?
At any rate, your suggested piece of code got the flashlight working. Thanks!
Step two; anyone know how to limit the aux power again? It's infinite in GM by default, as I'm sure you know. If I were to limit it again, would it be unchangeable, or would there be some way to control the amount and recharge rate of aux power? I'd like to be able to do that, so different players on different teams have different amounts of stamina.
Sorry, you need to Log In to post a reply to this thread.