LUA Errors - Help Fast Please


10/02/2010 - 23:03:04: Lua Error: Timer Error: [@gamemodes\darkrp\gamemode\player.lua:359] bad argument #1 to 'floor' (number expected, got nil)

[lua]
function meta:PayDay()
if ValidEntity(self) and self:GetTable().Pay == 1 then
if not RPArrestedPlayers[self:SteamID()] then
**** local amount = math.floor(DB.RetrieveSalary(self)) ****
if amount == 0 then
Notify(self, 4, 4, LANGUAGE.payday_unemployed)
else
self:AddMoney(amount)
Notify(self, 4, 4, string.format(LANGUAGE.payday_message, CUR … amount))
end
else
Notify(self, 4, 4, LANGUAGE.payday_missed)
end
end
end[/lua]

Spams ALOT making the server lag…


Error #2


20:03:04 L 10/02/2010 - 23:03:06: Lua Error: Timer Error: [lua\includes\modules\hook.lua:105] attempt to index local 'gm' (a number value)

Spams ALOT!!!

[lua] if ( gm ) then

    local GamemodeFunction = gm[ name ]
    if ( GamemodeFunction == nil ) then return nil end
    
    if ( type( GamemodeFunction ) != "function" ) then
        Msg( "Calling Non Function!? ", GamemodeFunction, "

" )
end

    // This calls the actual gamemode function - after all the hooks have had chance to override
    b, rA, rB, rC, rD, rE, rF, rG, rH = pcall( GamemodeFunction, gm, ... )
    
    if (!b) then
    
        gm[ name .. "_ERRORCOUNT" ] = gm[ name .. "_ERRORCOUNT" ] or 0
        gm[ name .. "_ERRORCOUNT" ] = gm[ name .. "_ERRORCOUNT" ] + 1
        ErrorNoHalt( tostring(rA) .. "(Hook: "..tostring(name)..")

" )
return nil

    end
    
    return rA, rB, rC, rD, rE, rF, rG, rH
    
end[/lua]

DB.RetrieveSalary(self) is not returning a number. It is probably trying to get a networked value or a normal value from the player object, and it isn’t initialized.

Some code somewhere is using **[Hook.Call

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Hook.Call)** improperly. The second argument is supposed to be the gamemode table, or nothing at all (nil). Whoever wrote the script that is doing this is trying to pass an argument to a hook, but failed to account for the second argument to **[Hook.Call

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Hook.Call)**.

That is all I can say with the code you showed me.

Is there an easy fix for either of them?

It’s hard to say. The second one would probably be easy. Search all your Lua files for any references to **[Hook.Call

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Hook.Call)** (PRGrep is useful for this kind of thing) and see which one is passing a bad second argument. Then, insert nil as a second argument.

As for the first one, you need to find the script that defines DB.RetrieveSalary(), figure out what variable it is trying to use, and then hunt down the script that is supposed to initialize it. Then make sure it always gets initialized properly before a call to DB.RetrieveSalary() can be made.

I’m gonna try to find it :stuck_out_tongue:

I fixed it by going into hook.lua, and searching for the line, then I read another thread about how GM. has to be capital, I changed it to capital and haven’t received an error within the past 10 minutes.

That’s not a proper fix. hook.lua is a standard gmod file and SHOULD NOT BE EDITED!!! gm needs to be lowercase as it is the function argument being passed. Find the code that is calling it wrong, and fix that.

EDIT:

If you want to make it easier, TEMPORARILY add this to the top of the hook.Call function:
[lua]
if gm && type(gm) != “table” then error(“hook.Call used incorrectly!!!”, 2) end
[/lua]

That will cause the game to report an error at the offending script, instead of Garry’s function.

Can that script be anywhere or does it have to be near the hook.call that is passing a bad arguement

What the hell happened to the lua tags.

[lua]Oh god[/lua]

Please please please dont be broken…


Code work

Humm?

Read my post again.

Example:

[lua]
function Call( name, gm, … )

if gm && type(gm) != "table" then error("hook.Call used incorrectly!!!", 2) end -- This is the new line in hook.lua

    local b, rA, rB, rC, rD, rE, rF, rG, rH
    local HookTable = Hooks[ name ]

[/lua]