Creating gamemode functions that affect players/objects?

I’d like to make some convenience functions for a gamemode I’m starting but I’m not sure how to write them out in a way that will make them work or where to place them (shared.lua if I had to guess). The functions I’d like to make would work something like this

[lua]
function GetCookies()
return ply.Cookies
end

function GiveCookies(num)
ply:GetCookies() + num
end

//and work like this

ply:GiveCookies(50)

//ply now has 50 cookies
[/lua]

not sure how good of an example this is, but it’s the best I could think of.
The primary issue, I think, would be getting gmod to know what “ply” is (I mean in functions like PlayerSpawn() ply is already defined but I don’t know how to define “ply” in GiveCookies())

any suggestions?



local entMeta = FindMetaTable( 'Player' );
function entMeta:RocketMan( )
self:SetVelocity( Vector( 0, 0, 10000 ) )
end

for k,v in pairs( player.GetAll() )do
v:RocketMan()
end


Thank you, but again, where do I place these functions so that they work globally?

If you insert it into the meta-table, it’ll be global for that realm. So if you made it SERVER only, it’ll work on the SERVER-side, but not the CLIENT-side. If you made it work on the CLIENT, it won’t work on the SERVER but will work on the CLIENT. If it’s in a shared file, it’ll be accessible on both the CLIENT and SERVER.

Here’s a little bit of information about loading files across realms:
https://dl.dropboxusercontent.com/u/26074909/tutoring/loading_files_across_realms.lua

Alright, thank you!