Super confused about something

Hi, I’m making my own gamemode and I’m super confused about something.

I want to make my own variable that’s a boolean. It would be set to true whenever a player respawns and to false whenever another function happens.
I don’t know how to make the variable though, that’s specific to a player. I can’t find any answers ANYWHERE, and I know it has to be super simple and it’s frustrating the hell out of me.


edit: Also why the hell is this breaking my gamemode? Sorry but it’s really frustrating me… it seems like any if statement is breaking my init.lua

function TestProtected( ply )
    if ply:protected = true then
        ply:PrintMessage(3, "You are protected.")
        ply:PrintMessage(3, "You aren't safe.")
concommand.Add("amprotect", TestProtected)

[lua]if ply:protected = true then[/lua]
You are setting a true inside a statement on a method

you should use something like

[lua]if ply.protected == true then[/lua]

Looks like it worked, thanks!

Now I’m trying to make a variable true whenever a player respawns, but false whenever they take out a weapon. I want it to be a custom variable, how would I do this? I’ve been trying to figure this out all day and I just can’t and there’s no good documentation on it that I could find.

Also, when using : it expects a function is being called meaning it is going to give an error expecting ( or ()…

Use . to access sub-values, : for function calls. If you ever redirect a function, say you want ply:PrintMessage to be ply:Notify, you can do something like

META_PLAYER = FindMetaTable( "Player" ); 

then you can call ply:Notify( 3, “You aren’t safe!” ); just as if you’d typed PrintMessage in place of Notify.

There are many other associations regarding : and . …

Oh, okay that clears that up a lot. I thought something had changed maybe.

Alright so now I have it so that the var btkProtected becomes true when the player respawns, but false when they take out an AK. So, I want part of the HUD to change according to the variable. How would I make it repaint part of the HUD whenever the variable chagnes? thanks

If it is shared code that executes at the same time on client / server, then just HUDPainting the var should be enough. If it is server-side, then it’d need to be networked, OR you can find an alternative way.

Example, you want something to draw on hud for AK? Why not use the SWEP Hud function? If you still want to use HUDPaint, use

// Get player and store in var, check is valid
local _p = LocalPlayer( );
if ( !IsValid( _p ) ) then return; end

// Make sure GetActiveWeapon function exists
if ( !_p.GetActiveWeapon ) then return; end

// Get the active weapon and make sure is valid
local _w = _p:GetActiveWeapon( );
if ( !IsValid( _w ) then return; end

// Get the class, if the class is the type you want, then do what you want. GetActiveWeapon means you're holding the gun....

The code to change the variable is in init.lua and the HUD bit is in cl_init.lua an dI can’t use the weapons thing, because I’m going to be using it for all weapons other than building ones. Do you know any resources on Networking the things?

I really appreciate your help, I’m learning a lot today :slight_smile:

networking example using booleans:

Networking something to the player when they join, then displaying something on hud, then removing after set time.

I have more; but curious exactly what you’re trying to do ( end-result )…

Build to kill - people spawn with god, once they pull out a weapon they’re vulnerable

[editline]2nd July 2014[/editline]

Okay I was thinking - the files include aech other so the function should work across them all. there are 2 HUD functions - the drawHUD for protection ON and for protection OFF. couldn’t I just use a hook to say “whenever the variable becomes false, use hud2()” and vice versa? if so, how?