Search the Community
Showing results for tags 'play time'.
-
Hi Guis I was making a small script and it was firs writer so i have problem when a player win system give times put the times frozen in scoreboard it doesnt move i see the debug and i find that server.lua:206: attempt to index global 'A' (a nill value) [DUP x5] server.lua:206: attempt to index global 'A' (a nill value) So Its The server side Codes and any one help me pls !! captchaNums = 5 -- captcha letters length wordTimeInSec = 25 --- the time before the word disappear in seconds [ default 11 seconds ] --prizefrom,prizeto = 500,800 -- the prize random num timerfrom,timerto = 1.5,5.5 -- the random timer that shows the word [ default from 3 to 15 minutes ] ---- unChangeable wordOn = false --theWord = nil --thePrize = nil wordTime = wordTimeInSec * 1000 Error = { "هلا", "هلا", "انا", "ضض", "تنورا", "حياكم", "سيرفر" } g_root = getRootElement() addEvent("send_M",true) addEventHandler("send_M",root, function( Q, K, K1, A) if tonumber(A) then createCode(Q,A) coans = K coans1 = K1 Amont = A end end ) function createCode(Q,A) for k,v in ipairs( getElementsByType("player") ) do exports.easytext:displayMessageForPlayer(v,1, "=========", wordTime, 0.07, 0.5, 0, 255, 0, 255, 1.6) exports.easytext:displayMessageForPlayer(v,2, "Word : "..Q.."", wordTime, 0.07, 0.533, 255, 255, 0, 255, 1.6) exports.easytext:displayMessageForPlayer(v,3, "Prize : "..A.." Hours ", wordTime, 0.07, 0.563, 255, 255, 0, 255, 1.6) exports.easytext:displayMessageForPlayer(v,4, "=========", wordTime, 0.07, 0.593, 0, 255, 0, 255, 1.6) end startCodeTimer() wordOn = true end function startCodeTimer() codeTimer = setTimer( function () removeCode() OutPut("تم الغاء المسابقة لعدم وجود إجابات",root,0,255,0,true) end , wordTime , 1 ) end function removeCode() for k,v in ipairs( getElementsByType("player") ) do exports.easytext:clearMessageForPlayer(v,1) exports.easytext:clearMessageForPlayer(v,2) exports.easytext:clearMessageForPlayer(v,3) exports.easytext:clearMessageForPlayer(v,4) end if isTimer ( codeTimer ) then killTimer(codeTimer) end coans = nil coans1 = nil wordOn = false end function playerchatqaw ( msg, msgty, A) if coans1 == Error then coans = nil coans1 = nil OutPut("تم الغاء المسابقة لعدم وجود إجابات",getRootElement(),255,255,0,true) removeCode() else if coans then if string.find(msg,coans,1) then OutPut("وقد ربح "..Amont.." ساعة ╰ "..getPlayerName(source).." ╯ الفائز هو",getRootElement(),math.random(255),math.random(255),math.random(255),true) local pTime = { getPlayerTime ( source ) } setElementData ( source, 'PlayTime', tostring ( pTime [ 1 ] + Amont .. ':' .. pTime [ 2 ] .. ':' .. pTime [ 3 ] ) ) --givePlayerMoney(source,Amont) removeCode() coans = nil coans1 = nil end end end end addEventHandler ("onPlayerChat",g_root,playerchatqaw) function playerchatqaw1 ( msg, msgty, A) if coans1 == Error then coans = nil coans1 = nil OutPut("!! تم الغاء السؤوال لنفاذ الوقت",getRootElement(),255,255,0,true) removeCode() else if coans1 then if string.find(msg,coans1,1) then OutPut("وقد ربح "..Amont.." ساعة ╰ "..getPlayerName(source).." ╯ الفائز هو",getRootElement(),math.random(255),math.random(255),math.random(255),true) givePlayerMoney(source,Amont) removeCode() coans = nil coans1 = nil end end end end addEventHandler ("onPlayerChat",g_root,playerchatqaw1) ---------------------------------------------------------------------------------------------- function getPlayerTime ( Player ) local TimeData = getElementData(Player,'PlayTime') or '0:0:0'; if ( TimeData ) then return tonumber(split(TimeData,':')[1]) , tonumber(split(TimeData,':')[2]), tonumber(split(TimeData,':')[3]); end end exports.scoreboard:addScoreboardColumn('PlayTime') addEvent("addTime",true) addEvent("removeTime",true) addEvent("ToServer",true) local t = { } local w = {} addEventHandler("ToServer",root, function (word,get,time) if word and tonumber(get) and tonumber(time) then table.insert(w,{word,get}) setTimer(function () for _,v in ipairs(w) do if v[1] == word and v[2] == get then table.remove(w,i) end end end,time*60*60*1000,1) end end ) addEventHandler("onConsole",root, function (msg) for _,v in ipairs(w) do if msg == v[1] then local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then if not getAccountData ( playeraccount, "time-"..msg) then addPlayerTime(source,v[2]) setAccountData( playeraccount, "time-"..msg,true) end end end end end ) addEventHandler("addTime",root, function (to,time) if to == "all" then for _,v in ipairs(getElementsByType("player")) do addPlayerTime(v,time) end else plr = getPlayerFromName(to) if plr then addPlayerTime(plr,time) end end end ) addEventHandler("removeTime",root, function (to,time) if to == "all" then for _,v in ipairs(getElementsByType("player")) do removePlayerTime(v,time) end else plr = getPlayerFromName(to) if plr then removePlayerTime(plr,time) end end end ) function addPlayerTime(plr,time) time = math.floor(time) A[plr]['hour'] = tonumber(A[plr]['hour'] or 0) + time end function removePlayerTime(plr,time) time = math.floor(time) A[plr]['hour'] = tonumber(A[plr]['hour'] or 0) - time end function checkValues( source,arg1,arg2) if (arg2 >= 60) then A[ source ][ 'min' ] = tonumber( A[ source ][ 'min' ] or 0 ) + 1 A[ source ][ 'sec' ] = 0 end if (arg1 >= 60) then A[ source ][ 'min' ] = 0 A[ source ][ 'hour' ] = tonumber( A[ source ][ 'hour' ] or 0 ) + 1 end return arg1, arg2 end setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do if (not A[ v ]) then A[ v ] = { ["hour"] = 0, ["min"] = 0, ["sec"] = 0 } end A[ v ][ 'sec' ] = tonumber( A[ v ][ 'sec' ] or 0 ) + 1 local min,sec = checkValues ( v, A[ v ][ 'min' ] or 0, A[ v ][ 'sec' ] or 0 ) local hour = tonumber( A[ v ][ 'hour' ] or 0 ) setElementData( v, "PlayTime", tostring( hour )..':'..tostring( min )..':'..tostring( sec ) ) end end, 1000, 0 ) function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local sValue = getElementData( source,'PlayTime' ) local hour = tonumber( A[ source ][ 'hour' ] or 0 ) local min = tonumber( A[ source ][ 'min' ] or 0 ) local sec = tonumber( A[ source ][ 'sec' ] or 0 ) setAccountData ( playeraccount, "PlayTime-hour", tostring(hour) ) setAccountData ( playeraccount, "PlayTime-min", tostring(min) ) setAccountData ( playeraccount, "PlayTime-sec", tostring(sec) ) setAccountData ( playeraccount, "PlayTime", tostring(sValue) ) end A[ source ] = nil end function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local time = getAccountData ( playeraccount, "PlayTime" ) local hou = getAccountData ( playeraccount, "PlayTime-hour") local min = getAccountData ( playeraccount, "PlayTime-min") local sec = getAccountData ( playeraccount, "PlayTime-sec") if ( time ) then setElementData ( source, "PlayTime", time ) A[ source ]["hour"] = tonumber(hou) A[ source ]["min"] = tonumber(min) A[ source ]["sec"] = tonumber(sec) else setElementData ( source, "PlayTime",0 ) setAccountData ( playeraccount, "PlayTime",0 ) end end end addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) Any Help pls
- 10 replies
-
- play time
- server side
-
(and 1 more)
Tagged with: