Guest User

Untitled

a guest
Jul 15th, 2017
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.95 KB | None | 0 0
  1. --[[
  2. @author Lukasz Biegaj <[email protected]>
  3. @copyright 2011-2013 Lukasz Biegaj <[email protected]>
  4. @license Dual GPLv2/MIT
  5. ]]--
  6.  
  7.  
  8. -- wczytujemy biznesy
  9.  
  10. local budynki={}
  11.  
  12.  
  13.  
  14. function onType1Hit(el)
  15.   if (getElementType(el)~="player") then return end
  16.   local container = getElementData(source, "type:container_id")
  17.   triggerClientEvent("onMarkerType1Enter", getRootElement(), el, container)
  18. end
  19. function onType1Leave(el)
  20.   if (getElementType(el)~="player") then return end
  21.   triggerClientEvent("onMarkerType1Leave", getRootElement(), el)
  22. end
  23.  
  24.  
  25.  
  26. local function zaladujOferte(npc)
  27.     local cid=getElementData(npc,"budynek:container_id")
  28. --    local query=string.format("SELECT cc.itemid,cc.subtype,cc.count,bo.sellprice FROM lss_container_contents cc JOIN lss_budynki_oferta bo ON bo.container_id=cc.container_id AND bo.itemid=cc.itemid AND IFNULL(bo.subtype,0)=IFNULL(cc.subtype,0) WHERE cc.container_id=%d", cid)
  29.     local query=string.format("SELECT cc.itemid,i.name,cc.subtype,cc.count,bo.sellprice FROM lss_container_contents cc JOIN lss_budynki_oferta bo ON bo.container_id=cc.container_id AND bo.itemid=cc.itemid AND IFNULL(bo.subtype,0)=IFNULL(cc.subtype,0) JOIN lss_items i ON cc.itemid=i.id WHERE cc.container_id=%d", cid)
  30.     local oferta=exports.DB:pobierzTabeleWynikow(query)
  31.     setElementData(npc,"budynek:oferta", oferta)
  32. end
  33.  
  34. local function zaladujNPC(bid)
  35.     local query=string.format("select * from lss_budynki_npc WHERE budynek_id=%d", bid)
  36.     local dane=exports.DB:pobierzTabeleWynikow(query)
  37.     if (not dane) then return nil end
  38.     local npcs={}
  39.     for i,v in ipairs(dane) do
  40.     local npc=createPed(tonumber(v.skin), tonumber(v.x), tonumber(v.y),tonumber(v.z),tonumber(v.a), false)
  41.     setElementInterior(npc, tonumber(v.interior))
  42.     setElementDimension(npc, tonumber(v.dimension))
  43.     setElementData(npc,"npc",true)
  44.     setElementData(npc, "name", "Sprzedawca")
  45.     setElementFrozen(npc, true)
  46.         -- strefa
  47.         local rrz=math.rad(tonumber(v.a)+180)
  48.         local x2= tonumber(v.x) - (2 * math.sin(-rrz))
  49.         local y2= tonumber(v.y) - (2 * math.cos(-rrz))
  50.         local strefa=createColSphere(x2,y2,tonumber(v.z),2)
  51.     setElementDimension(strefa, tonumber(v.dimension))
  52.     setElementInterior(strefa, tonumber(v.interior))
  53.     setElementParent(strefa, npc)
  54.     -- dane oferty
  55.    
  56.     setElementData(npc,"budynek:container_id", tonumber(v.container_id))
  57.     zaladujOferte(npc)
  58.    
  59.     table.insert(npcs,npc)
  60.     end
  61.     return npcs
  62. end
  63.  
  64. local function wlascicieleBudynku(bid,fid)
  65.   local wlasciciele={}
  66.   local wlasciciele_id={}
  67.   if not tonumber(bid) then return wlasciciele_id,wlasciciele end
  68.   -- w przypadku gdy wlascicielem budynku jest frakcja, odczytujemy jej nazwe i spis czlonkow z uprawnieniem permission_door
  69.   if (fid) then
  70.     -- odczytujemy nazwe frakcji
  71.     local query=string.format("SELECT name FROM lss_faction WHERE id=%d", fid)
  72.     local dane=exports.DB:pobierzWyniki(query)
  73.     table.insert(wlasciciele, dane.name)
  74.     -- odczytujemy liste czlonkow z odpowiednimi uprawnieniami
  75.     query=string.format("select cf.character_id from lss_character_factions cf JOIN lss_faction_ranks fr ON cf.faction_id=fr.faction_id AND cf.rank=fr.rank_id AND fr.perm_doors=1 WHERE cf.faction_id=%d", fid)
  76. --  outputConsole(query)
  77.     dane=exports.DB:pobierzTabeleWynikow(query)
  78.     for i,v in ipairs(dane) do
  79.       table.insert(wlasciciele_id,v.character_id)
  80.     end
  81.  
  82.   else
  83.   -- w przypadku gdy wlascicielem budynku nie jest zadna frakcja, dokonujemy odczytu z tabeli lss_budynki_owners
  84.     local query=string.format("select bo.character_id,concat(c.imie,' ',c.nazwisko) wlasciciel from lss_budynki_owners bo JOIN lss_characters c ON c.id=bo.character_id where bo.budynek_id=%d", bid)
  85.     local wyniki=exports.DB:pobierzTabeleWynikow(query)
  86.     for i,v in ipairs(wyniki) do
  87.         table.insert(wlasciciele_id,v.character_id)
  88.         table.insert(wlasciciele,v.wlasciciel)
  89.     end
  90.   end
  91.   return wlasciciele_id, wlasciciele
  92. end
  93.  
  94. local function cleanupBudynek(id)
  95.     if (not budynki[id]) then return false end
  96.     destroyElement(budynki[id].text3d)
  97.     destroyElement(budynki[id].marker)
  98.     destroyElement(budynki[id].blip)
  99.     destroyElement(budynki[id].markerwyjsciowy)
  100.     for i,v in ipairs(budynki[id].npcs) do
  101.     for i2,v2 in ipairs(getElementChildren(v)) do
  102.         destroyElement(v2)
  103.     end
  104.     destroyElement(v) -- usuwamy npc
  105.     end
  106.     budynki[id]=nil
  107.     return true
  108. end
  109.  
  110. local function utworzBudynek(v)
  111.     local id=tonumber(v.id)
  112.     if (budynki[id]) then
  113.         cleanupBudynek(id)
  114.     end
  115.     v.id=tonumber(v.id)
  116.     v.paidTo_days=tonumber(v.paidTo_days)
  117.     if (v.paidTo_days<0) then
  118.       v.zamkniety=1
  119.       v.descr2="Lokal nieczynny."
  120.     end
  121.     v.entryCost=tonumber(v.entryCost)
  122.    
  123.     if (type(v.linkedContainer)=="userdata") then -- null
  124.         v.linkedContainer=nil
  125.         v.entryCost=0   -- nie zbieramy oplat jesli nie ma przypisanego sejfu
  126.     else
  127.         v.linkedContainer=tonumber(v.linkedContainer)
  128.     end
  129. --  outputDebugString("Entry cost: " .. v.entryCost)
  130.    
  131.     v.drzwi=split(v.drzwi,",")
  132.     v.drzwi[1], v.drzwi[2], v.drzwi[3] = tonumber(v.drzwi[1]), tonumber(v.drzwi[2]), tonumber(v.drzwi[3])
  133.     v.punkt_wyjscia=split(v.punkt_wyjscia,",")
  134.     v.punkt_wyjscia[1], v.punkt_wyjscia[2], v.punkt_wyjscia[3], v.punkt_wyjscia[4] = tonumber(v.punkt_wyjscia[1]), tonumber(v.punkt_wyjscia[2]), tonumber(v.punkt_wyjscia[3]), tonumber(v.punkt_wyjscia[4])
  135.     v.i_entrance=split(v.i_entrance,",")
  136.     v.i_exit=split(v.i_exit,",")
  137.     v.i_entrance[1], v.i_entrance[2], v.i_entrance[3], v.i_entrance[4] = tonumber(v.i_entrance[1]), tonumber(v.i_entrance[2]), tonumber(v.i_entrance[3]), tonumber(v.i_entrance[4])
  138.     v.i_i,v.i_d=tonumber(v.i_i), tonumber(v.i_d) or (1000+v.id)
  139.     v.type = tonumber(v.type)
  140.     v.owning_faction=tonumber(v.owning_faction)
  141.  
  142.     budynki[id]=v
  143.  
  144.     if not v.descr2 or type(v.descr2)~="string" then v.descr2="" end
  145.     v.descr2_orig=v.descr2
  146.     v.wlasciciele,wlasciciele=wlascicieleBudynku(v.id,v.owning_faction)
  147.     if (#wlasciciele==1) then
  148.       v.descr2=v.descr2 .. "\n\nWłaściciel: " .. wlasciciele[1]
  149.     elseif (#wlasciciele>1) then
  150.       v.descr2=v.descr2 .. "\n\nWłaściciele: " .. table.concat(wlasciciele,", ")
  151.     end
  152.     v.descr2=v.descr2.."\n\nID budynku: " .. id
  153. --  outputDebugString(type(v.wlasciciele))
  154.  
  155.     budynki[id].text3d=createElement("text")
  156.  
  157.  
  158.    
  159.     setElementPosition(budynki[id].text3d, v.drzwi[1], v.drzwi[2], v.drzwi[3]+0.5)
  160.  
  161.     setElementData(budynki[id].text3d, "text", v.descr)
  162.  
  163.     budynki[id].marker=createMarker(v.drzwi[1], v.drzwi[2], v.drzwi[3]+0.51, "arrow", 1, 255,0,0,100)
  164.     budynki[id].blip=createBlip(v.drzwi[1], v.drzwi[2], v.drzwi[3], 0, 1, 5,105,255,155, -1000, 200)
  165.     budynki[id].cs=createColSphere(v.drzwi[1], v.drzwi[2], v.drzwi[3], 1)
  166. --  outputDebugString(string.format("%d %f %f %f", v.id, v.drzwi[1], v.drzwi[2], v.drzwi[3]))
  167.     setElementData(budynki[id].cs,"budynek",v)
  168.     setElementData(budynki[id].cs,"type",tonumber(v.type))
  169.  
  170.     -- marker wyjsciowy
  171.     budynki[id].markerwyjsciowy=createMarker(tonumber(v.i_exit[1]), tonumber(v.i_exit[2]), tonumber(v.i_exit[3])+0.51, "arrow", 1, 255,0,0,100)
  172.     setElementInterior(budynki[id].markerwyjsciowy, v.i_i)
  173.     setElementDimension(budynki[id].markerwyjsciowy, v.i_d)
  174.     setElementData(budynki[id].markerwyjsciowy, "budynek:tpto", v.punkt_wyjscia)
  175.     setElementData(budynki[id].markerwyjsciowy,"type",tonumber(v.type))
  176.  
  177.    
  178.    
  179.  
  180.    
  181.     -- funkcje dodatkowe
  182.     if v.type == 1 then --sklep odziezowy
  183.         local int = v.i_i
  184.        
  185.         if int == 3 then
  186.             xyz = {207.16,-129.73,1002.51} --int 79
  187.         elseif int == 1 then
  188.             xyz = {203.81,-44.16,1000.80} --int 84
  189.         elseif int == 18 then
  190.             xyz = {161.35,-84.21,1000.80}  --int 86
  191.         elseif int == 14 then
  192.             xyz = {204.42,-160.22,999.52}  --int 87
  193.         elseif int == 2 then
  194.             if v.i_entrance[1] == 466.77 then
  195.                 xyz = {467.05,-1128.92,2002.51}
  196.             elseif v.i_entrance[1]== 489.42 then
  197.                 xyz = {489.43,-1547.55,2100.80}  --int
  198.             elseif v.i_entrance[1]== 1734.05 then
  199.                 xyz = {1716.63,-1669.58,2000.21}
  200.             end
  201.         end
  202.         local x,y,z = unpack(xyz)
  203.        
  204.         budynki[id].type1marker = createMarker(x,y,z,"cylinder",1.2,255,255,0,100)
  205.         setElementInterior(budynki[id].type1marker, v.i_i)
  206.         setElementDimension(budynki[id].type1marker, v.i_d)
  207.         setElementData(budynki[id].type1marker,"type:container_id", tonumber(v.linkedContainer))
  208.         addEventHandler("onMarkerHit", budynki[id].type1marker, onType1Hit)
  209.         addEventHandler("onMarkerLeave", budynki[id].type1marker, onType1Leave)
  210.     end
  211.    
  212.     budynki[id].npcs=zaladujNPC(id)
  213. end
  214.  
  215. function zaladujBudynek(id)
  216.     local query=string.format("SELECT b.id,b.descr,b.descr2,b.drzwi,b.linkedContainer,b.owning_faction,b.entryCost,b.punkt_wyjscia,i.interior i_i,i.dimension i_d,i.entrance i_entrance,i.exit i_exit,b.zamkniety,b.koszt,b.updated,b.paidTo,IFNULL(datediff(b.paidTo, NOW()),-1) paidTo_days,b.type,b.linkedContainer FROM lss_budynki b JOIN lss_interiory i ON i.id=b.interiorid WhERE b.id=%d LIMIT 1", id)
  217.     local wyniki=exports.DB:pobierzWyniki(query)
  218.     utworzBudynek(wyniki)
  219. end
  220.  
  221. do
  222.   local query="SELECT b.id,b.descr,b.descr2,b.drzwi,b.entryCost,b.owning_faction,b.linkedContainer,b.punkt_wyjscia,i.interior i_i,i.dimension i_d,i.entrance i_entrance,i.exit i_exit,b.zamkniety,b.koszt,b.updated,b.paidTo,IFNULL(datediff(b.paidTo, NOW()),-1) paidTo_days,b.type,b.linkedContainer FROM lss_budynki b JOIN lss_interiory i ON i.id=b.interiorid"
  223.   local wyniki=exports.DB:pobierzTabeleWynikow(query)
  224.   for i,v in ipairs(wyniki) do
  225.     utworzBudynek(v)
  226.   end
  227. end
  228.  
  229. --[[
  230. addEventHandler("onMarkerHit", resourceRoot, function(el,md)
  231.   if (getElementType(el)~="player") then return end
  232.   if (not md) then return end
  233.   triggerEvent("broadcastCaptionedEvent", el, getPlayerName(el) .. " łapie za klamkę i próbuje otworzyć drzwi.", 5, 15,true)
  234.   outputChatBox("(( biznesy do kupienia - w przygotowaniu. ))", el)
  235. end)
  236. ]]--
  237.  
  238. -- triggerServerEvent("onPlayerRequestEntrance", resourceRoot, localPlayer, biznes)
  239. addEvent("onPlayerRequestEntrance", true)
  240. addEventHandler("onPlayerRequestEntrance", resourceRoot, function(plr, budynek)
  241.   if (budynek.entryCost>0) then
  242.     if (getPlayerMoney(plr)<budynek.entryCost) then
  243.     return  -- nie powinno sie wydarzyc bo sprawdzanie jest zduplikowane po stronie klienta
  244.     end
  245.     if (exports["lss-pojemniki"]:insertItemToContainer(budynek.linkedContainer, -1, budynek.entryCost)) then
  246.         takePlayerMoney(plr, budynek.entryCost)
  247.     else
  248.     outputDebugString("Nie udalo sie pobrac oplaty za wstep do biznesu " .. budynek.id)
  249.     end
  250.    
  251.   end
  252.   setElementPosition(plr, budynek.i_entrance[1]+math.random(-5,5)/10, budynek.i_entrance[2]+math.random(-5,5)/10, budynek.i_entrance[3])
  253.   setElementInterior(plr, budynek.i_i)
  254.   setElementDimension(plr, budynek.i_d or 1000+budynek.id)
  255.   setPedRotation(plr, budynek.i_entrance[4])
  256.   if (budynek.radio) and (budynek.radio~="") then triggerClientEvent("startBiznesSound", getRootElement(), plr, budynek.radio) end
  257.  
  258.   if tonumber(budynek.type) == 1 then
  259.     setElementData(plr, "type1oldskin", false)
  260.   end
  261.  
  262. end)
  263.  
  264.  
  265. addEventHandler("onMarkerHit", resourceRoot, function(el,md)
  266.   if (getElementType(el)~="player") then return end
  267.  
  268.   if (not md) then return end
  269.  
  270.   local tpto=getElementData(source,"budynek:tpto")
  271.   if (tpto) then
  272.     setElementPosition(el, tpto[1]+math.random(-5,5)/10, tpto[2]+math.random(-5,5)/10, tpto[3])
  273.     setPedRotation(el, tpto[4])
  274.     setElementInterior(el, 0)
  275.     setElementDimension(el, 0)
  276.     if getElementData(source,"type") == 1 then
  277.         triggerClientEvent("stopBiznesSound", getRootElement(), el, getElementData(source,"type"))
  278.         if getElementData(el, "type1oldskin") then
  279.             setElementModel(el, getElementData(el, "type1oldskin"))
  280.         end
  281.     end
  282.  
  283.   end
  284. end)
  285.  
  286.  
  287.  
  288. local function odswiezOferte()
  289.   local sprzedawcy=getElementsByType("ped",resourceRoot)
  290.   outputDebugString("Sprzedawcow: " .. #sprzedawcy)
  291.   for i,v in ipairs(sprzedawcy) do
  292.     zaladujOferte(v)
  293.   end
  294.  
  295. end
  296.  
  297. setTimer(odswiezOferte, 60000*2, 0)
  298.  
  299.  
  300.  
  301.  
  302. addEvent("setElementModelShop", true)
  303. addEventHandler("setElementModelShop", getRootElement(), function(plr,model,przym,pay,pojemnik,premium)
  304.     if przym then
  305.         triggerEvent("broadcastCaptionedEvent", plr, getPlayerName(plr).." przymierza ubranie", 3, 10, true)
  306.         if not getElementData(plr, "type1oldskin") then
  307.             setElementData(plr, "type1oldskin", getElementModel(plr))
  308.         end
  309.     end
  310.     if pay then
  311.         if getPlayerMoney(plr)-pay < 0 then outputChatBox("Sprzedawca mówi: niestety, nie stać Pana na to ubranie!", plr) return end
  312.         takePlayerMoney(plr,pay)
  313.         triggerEvent("broadcastCaptionedEvent", plr, getPlayerName(plr).." zakupuje ubranie", 3, 10, true)
  314.         setElementData(plr, "type1oldskin", false)
  315.         local c = getElementData(plr, "character")
  316.         if not premium then
  317.             local query=string.format("UPDATE lss_characters SET skin=%d, premiumskin = NULL WHERE id=%d LIMIT 1", model, c.id)
  318.             exports.DB2:zapytanie(query)
  319.         else
  320.             local query=string.format("UPDATE lss_characters SET premiumskin=%d WHERE id=%d LIMIT 1", model, c.id)
  321.             exports.DB2:zapytanie(query)
  322.         end
  323.         exports["lss-pojemniki"]:insertItemToContainer(pojemnik, -1, math.ceil(tonumber(pay)/2),0,"Gotówka")
  324.     end
  325.    
  326.     setElementModel(plr,model)
  327. end)
Advertisement
Add Comment
Please, Sign In to add comment