Check my Code Pls


function donamor( ply )
    if
	   ply:IsUserGroup() == "donator" then
	   ply:SetAmor ( 100 )
    end
end

hook.Add("PlayerSpawn",donamor)

I want donator spawning with 100 Amor

What the hell is amor?

Do you mean armor?

If so, the function is just ply:SetArmor(amount)

Also, your if statement has to be on the same line.


function donarmor( ply )
           if
	   ply:IsUserGroup() == "donator" then
	   ply:SetArmor (100)
	   end
end

hook.Add("PlayerSpawn",donarmor)

so??

i checked your code and it looks like code to me
i’ve seen enough code in my time to know what code looks like and this is definitely code

The amount of time it took you to make this thread you could have just tested it yourself?

ok :smiley:

Maybe go learn to read the wiki…and maybe just learn to program?

You didn’t set a hook name, you are using the class “IsUserGroup()” incorrectly, why is your if and if check on different lines, why didn’t you local your function? So many things wrong with just what, 6 lines of code?

[editline]12th December 2016[/editline]

Actually, it doesn’t. Lua doesn’t run with whitespaces.
It’s just poor programming technique…
Correction* It’s just people who don’t know how to program technique.

Oh, i wasnt aware of this.

Sorry, my mistake.

I already posted this in your previous thread:


hook.Add("PlayerSpawn", "DonatorArmour", function(ply)
   -- Check the usergroup case-insensitive
   if (ply:GetNWString("usergroup"):lower() == "donator") then
      ply:SetArmor(100)
   end
end)

Why not use the method already given in gmod,

Player:GetUserGroup? Also in the gmod implementation of user group the key is “UserGroup”, so unless this is a custom implementation that won’t work.

It’s case-insensitive iirc. Also, I didn’t know that function existed, but I would still use the prior just because GetUserGroup uses GetNWString internally.

This code makes me wanna throw up. You kinda goofed your PlayerSpawn qoutes, also, why are you getting an NWString and making it lower? It would be so much easier to just use GetUserGroup

Ah, well you’re right on the case-insensitive part, however, isn’t the point of a function to wrap up commonly used things? For convenience sake I’d rather use GetUserGroup as it’s sorter, it also returns “user” if no value was found, your current code would error in that situation.

Because I typed it from my phone, sorry. Also, read my previous post.

[editline]12th December 2016[/editline]

usergroup will always be set from looking at Source engine code, but of course that’s reliant programming and I agree a bad standard on my part from old coding habits. As for not using GetUserGroup, I agree about wrapping commonly used functions, but I feel that one-line simplifications like that are useless and is just hiding implementation details. That’s just my own personal philosophy approaching functions like that, but the only problem with my linked code is the missing quote.

All decent admin mods will support GetUserGroup while not all use SetNWString. Unless you have no choice but to make hacky workarounds you should not touch internal stuff.

GetUserGroup was added in 2014 – people used GetNWString for years, or admin mods had their own version to check user groups (IsUserGroup for ULX). If there was a unified, abstract usergroup checking form for a majority of admin mods, I would use it, but from looking at Evolve, ULX, and SG, GetNWString is the standard. Again, it’s personal preference for me.

http://forum.facepunch.com/showthread.php?t=1454164

This is why we should push for CAMI to be honest.

code_gs already answered your question. I dont know why people set him as dumb.
Also the wiki knowledge is missing. Please use it.
https://wiki.garrysmod.com/page/Player/SetArmor

Player:IsUserGroup is a Garry’s Mod function. All mods should support those two functions and you should use them in your code unless you absolutely can’t.

It used to be a ULX-only function. Again, it’s from old habits and my own personal philosophy – now that I know these functions exist in base Garry’s Mod, I will use them.