MrAngel (Not a previous Clockwork Developer) does crap

Angel

she/her/they nonbinary transfem
Joined
Apr 26, 2016
Messages
9,940
Nebulae
8,986
@Zak & @Zombine watch out 'cause "Not a previous Clockwork Developer" has fucking arrived.

Either way...

First thing I did (not counting the Gmod Wiki Challenges):

Gist Link
Code:
hook.Add("PlayerSay", "ChatCommands", function(client, text)

    if (IsValid(client)) then
        local PlayerSay = string.Explode(" ", text)
        local amount = tonumber(PlayerSay[2])

        if (PlayerSay[1]:lower() == "/kill") then
            client:Kill()
            client:ChatPrint("You killed yourself!")
            return
        end


        if (amount < 0 or amount > 100) then
            client:ChatPrint("You can only use values between 0 and 100!")
            return
        end


        if (PlayerSay[1]:lower() == "/sethealth") then
            client:SetHealth(amount)
            client:ChatPrint("Your Health has been set to " .. amount)

         
        elseif (PlayerSay[1]:lower() == "/setarmor") then
            client:SetArmor(amount)
            client:ChatPrint("Your Armor has been set to " .. amount)
         
        end
    end
end)
Thanks to @Zombine for answering all my dumb ass questions and helping me a lot with this very simple, yet odd piece of lua.

Very simply, you can kill yourself by typing /kill and set your health and armor with /sethealth and /setarmor respectively.
It is capped at 100 for both armor and health.. and uh.. it prints shit when you do it.


Hopefully more to come!
 

Zak

Resident xenophile
Joined
Apr 26, 2016
Messages
5,887
Nebulae
16,124
@Zak & @Zombine watch out 'cause "Not a previous Clockwork Developer" has fucking arrived.

Either way...

First thing I did (not counting the Gmod Wiki Challenges):

Gist Link
Code:
hook.Add("PlayerSay", "ChatCommands", function(client, text)

    if (IsValid(client)) then
        local PlayerSay = string.Explode(" ", text)
        local amount = tonumber(PlayerSay[2])

        if (PlayerSay[1]:lower() == "/kill") then
            client:Kill()
            client:ChatPrint("You killed yourself!")
            return
        end


        if (amount < 0 or amount > 100) then
            client:ChatPrint("You can only use values between 0 and 100!")
            return
        end


        if (PlayerSay[1]:lower() == "/sethealth") then
            client:SetHealth(amount)
            client:ChatPrint("Your Health has been set to " .. amount)

        
        elseif (PlayerSay[1]:lower() == "/setarmor") then
            client:SetArmor(amount)
            client:ChatPrint("Your Armor has been set to " .. amount)
        
        end
    end
end)
Thanks to @Zombine for answering all my dumb ass questions and helping me a lot with this very simple, yet odd piece of lua.

Very simply, you can kill yourself by typing /kill and set your health and armor with /sethealth and /setarmor respectively.
It is capped at 100 for both armor and health.. and uh.. it prints shit when you do it.


Hopefully more to come!
you can use math.clamp to make it automatically clamp values to a certain number
 
Reactions: List

Angel

she/her/they nonbinary transfem
Joined
Apr 26, 2016
Messages
9,940
Nebulae
8,986
you can use math.clamp to make it automatically clamp values to a certain number
Actually, I used math.clamp in a first version, but that wasn't the goal.

By using math.clamp I couldn't get the ''error message'' displayed to the user if he tried /setarmor 110 ; it would simply auto clamp and set it to 100, when I specifically wanted it to say he couldn't do that.
Pretty much was a simple exercise of 'okay, how can I do this?' just as a learning process in case I need it at some point.



for some reason I never bother to add anything like
Code:
    if (IsValid(client)) then

in my code

you're already better than me congratulations



:(

Well, @Zombine told me that whenever you run anything on a player you should make sure he is still a valid entity, in case he disconnects or something.
Not that I would matter here (I don't think) since the player has to type it themselves, but it's just so I keep in my that part I need to do, I guess.
 
Reactions: List