nikitafloy Posted April 17, 2014 Share Posted April 17, 2014 Писал, писал, решил дописать код. Используя таблицы, вносил игроков и таймер в ячейки, чтобы потом по ним проходиться и пользоваться. Из-за моего малого опыта наделал ошибки. Первого игрока освобождает заранее, второй остается за решеткой с 2-ой ошибкой. 1) Массив в строке (29-34) повторяется 2 раза. 2) Ошибки. Видимо, неверно составил алгоритм работы. (71 строка) idtableonline = {} function idtableonlineresourceStart () for i = 1, 10 do idtableonline[i] = false end end addEventHandler("onResourceStart", root, idtableonlineresourceStart) function sitPr ( thePlayer, cmd, Psource, timer ) for _, aclGr in ipairs ( { 'Security', 'FBI' } ) do if ( isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( thePlayer )), aclGetGroup ( aclGr ) ) == true ) then if ( isElementWithinColShape ( thePlayer, fP ) ) then if ( Psource ) then local occup = getPedOccupiedVehicle ( thePlayer ) if ( occup ) then local Psource = getPlayerFromName ( Psource ) local occupData = setElementData ( Psource, "namePrison", tostring(getPlayerName ( Psource )) ) if ( isElementWithinColShape ( Psource, fP ) ) then if ( pC[ getElementModel( getPedOccupiedVehicle ( thePlayer ) ) ] ) then local rnd = math.random ( 1, #habz ) if ( getVehicleOccupant ( occup ) ) then if (tonumber(timer) <= 30) then local account = getPlayerAccount ( Psource ) local oldskin = setAccountData ( account, 'oldskin', tostring (getElementModel ( Psource )) ) local oldfgt = setAccountData ( account, 'oldfgt', tostring (getPedFightingStyle ( Psource )) ) takePlayerMoney ( Psource, 15000 ) givePlayerMoney ( thePlayer, 15000 ) outputChatBox ( 'Не забудьте, что без Вас из тюрьмы никто не выберется!', thePlayer, 255, 145, 0 ) outputChatBox ( 'Следить за временем заключения - Ваша работа!', thePlayer, 255, 145, 0 ) setPlayerMuted ( Psource, true ) outputChatBox ( 'Вы были обезмолвлены на время заключения.', Psource, 255, 145, 0 ) outputChatBox ( 'Если кто-то из работников полиции нарушит свои полномочия - обращайтесь в', Psource, 255, 145, 0 ) outputChatBox ( '/report, либо в группу. За Вами обязательство предъявить надлежащие факты.', Psource, 255, 145, 0 ) setTimer (fadeCamera, 2000, 1, Psource, true) setTimer (function() spawnPlayer ( Psource, habz[rnd][1], habz[rnd][2], 1004, 90, 299, 3, 0 ) setCameraTarget ( Psource ) end, 2000, 1 ) for i=1, 10 do if prisoner[i]==nil then outputChatBox('1') prisoner['iname']=getPlayerName( Psource ) prisoner['itimer']=tonumber(timer) break else return end end for i=1, 10 do if (idtableonline[i] == false) then if tonumber(prisoner['itimer'])~=nil then if prisoner['itimer'] and prisoner['iname'] then idtableonline[i] = true break end end end i=i end setTimer(function() for i=1, 10 do if (idtableonline[i] == true) then if tonumber(prisoner['itimer'])~=nil then if prisoner['itimer'] and prisoner['iname'] then prisoner['itimer']=tonumber(prisoner['itimer'])-1 outputChatBox('first:'..prisoner['itimer']..'') end end end if (tonumber(prisoner['itimer']) <= 0 ) then outputChatBox('second:'..prisoner['itimer']..'') spawnPlayer(getPlayerFromName(tostring(prisoner['iname'])),0,0,0) prisoner['itimer']=nil prisoner['iname']=nil idtableonline[i] = false end end end, 60000, 0) else outputChatBox('Нельзя сажать дольше, чем на 30 минут.', thePlayer, 255, 0, 0 ) end end end end end end end end end end addCommandHandler ( 'sPr', sitPr ) Link to comment
CocaColaBear Posted April 17, 2014 Share Posted April 17, 2014 Вы немного не так делаете. Как я понял, у вас у каждого игрока будет свой таймер. Зачем это? Запоминайте время, когда игрок был помещен в тюрьму и срок. Потом на клиенте все это считаете (даже в том же onClientRender при прорисовке оставшегося времени заключения), а когда срок заканчивается - отправляете данные на сервер. А при выходе игрока из игры, просто обновить время, помещения в тюрьму и убавить срок, в зависимости от того, сколько он просидел. Link to comment
nikitafloy Posted April 17, 2014 Author Share Posted April 17, 2014 Вы немного не так делаете. Как я понял, у вас у каждого игрока будет свой таймер. Зачем это? Запоминайте время, когда игрок был помещен в тюрьму и срок. Потом на клиенте все это считаете (даже в том же onClientRender при прорисовке оставшегося времени заключения), а когда срок заканчивается - отправляете данные на сервер. А при выходе игрока из игры, просто обновить время, помещения в тюрьму и убавить срок, в зависимости от того, сколько он просидел. На Client: function check(timer) hours, minutes = getTime() timePrison = timer+minutes if (tonumber(timePrison)>60) then hours=hours+1 timePrison=minutes-timePrison end local prisTimer = setTimer(function() hoursN, timeN = getTime() if ( hoursN == hours and timeN == timePrison) then if isTimer ( prisTimer ) then killTimer ( prisTimer ) end end end, 1000, 0) end addEvent( "checkTimer", true ) addEventHandler( "checkTimer", getRootElement(), check ) Link to comment
nikitafloy Posted April 19, 2014 Author Share Posted April 19, 2014 Вы немного не так делаете. Как я понял, у вас у каждого игрока будет свой таймер. Зачем это? Запоминайте время, когда игрок был помещен в тюрьму и срок. Потом на клиенте все это считаете (даже в том же onClientRender при прорисовке оставшегося времени заключения), а когда срок заканчивается - отправляете данные на сервер. А при выходе игрока из игры, просто обновить время, помещения в тюрьму и убавить срок, в зависимости от того, сколько он просидел. Телепортирует всех игроков. --Server triggerClientEvent ( 'checkTimer', root, Psource, tonumber(timer) ) setTimer (fadeCamera, 2000, 1, Psource, true) setTimer (function() spawnPlayer ( Psource, habz[rnd][1], habz[rnd][2], 1004, 90, 299, 3, 0 ) setCameraTarget ( Psource ) end, 2000, 1 ) function fipustitIgrok() spawnPlayer( source, 2280,2432,3.3 ) end addEvent('Vipustit', true) addEventHandler( 'Vipustit', root, fipustitIgrok ) --Client function check(Psource,timer) hours, minutes = getTime() timePrison = tonumber(timer)+minutes if (tonumber(timePrison)>60) then hours=hours+1 timePrison=timePrison-minutes end local prisTimer = setTimer(function() hoursN, timeN = getTime() if ( hoursN == hours and timeN == timePrison) then triggerServerEvent( 'Vipustit', Psource ) end end, 1000, 0) end addEvent( "checkTimer", true ) addEventHandler( "checkTimer", getRootElement(), check ) Link to comment
CocaColaBear Posted April 19, 2014 Share Posted April 19, 2014 Вот, набросал по-быстрому. Не проверял, писал тупо в блокноте. Может будут какие-нибудь ошибки. Но по сути, сервер лишь посылает клиенту, что он за решеткой и дальнейшая обработка происходит на клиенте. Вы только допишите, чтобы сохранялось время которое он отсидел и оставшееся, в случае перезахода на сервер. Проверить можно по команде /jail [Имя_игрока] [Время_в_секундах] -- Server function unJailPlayer() -- Освободить игрока с тюрьмы --setElementPosition(client, ...) outputChatBox("Вы освобождены из тюрьмы!", client) end addEvent("unJailPlayer", true) addEventHandler("unJailPlayer", root, unJailPlayer) addCommandHandler("jail", function(player, _, prisonerName, time) local prisoner = getPlayerByName(prisonerName) if(prisoner) then -- Посадить в тюрьму -- setElementPosition(prisoner, ...) triggerClientEvent(prisoner, "jailPlayer", prisoner, time or 60) else outputChatBox("Такого игрока нет!", player) end end ) -- Client local releaseTime function drawJailTime() local remainingTime = releaseTime - getTickCount() if(remainingTime > 0) then dxDrawText("Вам осталось "..(remainingTime/1000).." секунд", 500, 500) else releaseTime = nil triggerServerEvent("unjailPlayer", localPlayer) removeEventHandler("onClientRender", root, drawJailTime) end end function jailPlayer(jTime) -- jTime в секундах releaseTime = getTickCount() + jTime*1000 addEventHandler("onClientRender", root, drawJailTime) end addEvent("jailPlayer", true) addEventHandler("jailPlayer", root, jailPlayer) Link to comment
nikitafloy Posted April 19, 2014 Author Share Posted April 19, 2014 Вот, набросал по-быстрому. Не проверял, писал тупо в блокноте. Может будут какие-нибудь ошибки.Но по сути, сервер лишь посылает клиенту, что он за решеткой и дальнейшая обработка происходит на клиенте. Вы только допишите, чтобы сохранялось время которое он отсидел и оставшееся, в случае перезахода на сервер. Проверить можно по команде /jail [Имя_игрока] [Время_в_секундах] -- Server function unJailPlayer() -- Освободить игрока с тюрьмы --setElementPosition(client, ...) outputChatBox("Вы освобождены из тюрьмы!", client) end addEvent("unJailPlayer", true) addEventHandler("unJailPlayer", root, unJailPlayer) addCommandHandler("jail", function(player, _, prisonerName, time) local prisoner = getPlayerByName(prisonerName) if(prisoner) then -- Посадить в тюрьму -- setElementPosition(prisoner, ...) triggerClientEvent(prisoner, "jailPlayer", prisoner, time or 60) else outputChatBox("Такого игрока нет!", player) end end ) -- Client local releaseTime function drawJailTime() local remainingTime = releaseTime - getTickCount() if(remainingTime > 0) then dxDrawText("Вам осталось "..(remainingTime/1000).." секунд", 500, 500) else releaseTime = nil triggerServerEvent("unjailPlayer", localPlayer) removeEventHandler("onClientRender", root, drawJailTime) end end function jailPlayer(jTime) -- jTime в секундах releaseTime = getTickCount() + jTime*1000 addEventHandler("onClientRender", root, drawJailTime) end addEvent("jailPlayer", true) addEventHandler("jailPlayer", root, jailPlayer) Да, расставил аргументы как у Вас. Все сработало! Спасибо! 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