U?ywanie dbGet w evencie onClientRender to jednak s?aby pomys?.
Nie mo?esz u?ywa? tej elementDaty przy zdobywaniu pieni?dzy? Wtedy w hudzie b?dzie to si? samoczynnie aktualizowa?o.
Z ka?d? wyp?at? gracza, zwi?kszasz elementDat? "player:bank" o dan? kwot?.
Albo u?ywasz domy?lnego systemu kasy itd. Zawsze mo?esz to wszystko 'zapakowa?' i korzysta? z tylko jednej elementDaty w ca?ym gamemodzie.
addEvent("bank:oddaj", true)
addEventHandler("bank:oddaj", root, function(i)
local pieniadze = getPlayerBankMoney(source)
local money = getPlayerOwnMoney(source)
i = string.gsub(i, "%a", "")
if not tonumber(i) then
outputChatBox("* Wprowadzona warto?? musi by? liczb?!", source, 255, 255, 255)
return
end
i = tonumber(i)
i = math.floor(i)
if i < 1 then
outputChatBox("* Wprowadzona warto?? musi by? wi?ksza ni? 0!", source, 255, 255, 255)
return
end
if i > pieniadze then
outputChatBox("* Nie posiadasz takiej sumy na swoim koncie!", source, 255, 255, 255)
return
end
givePlayerMoney(source, i)
local uid = getElementData(source, "player:sid")
exports["gl-db"]:dbGet("UPDATE gl_users SET bank_money=bank_money-? where id=?", i, uid)
outputChatBox("#008b00Pomy?lnie wyp?acono: "..i.." PLN z bankomatu.", source, 255, 255, 255, true)
triggerClientEvent(source, "wczytaj:bankOkno", source, getPlayerBankMoney(source))
end)
Zamiast 'tutaj_zmienna_gracza' wstaw w?asnie zmienn? gracza w danym kodzie.
Dla przyk?adu na kodzie, kt?ry wys?a?e?:
addEvent("bank:oddaj", true)
addEventHandler("bank:oddaj", root, function(i)
local pieniadze = getPlayerBankMoney(source)
local money = getPlayerOwnMoney(source)
i = string.gsub(i, "%a", "")
if not tonumber(i) then
outputChatBox("* Wprowadzona warto?? musi by? liczb?!", source, 255, 255, 255)
return
end
i = tonumber(i)
i = math.floor(i)
if i < 1 then
outputChatBox("* Wprowadzona warto?? musi by? wi?ksza ni? 0!", source, 255, 255, 255)
return
end
if i > pieniadze then
outputChatBox("* Nie posiadasz takiej sumy na swoim koncie!", source, 255, 255, 255)
return
end
givePlayerMoney(source, i)
local uid = getElementData(source, "player:sid")
exports["gl-db"]:dbGet("UPDATE gl_users SET bank_money=bank_money-? where id=?", i, uid)
outputChatBox("#008b00Pomy?lnie wyp?acono: "..i.." PLN z bankomatu.", source, 255, 255, 255, true)
triggerClientEvent(source, "wczytaj:bankOkno", source, getPlayerBankMoney(source))
setElementData(source, "player:bank", getPlayerBankMoney(source))
end)
function getPlayerBankMoney(player)
local uid = getElementData(player, "player:sid")
local result=exports["gl-db"]:dbGet("SELECT * from gl_users where id=?", uid)
if result and #result > 0 then
return result[1].bank_money
end
return 0
end
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach