I need someone to point out all the errors in my script(s)

I’m trying to write a rewards system, the idea being that the longer somebody plays in a server, the more cool stuff they get in their inventory (health packs, speed boosts ETC)

This is the first time I’ve tried to write something that isn’t a SWEP or a SENT, and it isn’t working as well as I’d hoped.

Here’s the code I’ve written, my comments explain what the problem is

lua\autorun\client\rd_autorun.lua:
[lua]Rewardeus = {} – Setup the table

– Clientside includes go here
include(“rd_cl_init.lua”)[/lua]

lua\autorun\server\rd_autorun.lua:
[lua]Rewardeus = {} – Setup the table
Rewardeus.Inventories = {}

– Clientside file distributions go here
AddCSLuaFile(“autorun/client/rd_autorun.lua”)
AddCSLuaFile(“rd_cl_init.lua”)

– Serverside includes go here
include(“rd_sv_init.lua”)
include(“rd_sv_newplayer.lua”)[/lua]

lua\rd_cl_init.lua:
[lua]-- Print a message in the console
Msg("=============================================
“)
Msg(”| Rewardeus successfully started clientside |
“)
Msg(”=============================================
")[/lua]

lua\rd_sv_init.lua:
[lua]Msg("=============================================
“)
Msg(”| Rewardeus successfully started serverside |
“)
Msg(”|-------------------------------------------|
“)
Msg(”| Loading inventory file… |
")

dataTable = file.Read(“inv.txt”)
– Loop through all lines in the file
for line in string.gmatch(dataTable, “[^
]+”) do
table.insert(Rewardeus.Inventories, line)
end

Msg("| Done loading inventory. |
“)
Msg(”=============================================
")[/lua]

lua\rd_sv_newplayer.lua
[lua]function CheckNewPlayer(ply) – Function to check if a player has already got an inventory or not
Msg("[debug] CheckNewPlayer
“)
for i, line in pairs(Rewardeus.Inventories)
data = string.Explode(”;", line) – Note: I know this doesn’t actually do anything,
Msg("[debug] " … data … "
") – the point is that this code isn’t being reached
end
end
hook.Add(“PlayerInitialSpawn”, “CheckNewPlayer”, CheckNewPlayer)[/lua]

So yeah, my inventory messages in the rd_sv_init and rd_cl_init files are being printed, but nothing inside rd_sv_newplayer seems to be getting run. What thing(s) have I done wrong?

Why exactly did you split this into this many files / directories?

C++ programmer, it’s ingrained into me now :saddowns:

Your file inclusion looks really messed up (but maybe thats just me). You try to include files from the autorun directories, which are actually located a few directories down. I am not sure if this will work out as you planned it. Furthermore, you are doing this:

[lua]AddCSLuaFile(“autorun/client/rd_autorun.lua”) [/lua] …while you are in the autorun folder.

I thought the inludes were relative to the Lua folder :ohdear:

I guess that’s my problem then, thank you. I’ll fix it up and post results.