Couldn't include file 'events.lua' (File not found)

I have a file called events.lua which contains all the functions for the event based things in my gamemode.

In shared.lua i have

include( 'events.lua' )

in line 1 and this has been working just fine but now it has completely stopped working ever since i added a new function to events.lua and even after removing said function i still get this error in the server console:

Couldn't include file 'events.lua' (File not found) (@gamemodes/plates/gamemode/shared.lua (line 1))

I’ve also tried taking the code from events.lua and just copying it into shared.lua to see if my code would still work without including the file but it doesnt and its no different from how it was before.

Any idea why this is happening?


shared.lua doesn’t work if you put the events.lua code inside? Strange, maybe there’s some character that somehow breaks it. Can you show the code?

There are the two functions in shared.lua that rely on events.lua

function chooseEvent()
    eventType = 0
    eventID = math.random(0,3)
    PrintMessage(HUD_PRINTTALK,typeName(eventType) .. ": " .. eventName(eventID,eventType))
function runEvent(players)
    for i=1,players do
        local ply = table.Random(team.GetPlayers(1)) --player.GetAll()[math.random(1,player.GetCount())]
        PrintMessage(HUD_PRINTTALK, "Plate Affected: " .. ply:GetName())
        if eventID == 0 then evPlatformSize(ply, 1.1)
        elseif eventID == 1 then evPlatformSize(ply, 0.9)
        elseif eventID == 2 then evPlatformBarrel(ply)
        elseif eventID == 3 then evPlatformSpin(ply)

and this is events.lua:

function eventName(id,type)
  if type == 0 then
    if id == 0 then return "Platform Growth (10%)"
    elseif id == 1 then return "Platform Shrink (10%)"
    elseif id == 2 then return "Explosive Barrel"
    elseif id == 3 then return "Spinning Plate"
    else return "ERROR" end
  else return "ERROR" end

function typeName(type)
  if type == 0 then return "Platform Event"
  elseif type == 1 then return "Player Event"
  elseif type == 2 then return "World Event"
  else return "ERROR" end

function evPlatformSize(ply, percent)
  local platform = platforms[numbers[ply:AccountID()]]
  if platform ~= nil then
    local offset = (3.5 * platform:GetModelScale() * percent) - (3.5 * platform:GetModelScale())
    if offset > 0 then platform:SetPos(Vector(platform:GetPos().x,platform:GetPos().y,platform:GetPos().z-offset)) end
    platform:SetModelScale(platform:GetModelScale() * percent, 0)
  else print("PLATFORM NOT FOUND") end

function evPlatformBarrel(ply)
  local platform = platforms[numbers[ply:AccountID()]]
  if platform ~= nil then
    local xx = platform:GetPos().x + math.random(-(platform:GetModelScale()*238)/2,(platform:GetModelScale()*238)/2)
    local yy = platform:GetPos().y + math.random(-(platform:GetModelScale()*238)/2,(platform:GetModelScale()*238)/2)
    local barrel = ents.Create("prop_physics")
    local phys = barrel:GetPhysicsObject()

function evPlatformSpin(ply)
  spinning[#spinning+1] = platforms[numbers[ply:AccountID()]]

Most of the variables that events.lua calls upon are found in shared.lua which i thought might have been the problem at first but it worked perfectly fine beforehand so I’m not quite sure

I can run this code fine, can you send/show a screenshot of the gamemode’s folder structure?

[editline]9th October 2017[/editline]

It’s possible that you accidentally deleted/moved the file or the file name is not fully lowercase as well, just make sure.

Are you running this on a listen server or dedicated one?

It’s a dedicated server, heres a pic of the folder

C:\gmod is the dedicated server folder.

ideas.txt can be ignored as its just for personal use

Are you AddCSLuaFile’ing it?

no, I’m just using

include( 'events.lua' )

as they’re meant to be server side functions

[editline]8th October 2017[/editline]

Also, it may help to know that it only prints that error once i join the server and all code leading up to the calling of a function from events.lua works just fine but once it calls a function from events.lua (which in my case happens to be typeName()) it outputs that error and stops working.

[editline]8th October 2017[/editline]

Also upon further testing I found out that all my code is running just fine (adding a print line to GM:Tick() prints a shit load and like i said all prior code runs so I can only assume all other code is running) just none of the code from events.lua (which is literally the entirety of the game)

If it’s serverside only then you should be including the file from init, not shared.

Okay i seemed to have solved the problem by removing a player team check and it runs all the code without any issue (even though it still gives the error of not being able to include events.lua)

I’ll report back if I find anything else out for others who happen to come across this thread