· 9 years ago · Oct 11, 2016, 09:18 PM
1con = dbConnect( "sqlite", "inv.db" )
2dbExec(con, "CREATE TABLE IF NOT EXISTS 'inventory' (gracz TEXT, SLOT1 TEXT, SLOT2 TEXT, SLOT3 TEXT, SLOT4 TEXT, SLOT5 TEXT, SLOT6 TEXT, SLOT7 TEXT, SLOT8 TEXT, SLOT9 TEXT, SLOT10 TEXT, SLOT11 TEXT, SLOT12 TEXT)")
3
4
5
6--result = dbExec(con,"INSERT INTO 'inventory' (gracz, SLOT1,SLOT2,SLOT3,SLOT4,SLOT5,SLOT6,SLOT7,SLOT8,SLOT9,SLOT10,SLOT11,SLOT12) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)","Sanlock", "", "", "", "", "", "", "", "", "", "", "", "")
7inventoryfrom = {}
8
9addEventHandler("onPlayerSpawn",root,function()
10 que = dbQuery(con,"SELECT * FROM inventory WHERE gracz = ?", getPlayerName(source))
11 local result = dbPoll(que, -1)
12 outputDebugString("[System Inventory] Staruje polaczenie z baza danych dla gracza "..getPlayerName(source))
13 if que and #result > 0 then
14 outputDebugString("[System Inventory] Pobiera ekwipunek gracza "..getPlayerName(source))
15 for k,v in pairs(result) do
16 outputDebugString("[System Inventory] Dal ekwipunek graczowi "..getPlayerName(source))
17 triggerClientEvent(source, "giveInv",source,v.SLOT1,v.SLOT2,v.SLOT3,v.SLOT4,v.SLOT5,v.SLOT6,v.SLOT7,v.SLOT8,v.SLOT9,v.SLOT10,v.SLOT11,v.SLOT12)
18 end
19 else
20 outputDebugString("[System Inventory] Tworzenie ekwipunku dla gracza "..getPlayerName(source))
21 result = dbExec(con,"INSERT INTO 'inventory' (gracz, SLOT1,SLOT2,SLOT3,SLOT4,SLOT5,SLOT6,SLOT7,SLOT8,SLOT9,SLOT10,SLOT11,SLOT12) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",getPlayerName(source), "PieniÄ…dze", "", "", "", "", "", "", "", "", "", "", "")
22 if result then
23 outputDebugString("[System Inventory] "..getPlayerName(source).." otrzymał ekwipunek startowy!")
24 else
25 outputDebugString("[System Inventory] "..getPlayerName(source).." otrzymał error ekwipunku!")
26 end
27 end
28end)
29
30addCommandHandler("inv",function(plr,cmd,slot, ...)
31 if tonumber(slot) then
32 local info = table.concat({...}, " ")
33 dbQuery(con, "UPDATE inventory SET ?? = ? WHERE gracz = ?", string.upper(string.format("slot%s", tostring(slot))), info, getPlayerName(plr))
34 que = dbQuery(con,"SELECT * FROM inventory WHERE gracz = ?", getPlayerName(plr))
35 local result = dbPoll(que, -1)
36 outputChatBox(info.." "..slot)
37 for k,v in pairs(result) do
38 triggerClientEvent(plr, "giveInv",plr,v.SLOT1,v.SLOT2,v.SLOT3,v.SLOT4,v.SLOT5,v.SLOT6,v.SLOT7,v.SLOT8,v.SLOT9,v.SLOT10,v.SLOT11,v.SLOT12)
39 end
40 end
41end)
42
43addEvent("pobierzSloty",true)
44function pobierzSLOTY(plr)
45 que = dbQuery(con,"SELECT * FROM inventory WHERE gracz = ?", getPlayerName(plr))
46 local result = dbPoll(que, -1)
47 for k,v in pairs(result) do
48 triggerClientEvent(plr, "giveInv",plr,v.SLOT1,v.SLOT2,v.SLOT3,v.SLOT4,v.SLOT5,v.SLOT6,v.SLOT7,v.SLOT8,v.SLOT9,v.SLOT10,v.SLOT11,v.SLOT12)
49 end
50
51end
52addEventHandler("pobierzSloty",root,pobierzSLOTY)