How to create a custom method?

I’ve looked online for an extensive amount of time, and I’ve found sites that seem to explain it, but I’m just too much of a newb or too dense to understand them. I’d like to be able to creatue a custom method to evaluate a number and output a result based on that number

For example:

ply:Height(“100”) will return “shorty”

ply:Height(“300”) will return “Giant”

Can you guys explain this to me in plain english? I do understand lua to a certain degree, just not the the depth that some websites go into.

[lua]
local playerMeta = FindMetaTable(“Player”) – Get the player metatable.

– Define a function within the player metatable.
function playerMeta:Height(height)
– Check if the height is equal to or greater than 300.
if (height >= 300) then
– Return giant if it is.
return “Giant”
else
– Otherwise, return shorty.
return “Shorty”
end
[/lua]

Then if you were to run that clientside and did:

print(LocalPlayer():Height(300)) then it would print Giant.

In lua this is referred to as a function. You define a function like this:

[lua]
function your_function_name(arguments)
code goes here
end
[/lua]

You run your function like this:

[lua]
your_function_name(arguments)
[/lua]

In this example, I add a function to the player metadata, which means that it can be run on any player.

[lua]
local plymeta = FindMetaTable(“Player”)

function plymeta:Height(height)
if height == nil then return end
if height > 100 then return “Giant” else return “shorty” end
end
[/lua]

You can then run ply:Height(height_number_argument), in a way such as:

[lua]
local playerheight = ply:Height(number goes here)

or you could also do

print(ply:Height(number goes here))
[/lua]

When defining your function, you can type in anything as an argument name. The arguments in the defining of the function are just placeholders for values sent to the function during calling.

[lua]
function add(penis, spiders, cactus)
return penis+spiders+cactus
end

print(add(1,10,11))
>22
[/lua]

Arguments do not have to be included in a function definition. Your function could just do a specific non variable task, and would be defined and run as functionname() instead of functionname(arguments).

Both of you, thanks a bunch!

You could simplify that by doing:
[lua]
local Player = FindMetaTable(“Player”)
if !Player then return end

function Player:Height(height)
return (height >= 300 and “Giant”) or “Shorty”
end
[/lua]