Hello, Need a teacher !

I want to learn Lua coding language. Its my first coding language and that says quite a lot about my expierence. I try to learn everything myself but I often do something silly and end up with an error. So I need not full time teacher but just someone who can point out my mistakes and help me a bit and sometimes test stuff I know. I am gonna reward the person who volunteers after some time. Thanks for reading this and Have a nice day.

theres a lot of free knowledge already, no need to pay someone

Errors are natural part of coding process. If you have any questions you can just post here, BUT BE SURE TO:

  1. Google it first and not just first page
  2. Check the wiki
  3. Check for similar threads
  4. Search GMod code for similar code ( You can search online at GitHub )
  5. Search for code in other addons

Don’t let this stop you! You should use errors as an opportunity to learn more, and if you genuinely cannot get passed it, that’s okay too and you can just go work on something else.

That attracts people better ._. All I want is just a teacher who knows what he is doing and can say what are my mistakes and help me understand all the stuff better. I don’t really care if it costs me a little.

your not going to be learning if your not learning from your mistakes

No, that’s not going to happen. Not how you want at least. The way you’re wording it is that you won’t even consider paying them. You actually don’t even mention anything about that. “Reward” the person who volunteers after some time. Yeah, that’s not going to work for you. I guarantee it.

So, you want someone to just donate they’re time and do it for free. Then, you’re “gonna reward” them. With what? Them being super admin on your server?

It’s going to take a lot longer than you think. It’s also going to cost more. I’m pretty sure any decent coder that can teach another person is going to charge per hour. Probably not cheap either. So, I guess you could go to Coderhire and make a job for that.

Also, it doesn’t seem like English is your first language. That’s going to be harder for you and the teacher. Just how I see it personally.

But I am like stuck so much times and have no idea what to do. Well for example this

AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

// Serverside only stuff goes here
// locals here
local HealthToReg = 70
// local end here
   Name: gamemode:PlayerLoadout( )
   Desc: Give the player the default spawning weapons/ammo
function GM:PlayerInitialSpawn( ply )
	ply:SetGravity( 1 )
	ply:SetWalkSpeed( 300 )
	ply:SetRunSpeed( 500 )	
	ply:SetTeam( 3 )

function GM:PlayerSpawn( ply )
	if ply:Team()== 1 then
	if ply:Team()== 2 then
	if ply:Team()== 3 then
		ply:SetRunSpeed( 1000 )
local RDM = math.random( 1, 2 )
        if RDM == 1 then
                ply:SetTeam( 1 )
        elseif RDM == 2 then
                ply:SetTeam( 2 )
function Health ( ply )
  if ply:Health() <= HealthToReg then
	ply:SetHealth(ply:Health() + 2)
  if ply:Health() == 100 then
  return false
timer.Create("Health", 1, 0)
hook.Add("PlayerSpawn", "Healthregen", Health)
timer.Create("Health", 1, 0 function( ply )

(Trying to create timer that would heal you constantly if you’re hurt) It just says file missing error 1 and I feel stupid. I bet someone will go just like “HAH HE’S STUPID ITS OBVIOUS MISTAKE” but I have no idea what’s wrong with this entirely. I tried various variations I could think of this but just gives me more mistakes ._.
Edit : TheLuaNoob I see what you mean, when I posted this post to expect a teacher was equal to expect a miracle to happen.

Lua tags please…

Although this isn’t my code. I remember this from somewhere. It worked for DarkRP last time I checked.

I think this is it. I don’t know some shit like that. I’m sure you can edit it to your liking. Put it in init.lua.
local function Tick( )
for k, v in ipairs( player.GetAll( ) ) do
if v:Alive( ) and v:Health( ) < 100 and v:GetLastDamagedTime( ) <= -5 then
v:SetHealth( math.min( 100, v:Health( ) + 5 ) )
v:SetLastDamagedTime( 0 )
hook.Add( “Tick”, “Regeneration.Tick”, Tick )

Well thank you I will try learning out of that. But that is a bit more advanced than I know.
Edit : NOPE
[ERROR] gamemodes/test/gamemode/init.lua:45: attempt to call method ‘GetLastDamagedTime’ (a nil value)

  1. v - gamemodes/test/gamemode/init.lua:45
  2. unknown - lua/includes/modules/hook.lua:82

Yeah, I know hold on.

Alright, with some major fucking tweaking… It works.

Although, it’s not my code so don’t bitch at me. It will work though. Any gamemode.

Put this in init.lua


function DataField( ent, key, name, force, fl )
fl = fl or DF_BOTH

if bit.band( fl, DF_READ ) ~= 0 then
    ent[ "Get" .. name ] = function( e )
        local res = e:GetSaveTable( )[ key ]
        if force == FORCE_NUMBER then
            return tonumber( res ) or 0
        elseif force == FORCE_STRING then
            return tostring( res )
        elseif force == FORCE_BOOL then
            return tobool( res )
            return res

if bit.band( fl, DF_WRITE ) ~= 0 then
    ent[ "Set" .. name ] = function( e, v )
        if force == FORCE_NUMBER then
            e:SetSaveValue( key, tonumber( v ) or 0 )
        elseif force == FORCE_STRING then
            e:SetSaveValue( key, tostring( v ) )
        elseif force == FORCE_BOOL then
            e:SetSaveValue( key, tobool( v ) )
            e:SetSaveValue( key, v )


DataField( FindMetaTable(“Player”), “m_flLastDamageTime”, “LastDamagedTime”, FORCE_NUMBER )

local function Tick( )
for k, v in ipairs( player.GetAll( ) ) do
if v:Alive( ) and v:Health( ) < 100 and v:GetLastDamagedTime( ) <= -5 then
v:SetHealth( math.min( 100, v:Health( ) + 5 ) )
v:SetLastDamagedTime( 0 )

hook.Add( “Tick”, “Regeneration.Tick”, Tick )

It’s not as easy as you think. So, don’t worry you’re not “stupid” for not knowing it.

dude you actually have to define it lol

[editline]20th October 2013[/editline]

thats the scariest code i’ve ever seen

edit: im going now, so yeah have this


Yeah, you’d think it would be easier than that.

I remember trying to figure out how this worked months ago. Took a long fucking time and was annoying as hell. Finally found this thing… Was able to edit it a bit… And you get regenerating health like a motherfucker.

Ok let me be clear with you I understand almost none of that code ._.

Yeah, don’t touch it… It’s like Skynet. That shits dangerously confusing. I don’t think regenerating health is a good place to start “learning”.

It does work though. So, that’s good at least. You should do something easier for now and try to “learn” about that later on once you’re comfortable.

It’s probably not the “best” method of doing it, but it works. I remember that a lot of this “regenerating” shit didn’t work. This is the one way I know of that works.

If anyone has a simple and better method feel free to share.

Yeah I am like watching now some tutorials about GMOD lua coding and one was timers so I thought " HOW ABOUT ME BEING ORIGINAL AND MAKING TIMER FOR HEALTH REGAINING" And now I know its so ridicusly hard. Thanks a lot for that I just won’t touch that for now.

That code is actually terrifying.

[lua]function HealthRegenThink()
if CurTime() > (LastHRThink or 0) + 0.1 then
LastHRThink = CurTime()
for _,ply in pairs (player.GetAll()) do
if ply.HPRegenNext == nil then
ply.HPRegenNext = CurTime()
local hp = ply:Health()
if (ply.LastHit or 0) + 5 < CurTime() then
if ply.HPRegenNext < CurTime() then
if ply:Health() >= 100 or not ply:Alive() then else
ply.HPRegenNext = CurTime() + ply.HPRegenSpeed
ply:SetHealth (hp+1)

timer.Create(“HeathThink”, .1, 0, HealthRegenThink)[/lua]

That’ll work on it’s own. If you want it to only regen health 5 seconds after they last took damage, in your gamemode’s OnPlayerTakeDamage, when it gets to the true part, put in ply.LastHit = CurTime() If it’s not a gamemode, hook on to that in your addon or wherever.