Jump to content

Script spamming with errors after some time...


OffRoader23

Recommended Posts

OK, so this code works, most of the time, but sometimes it seems when a player Quits it doesn't fully cancel out the timer which causes the console to get spammed with errors. Here is my code:

function playerJoin () 
    moneys = setTimer ( GiveMoneys, 500, 0, source ) 
    setPlayerMoney( source, 25000 ) 
end 
  
function playerLeave () 
    killTimer ( moneys ) 
end 
  
function GiveMoneys ( source ) 
    if (isPlayerInVehicle( source ) == true) then 
        local value = getPlayerSpeed ( source, 1 ) 
        local speeds = math.ceil(value * 0.3) 
        givePlayerMoney ( source, speeds ) 
    end 
end 
  
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerLeave ) 

And I get spammed with this error after the servers been up and people have left/joined a lot.

[23:43:23] WARNING: fr.lua: Bad 'player' pointer @ 'isPlayerInVehicle'(1) - Line: 46 
[23:43:23] WARNING: fr.lua: Bad 'player' pointer @ 'isPlayerInVehicle'(1) - Line: 46 
[23:43:23] WARNING: fr.lua: Bad 'player' pointer @ 'isPlayerInVehicle'(1) - Line: 46 
[23:43:23] WARNING: fr.lua: Bad 'player' pointer @ 'isPlayerInVehicle'(1) - Line: 46 
[23:43:23] WARNING: fr.lua: Bad 'player' pointer @ 'isPlayerInVehicle'(1) - Line: 46 
[23:43:23] WARNING: fr.lua: Bad 'player' pointer @ 'isPlayerInVehicle'(1) - Line: 46 

Isn't the player pointer the SOURCE of the timer, which was originally sent when the player joins the server, and should kill the timer when they leave? What am I doing wrong here. Any help would be appreciated. Or a way to disable error reporting to the console, because the script seems to work just fine, it errors when someone leaves the server and for some reason the timer hasn't stopped.

Edit: Sorry if this is in the wrong section.

Edit: OK this code doesn't work at all anymore...it sorta dies a lot.

Link to comment
  
local timer = {} 
  
function playerJoin () 
    timer[source] = setTimer ( GiveMoneys, 500, 0, source ) 
    setPlayerMoney( source, 25000 ) 
end 
  
function playerLeave () 
    killTimer ( timer[source] ) 
    timer[source] = nil 
end 
  
function GiveMoneys ( source ) 
    if (isPlayerInVehicle( source ) == true) then 
        local value = getPlayerSpeed ( source, 1 ) 
        local speeds = math.ceil(value * 0.3) 
        givePlayerMoney ( source, speeds ) 
    end 
end 
  
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerLeave ) 

you were using the same variable for every player on the server, say a player decides to quit right after another player joined, 'moneys' would be overwritten and it would kill the wrong timer

EDIT: updated

Edited by Guest
Link to comment

Wow, so that's how you store variables in an array. Sweet. Thanks for the help!

Is there a way to compact this though, so it runs ONE timer that just checks it for every player, rather then making a separate timer for each player?

Also, I tried this code, it is working, but is still spamming me with an isPlayerInVehicle error still, I joined and left the server and it's still running the timer, it gives me a bad Arguement @ killTimer.

Edit: Nevermind, I think I got it, I removed timer[source] = nil from the timer, and that seems to have stopped it for now. I'll see what kind of results I get tomorrow when theres more people on the server. Thanks again for the help.

Link to comment
function scriptStart() 
    setTimer ( GiveMoneys, 500, 0 ) 
end 
  
function GiveMoneys() 
    local players = getElementsByType ( "player" ) 
    if ( #players ~= 0 ) then 
        for i, v in ipairs ( players ) do 
            if isPlayerInVehicle( v ) then 
                local value = getPlayerSpeed ( v, 1 ) 
                local speeds = math.ceil(value * 0.3) 
                givePlayerMoney ( v, speeds ) 
            end 
        end 
    end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), scriptStart ) 

you can modify it so it only checks the players that are in vehicles (insert them in a table when they enter a car and remove them when they leave), or you could make it clientside and then you wouldn't need the loop

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...