Best-Killer Posted February 2, 2016 Share Posted February 2, 2016 attempt to call global 'findPlayer' a nill value) local pt = { } exports.scoreboard:scoreboardAddColumn ( "Playtime", root, 50 ) addEventHandler ( "onResourceStart", resourceRoot, function ( ) for i, v in pairs ( getElementsByType ( "player" ) ) do pt [ v ] = 0 local x = tonumber ( getElementData ( v, "PlayerFunct:HiddenPTMins" ) ) if ( x ) then pt [ v ] = x end end end ) addEventHandler ( "onResourceStop", resourceRoot, function ( ) for i, v in pairs ( getElementsByType ( "player" ) ) do local x = 0 if ( pt [ v ] ) then x = pt [ v ] end setElementData ( v, "PlayerFunct:HiddenPTMins", x ) end end ) setTimer ( function ( ) for i, v in pairs ( getElementsByType ( "player" ) ) do if ( not pt [ v ] ) then pt [ v ] = 0 end pt [ v ] = pt [ v ] + 1 updatePlayerPlaytime ( v ) end end, 60000, 0 ) function updatePlayerPlaytime ( v) if ( not ( pt [ v ] ) ) then return false end return setElementData ( v, "Playtime", tostring ( convertMinsToActualTime ( pt [ v ] ) ) ) end function deletePlayerPlaytime ( p ) if ( p and pt [ p ] ) then pt [ p ] = nil return true end return false end function setPlayerPlaytime ( p, m ) if ( p and m ) then pt [ p ] = m updatePlayerPlaytime ( p ) return true end return false end function getPlayerPlaytime ( p ) if ( p and pt [ p ] ) then return pt [ p ] end return false end function convertMinsToActualTime ( m ) local hours = 0 while ( m >= 60 ) do m = m - 60 hours = hours + 1 end -- Minutes only if ( hours == 0 ) then return tostring(m).."m" -- Hours and minutes elseif ( hours > 0 ) then return tostring(hours)..":" ..tostring(m).."" end end addCommandHandler("setplaytime", function (source, _, who, h, min) if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Owner")) then if findPlayer(who) then if getPlayerFromNamePart(who) then local findPlayer = exports.SAEGPlayerFunctions:getPlayerFromNamePart(who) t[findPlayer(who)] = {["hours"] = tonumber(h), ["min"] = tonumber(min), ["sec"] = 0} end end end end) addCommandHandler ( "playtime", function ( p ) if ( not pt [ p ] ) then pt [ p ] = 0 end exports.SAEGMessages:sendClientMessage ( "You have a total of "..tostring(pt[p]).." minutes of online-time at SAEG:RPG", p, 0, 255, 0 ) end ) Line 92 Link to comment
KariiiM Posted February 2, 2016 Share Posted February 2, 2016 findPlayer is not defined. local findPlayer = exports.SAEGPlayerFunctions:getPlayerFromNamePart(who) Post the exported function Link to comment
Best-Killer Posted February 2, 2016 Author Share Posted February 2, 2016 function getPlayerFromNamePart ( str ) if ( str ) then local players = { } for i, v in ipairs ( getElementsByType ( 'player' ) ) do if ( string.find ( string.lower ( getPlayerName ( v ) ), string.lower ( str ) ) ) then table.insert ( players, v ) end end if ( #players == 0 or #players > 1 ) then return false end return players[1] end return false end Link to comment
SpecT Posted February 2, 2016 Share Posted February 2, 2016 You can't get returned value from exported function. Put the function getPlayerFromNamePart in your code. Link to comment
Best-Killer Posted February 2, 2016 Author Share Posted February 2, 2016 addCommandHandler("setplaytime", function (source, _, findPlayer, h, min) if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Owner")) then if findPlayer then if getPlayerFromNamePart2(findPlayer) then local findPlayer = getPlayerFromNamePart2(findPlayer) t[findPlayer(findPlayer)] = {["hours"] = tonumber(h), ["min"] = tonumber(min), ["sec"] = 0} end end end end) addCommandHandler ( "playtime", function ( p ) if ( not pt [ p ] ) then pt [ p ] = 0 end exports.SAEGMessages:sendClientMessage ( "You have a total of "..tostring(pt[p]).." minutes of online-time at SAEG:RPG", p, 0, 255, 0 ) end ) function getPlayerFromNamePart2 ( name ) --MY EPIC PLAYER FIND PART if ( name ) then for _, player in ipairs ( getElementsByType ( "player" ) ) do local name_ = getPlayerName ( player ):gsub ( "#%x%x%x%x%x%x", "" ):lower ( ) if name_:find ( tostring ( name ):lower ( ), 1, true ) then return player end end end end i got : attempt to call local findPlayer (a userdata value) Link to comment
Bonus Posted February 2, 2016 Share Posted February 2, 2016 You can't use "findPlayer(findPlayer)". Its not a function, it's a player (or nil). Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now