Jump to content

[SOLVED] TopTimes


Ascla

Recommended Posts

Posted (edited)

Hey guys,

I need your help for use the function call.

My script :

function hunter(pickupID, pickupType, vehicleModel) 
    if (pickupType == "vehiclechange") then 
        if (vehicleModel == 425) then 
            outputDebugString ("Hunter !")           
            call(getResourceFromName("race_toptimes"), "SMaptimes:getTimeForPlayer", source ) 
        end 
    end 
end 
addEventHandler('onPlayerPickUpRacePickup', source, hunter) 
addEvent('onPlayerPickUpRacePickup', true) 

function SMaptimes:getTimeForPlayer(player) 
    outputDebugString("Function getTimeForPlayer appelé !") 
    local i = self:getIndexForPlayer( player ) 
  
    if not i then 
        return false 
    end 
  
    return self.dbTable.rows[i].timeMs 
end 

TopTime meta :

... 
<export function="SMaptimes:getTimeForPlayer" type="server"/> 
... 

I got this error :

ERROR: attempt to call a nil value

ERROR: [gamemodes]/..../main.lua:212: call: failed to call 'race_toptimes:SMaptimes:getTimeForPlayer

Thank for your help,

Edited by Guest
Posted

Quite the problem you have here bro, I think it has to do with the Map Times using OOP. I'm going to give you a small edit and we will see if it works.

In the "race_toptimes" resource, add this near the getTimeForPlayer function:

local callTimeForPlayer = function(player) sMaptimes:getTimeForPlayer(player) end 

In the "race_toptimes" resource, export the callTimeForPlayer function.

We can now modify your original script:

function hunter(pickupID, pickupType, vehicleModel) 
    if (pickupType == "vehiclechange") then 
        if (vehicleModel == 425) then 
            outputDebugString ("Hunter !")          
            call(getResourceFromName("race_toptimes"), "callTimeForPlayer", source ) 
        end 
    end 
end 
addEvent('onPlayerPickUpRacePickup', true) 
addEventHandler('onPlayerPickUpRacePickup', source, hunter) 

Let me know of your findings, this problem intrigues me.

Posted

I tryed your code but i have always the same error :(

Thank for your help

ERROR: attempt to call a nil value

ERROR: [gamemodes]/..../main.lua:212: call: failed to call 'race_toptimes:callTimeForPlayer

Posted

I find a solution. I've transfer the script file who called in the script file who was called. I just use the function : TriggerEvent

Thanks you so much.

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...