Hiroszekk
Wiek: 24 Na forum: 3312 dni Posty: 113
Nick w MP: Hiroszek
Piwa : 845
Mam taki oto b??d w db3:
ERROR: [ogrpg]/ogrpg-offices/selectjobs/s_selectjob.lua:118: attempt to get length of local 'result2' (a nil value)
Kod s_selectjob.lua:
-- Od ? wie ? anie tabeli
function getyesterday ()
local realTime = getRealTime ()
date = string . format ( "%04d-%02d-%02d" , realTime . year + 1900 , realTime . month + 1 , realTime . monthday - 1 )
return date
end
function getday ()
local realTime = getRealTime ()
date = string . format ( "%04d-%02d-%02d" , realTime . year + 1900 , realTime . month + 1 , realTime . monthday )
return date
end
function refreshing ( client )
local result = exports [ "ogrpg-db" ]: dbGet ( "SELECT * FROM ogrpg_office" )
if result and #result > 0 then
triggerClientEvent ( client , "jobs:refresh" , resourceRoot , result )
end
end
setTimer (function()
local result = exports [ 'ogrpg-db' ]: dbGet ( "SELECT * from ogrpg_jobs WHERE actived<NOW() - INTERVAL 1 DAY;" )
if result and #result > 0 then
for i , v in pairs ( result ) do
exports [ 'ogrpg-db' ]: dbSet ( "DELETE FROM ogrpg_jobs WHERE code=? and uid=?? and actived=?" , v . code , v . uid , v . actived )
exports [ 'ogrpg-db' ]: dbSet ( "UPDATE ogrpg_office set spaces=spaces-1 where code=?" , v . code )
outputDebugString ( "Wyczyszczono prace z nieaktywnych os?b!" )
end
end
--[[
local result = exports [ "ogrpg-db" ]: pobierzTabeleWynikow ( "SELECT * FROM ogrpg_jobs" )
if ( result ) then
for ii , vv in ipairs ( result ) do
--if vv [ "code" ] ~= "SAPD" then
if vv [ "actived" ] ~= getyesterday () and vv [ "actived" ] ~= getday () then
local query = string . format ( "SELECT * FROM ogrpg_office WHERE code=%q" , vv [ "code" ])
local result2 = exports [ "ogrpg-db" ]: pobierzWyniki ( query )
if ( result2 ) then
local query2 = string . format ( "UPDATE ogrpg_office SET spaces=%d WHERE code=%q" , result2 [ "spaces" ]- 1 , vv [ "code" ])
exports [ "ogrpg-db" ]: dbSet ( query2 )
-- local query2 = string . format ( "UPDATE ogrpg_office SET spaces=%d WHERE code=%q" , result2 [ "spaces" ]+ 1 , vv [ "code" ])
-- exports [ "ogrpg-db" ]: dbSet ( query2 )
local query3 = string . format ( "DELETE FROM ogrpg_jobs WHERE code=%q AND uid=%d AND actived=%q LIMIT 1;" , vv [ "code" ], vv [ "uid" ], vv [ "actived" ])
exports [ "ogrpg-db" ]: dbSet ( query3 )
outputDebugString ( "Wyczyszczono prace z nieaktywnych os?b!" )
end
end
-- end
end
end
if #result > 0 then
outputServerLog ( tostring ( result . actived ))
for key , resulte in pairs ( result ) do
outputServerLog ( "INFO 2:" .. tostring ( resulte . actived ))
if resulte . code ~= "SAPD" then
if resulte . actived ~= getyesterday and resulte . actived ~= getday then
local result2 = exports [ "ogrpg-db" ]: dbGet ( "SELECT * FROM ogrpg_office WHERE code=?" , resulte . code )
if #result2 > 0 then
exports [ "ogrpg-db" ]: dbSet ( "UPDATE ogrpg_office SET spaces=spaces+1 WHERE code=?" , result2 . spaces , result2 . code )
exports [ "ogrpg-db" ]: dbSet ( "DELETE FROM ogrpg_jobs WHERE code=? AND uid=? AND actived=?<NOW()" , resulte . code , resulte . uid , resulte . actived )
outputDebugString ( "Wyczyszczono prace!" )
outputServerLog ( "Wyczyszczono prace!" )
end
end
end
end
--]] -- end
end , 86400000 , 0 ) -- 86400000 24h 86400000
addEvent ( "jobs:download" , true )
addEventHandler ( "jobs:download" , resourceRoot , refreshing )
addEvent ( "jobs:hire" , true )
addEventHandler ( "jobs:hire" , resourceRoot , function( _ , name , code )
-- Pobieramy UID gracza
local uid = getElementData ( client , "player:uid" )
if not uid then return end
-- Sprawdzamy czy kto ? istnieje w jakie ? frakcji
local result = exports [ "ogrpg-db" ]: dbGet ( "SELECT * FROM ogrpg_jobs WHERE uid=?" , uid )
if #result > 0 then
outputChatBox ( "* Ju? jeste? w jakie? frakcji." , client , 255 , 0 , 0 )
return
end
-- Sprawdzamy czy praca ma jakie ? wolne miejsca
local result = exports [ "ogrpg-db" ]: dbGet ( "SELECT * FROM ogrpg_office WHERE code=?" , code )
if #result > 0 then
if result [ 1 ]. spaces == result [ 1 ]. maxspaces then
outputChatBox ( "* W tej pracy nie ma wolnych miejsc." , client , 255 , 0 , 0 )
return
end
end
-- Dodajemy gracza do frakcji i nast ? pnie od ? wie ? amy wniki dodajemym dodatkowe miejsca itp .
local query = exports [ "ogrpg-db" ]: dbSet ( "INSERT ogrpg_jobs (code,uid) VALUES (?,?)" , code , uid )
if query then
exports [ "ogrpg-db" ]: dbSet ( "UPDATE ogrpg_office SET spaces=spaces+1 WHERE code=?" , code )
outputChatBox ( "* Otrzymujesz sta?? prac? w " .. name .. "" , client )
refreshing ( client )
end
end )
addEvent ( "jobs:slow" , true )
addEventHandler ( "jobs:slow" , resourceRoot , function( _ , name , code )
-- Pobieramy UID gracza
local uid = getElementData ( client , "player:uid" )
if not uid then return end
-- Sprawdzamy czy kto ? istnieje w jakie ? frakcji
local result = exports [ "ogrpg-db" ]: dbGet ( "SELECT * FROM ogrpg_jobs WHERE uid=?" , uid )
if #result > 0 then
-- Sprawdzamy czy praca ma jakie ? wolne miejsca
local query = string . format ( "SELECT * FROM ogrpg_office WHERE code=%q" , result [ 1 ]. code )
local result2 = exports [ "ogrpg-db" ]: pobierzWyniki ( query )
if #result2 > 0 then
if result2 [ "spaces" ] == 0 then
outputChatBox ( "* Wyst?pi? b??d, poniewa? nie by?e? zatrudniony?" , client , 255 , 0 , 0 )
return
end
end
-- Usuwamy gracza z frakcji i nast ? pnie od ? wie ? amy wniki usuwamy miejsce itp .
local result3 = exports [ "ogrpg-db" ]: dbSet ( "DELETE FROM ogrpg_jobs WHERE code=? AND uid=?" , result [ 1 ]. code , uid )
if query then
exports [ "ogrpg-db" ]: dbSet ( "UPDATE ogrpg_office SET spaces=? WHERE code=?" , result2 [ "spaces" ]- 1 , result [ 1 ]. code )
outputChatBox ( "* Zwolni?e? si? ze sta?ej pracy w " .. name , client )
refreshing ( client )
end
else
outputChatBox ( "* Nie jeste? w ?adnej frakcji." , client , 255 , 0 , 0 )
end
end )
I kod kt?ry odpowiada za zwalnianie:
addEvent ( "jobs:slow" , true )
addEventHandler ( "jobs:slow" , resourceRoot , function( _ , name , code )
-- Pobieramy UID gracza
local uid = getElementData ( client , "player:uid" )
if not uid then return end
-- Sprawdzamy czy kto ? istnieje w jakie ? frakcji
local result = exports [ "ogrpg-db" ]: dbGet ( "SELECT * FROM ogrpg_jobs WHERE uid=?" , uid )
if #result > 0 then
-- Sprawdzamy czy praca ma jakie ? wolne miejsca
local query = string . format ( "SELECT * FROM ogrpg_office WHERE code=%q" , result [ 1 ]. code )
local result2 = exports [ "ogrpg-db" ]: pobierzWyniki ( query )
if #result2 > 0 then
if result2 [ "spaces" ] == 0 then
outputChatBox ( "* Wyst?pi? b??d, poniewa? nie by?e? zatrudniony?" , client , 255 , 0 , 0 )
return
end
end
-- Usuwamy gracza z frakcji i nast ? pnie od ? wie ? amy wniki usuwamy miejsce itp .
local result3 = exports [ "ogrpg-db" ]: dbSet ( "DELETE FROM ogrpg_jobs WHERE code=? AND uid=?" , result [ 1 ]. code , uid )
if query then
exports [ "ogrpg-db" ]: dbSet ( "UPDATE ogrpg_office SET spaces=? WHERE code=?" , result2 [ "spaces" ]- 1 , result [ 1 ]. code )
outputChatBox ( "* Zwolni?e? si? ze sta?ej pracy w " .. name , client )
refreshing ( client )
end
else
outputChatBox ( "* Nie jeste? w ?adnej frakcji." , client , 255 , 0 , 0 )
end
end )
Pomo?e kto? ? Daje piwko i repke