Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bizs_entrance = {} --сюда идут все созданные маркеры входов
- local bizs_buy = {} --сюда идут все созданные маркеры покупки предметов
- function interiorType(int, x1, y1, z1, rotation, x2, y2, z2)
- --[[ id - номер
- int - номер интерьера
- x1, y1, z1 - координаты выхода
- x2, y2, z2 - координаты метки покупки --]]
- local obj = {}
- obj.interior = int
- obj.rotation = rotation
- obj.exit = {["position"] = Vector3(x1, y1, z1)}
- obj.buy = {["position"] = Vector3(x2, y2, z2)}
- return obj
- end
- INT_TYPE = {}
- INT_TYPE[1] = interiorType(18, -30.96, -91.64, 1003.54, 0, -28.02, -89.96, 1002.54)
- INT_TYPE[2] = interiorType(6, -27.45, -58.28, 1003.54, 0, -23.43, -55.64, 1002.54)
- INT_TYPE[3] = interiorType(4, -27.36, -31.77, 1003.55, 0, -30.92, -29.02, 1002.55)
- local BLIPID = {{50}, {10, 14}}
- local BUYPICKUPID = 1274
- local MARKERENTER_COLOR = {247, 255, 47}
- local MARKERBUY_COLOR = {255, 0, 0}
- local START_DIMENSION = 400
- local SPAWN_LENGTH = 2
- local MARKER_Z_OFFSET = 0.6
- local SELL_KOEF = 0.8
- function s_mode_biz_spawnBlips()
- local result = dbPoll(dbQuery(mysql_connection, "SELECT * FROM `shops`"), -1)
- if not result then return false end
- for _, r in pairs(result) do
- local entrance
- if (r.owner) then
- entrance = Marker(r.x, r.y, r.z+MARKER_Z_OFFSET, "arrow", 1, unpack(MARKERENTER_COLOR))
- addEventHandler("onMarkerHit", entrance, s_mode_biz_onTeleportMarkerHit)
- else
- entrance = Pickup(r.x, r.y, r.z, 3, BUYPICKUPID, 1000)
- addEventHandler("onPickupUse", entrance, s_mode_biz_onBuyPickupUse)
- end
- local blip = Blip.createAttachedTo(entrance, BLIPID[r.type][r.iconType], 0.5, 0, 0, 0, 255, 0, 150)
- entrance:setData("blip", blip, false)
- entrance:setData("rotation", INT_TYPE[r.intType].rotation, false)
- entrance:setData("interior", INT_TYPE[r.intType].interior, false)
- entrance:setData("dimension", START_DIMENSION + r.id, false)
- local ang = math.rad(INT_TYPE[r.intType].rotation)+math.pi/2
- local n = INT_TYPE[r.intType].exit.position+Vector3(SPAWN_LENGTH*math.cos(ang), SPAWN_LENGTH*math.sin(ang), 0)
- entrance:setData("position", {n.x, n.y, n.z}, false) --Нельзя ставить vector в дату
- bizs_entrance[r.id] = entrance
- s_mode_biz_setInterior(r.id , r)
- end
- end
- function s_mode_biz_setInterior(id, bdresult)
- local iDim = START_DIMENSION + id
- local iInt = INT_TYPE[bdresult.intType].interior
- local mrk = Marker(INT_TYPE[bdresult.intType].exit.position+Vector3(0, 0, MARKER_Z_OFFSET), "arrow", 1, unpack(MARKERENTER_COLOR))
- mrk.dimension = iDim
- mrk.interior = iInt
- mrk:setData("rotation", bdresult.rotation, false)
- local ang = math.rad(bdresult.rotation)+math.pi/2
- local n = Vector3(bdresult.x, bdresult.y, bdresult.z)+Vector3(SPAWN_LENGTH*math.cos(ang), SPAWN_LENGTH*math.sin(ang), 0)
- mrk:setData("position", {n.x, n.y, n.z}, false)
- mrk:setData("interior", 0, false)
- mrk:setData("dimension", 0, false)
- addEventHandler("onMarkerHit", mrk, s_mode_biz_onTeleportMarkerHit)
- mrk = Marker(INT_TYPE[bdresult.intType].buy.position, "cylinder", 1, unpack(MARKERBUY_COLOR)) --видимый маркер
- mrk.dimension = iDim
- mrk.interior = iInt
- mrk = Marker(INT_TYPE[bdresult.intType].buy.position+Vector3(0, 0, 0.6), "cylinder", 1) --рабочий маркер
- mrk:setVisibleTo(root,false)
- mrk.dimension = iDim
- mrk.interior = iInt
- bizs_buy[id] = mrk --тот самый костыль с неработающим маркером, когда игрок в нем
- end
- function s_mode_biz_removeBlips()
- for _, r in pairs(bizs_entrance) do
- if isElement(r) then
- local blip = r:getData("blip", false)
- if isElement(blip) then
- blip:destroy()
- end
- r:destroy()
- end
- end
- bizs_entrance = {}
- end
- function s_mode_biz_updateBlips()
- s_mode_biz_removeBlips()
- s_mode_biz_spawnBlips()
- end
- function s_mode_biz_getPlayerBizs(player)
- local result = dbPoll(dbQuery(mysql_connection, "SELECT * FROM `shops` WHERE `owner`=?", player.name), -1)
- if not result[1] then return false end
- return result
- end
- function Player:s_mode_biz_getBizs() return s_mode_biz_getPlayerBizs(self) end
- function s_mode_biz_isPlayerOwner(player,bizid)
- local result = dbPoll(dbQuery(mysql_connection, "SELECT * FROM `shops` WHERE `owner`=? AND `id`=?", player.name,bizid), -1)[1]
- if not result then return false end
- return result
- end
- function Player:s_mode_biz_isOwner(...) return s_mode_biz_isPlayerOwner(self,...) end
- function s_mode_biz_getInventory(id)
- local result = dbPoll(dbQuery(mysql_connection, "SELECT `inv` FROM `shops` WHERE `id`=?", id), -1)[1]
- if not result then return false end
- return fromJSON(result.inv)
- end
- function s_mode_biz_findItem(bizid,itemid)
- local inv = s_mode_biz_getInventory(bizid)
- if not inv then return nil end
- for i, r in pairs(inv) do
- if (r[1]==itemid) and (r[2]>0) then
- return i
- end
- end
- return false
- end
- function s_mode_biz_setInventory(id, inv)
- return dbExec(mysql_connection, "UPDATE `shops` SET `inv`=? WHERE `id`=?", toJSON(inv), id)
- end
- function s_mode_biz_sellbiz()
- local biz = client:getData("tmp_currentsellbiz",false)
- local whom = client:getData("tmp_currentsellbizto",false)
- local price = client:getData("tmp_currentsellbizprice",false)
- if whom and (not isElement(whom)) then return outputChatBox("Игрок не найден", client, 0, 255, 0) end
- if not whom then --продажа гос-ву
- BankTransaction(client, "+", math.floor(biz.buyprice*SELL_KOEF), "Продажа бизнеса "..base64Decode(biz.name))
- dbExec(mysql_connection, "UPDATE `shops` SET `owner`=NULL WHERE `id`=?", biz.id)
- s_mode_biz_updateBlips()
- client:setData("tmp_currentsellbiz",nil,false)
- client:setData("tmp_currentsellbizto",nil,false)
- return outputChatBox("Вы продали бизнес "..base64Decode(biz.name), client, 0, 255, 0)
- else --продажа игроку
- if whom.money<price then return outputChatBox("У игрока не достаточно денег", client, 0, 255, 0) end
- local format1 = client.name.." предложил Вам купить бизнес "..base64Decode(biz.name).." за "..price.."$<br>Вы согласны?"
- whom:setData("tmp_currentsellbizfrom",client,false)
- triggerClientEvent(whom,"c_ynBox",resourceRoot,"s_mode_biz_buy_accept",nil,nil,format1) --fracpack/defboxes_c.lua
- end
- end
- addEvent("s_mode_biz_sellbiz",true)
- addEventHandler("s_mode_biz_sellbiz",root,s_mode_biz_sellbiz)
- function s_mode_biz_buy_accept()
- local from = client:getData("tmp_currentsellbizfrom",false)
- if not isElement(from) then return outputChatBox("Игрок не найден", client, 0, 255, 0) end
- local biz = from:getData("tmp_currentsellbiz",false)
- local price = from:getData("tmp_currentsellbizprice",false)
- BankTransaction(from, "+", price, "Продажа бизнеса "..base64Decode(biz.name))
- BankTransaction(client, "-", price, "Покупка бизнеса "..base64Decode(biz.name))
- dbExec(mysql_connection, "UPDATE `shops` SET `owner`=? WHERE `id`=?", client.name, biz.id)
- s_mode_biz_updateBlips()
- from:setData("tmp_currentsellbiz",nil,false)
- from:setData("tmp_currentsellbizto",nil,false)
- from:setData("tmp_currentsellbizprice",nil,false)
- client:setData("tmp_currentsellbizfrom",nil,false)
- end
- addEvent("s_mode_biz_buy_accept",true)
- addEventHandler("s_mode_biz_buy_accept",root,s_mode_biz_buy_accept)
- -------------------------------
- --Ивенты
- -------------------------------
- function s_mode_biz_onTeleportMarkerHit(element, dim)
- if not dim then return nil end
- element.interior = source:getData("interior", false)
- element.dimension = source:getData("dimension", false)
- element.position = Vector3(unpack(source:getData("position", false)))
- exports.fracpack:s_facingangle_set ( element, source:getData("rotation", false) )
- end
- -------------------------------
- --Команды
- -------------------------------
- function s_mode_biz_cmd_buybiz(player, cmd)
- local id
- for i, r in pairs(bizs_entrance) do
- if getElementType(r)=="pickup" then -- .type у пикапа возвращает тип пикапа -_-
- if player:isWithinColShape(r.colShape) then
- id = i
- break
- end
- end
- end
- if not id then return outputChatBox("Вы не около бизнеса", player, 255, 0, 0) end
- local result = dbPoll(dbQuery(mysql_connection, "SELECT `owner`, `buyprice`, `name` FROM `shops` WHERE `id`=?", id), -1)[1]
- if result.owner then return outputChatBox("Бизнес уже куплен", player, 255, 0, 0) end
- if player.money<result.buyprice then return outputChatBox("У Вас не достаточно денег", player, 255, 0, 0) end
- BankTransaction(player, "-", result.buyprice, "Покупка бизнеса "..base64Decode(result.name))
- dbExec(mysql_connection, "UPDATE `shops` SET `owner`=? WHERE `id`=?", player.name, id)
- s_mode_biz_updateBlips()
- return outputChatBox("Вы купили бизнес "..base64Decode(result.name), player, 0, 255, 0)
- end
- addCommandHandler("buybiz", s_mode_biz_cmd_buybiz)
- function s_mode_biz_cmd_sellbiz(player, cmd, id, playerId, price)
- --Проверка владельца, синтаксиса
- id = tonumber(id)
- playerId = tonumber(playerId)
- price = tonumber(price)
- if not id then return outputChatBox("Синтаксис: /"..cmd.." [id] (id игрока) (цена)", player, 255, 0, 0) end
- local biz = player:s_mode_biz_isOwner(id)
- if not biz then return outputChatBox("Вы не владелец данного бизнеса", player, 255, 0, 0) end
- --Проверка на продажу игроку
- local curpl
- if playerId then
- if not price then return outputChatBox("Синтаксис: /"..cmd.." [id] [id игрока] [цена]", player, 255, 0, 0) end
- price = math.floor(price) --дробей еще напихают
- if price<=0 then return outputChatBox("Цена указана неверно", player, 255, 0, 0) end --и отрицательных чисел
- curpl = g_Players[playerId]
- if not isElement(curpl) then return outputChatBox("Игрок не найден", player, 255, 0, 0) end
- if (curpl.position - player.position).length>5 then return outputChatBox("Игрок слишком далеко", player, 255, 0, 0) end
- player:setData("tmp_currentsellbizto",curpl,false)
- player:setData("tmp_currentsellbizprice",price,false)
- end
- --ARE YOU SURE?
- player:setData("tmp_currentsellbiz",biz,false)
- local format1 = curpl and "Вы действительно хотите продать бизнес "..base64Decode(biz.name).." игроку "..curpl.name.." за "..price.."$ ?" or "Вы действительно хотите продать бизнес государству?"
- triggerClientEvent(player,"c_ynBox",resourceRoot,"s_mode_biz_sellbiz",nil,nil,format1) --fracpack/defboxes_c.lua
- end
- addCommandHandler("sellbiz", s_mode_biz_cmd_sellbiz)
- local ITEM_BUYTYPE = {} --single(нельзя купить, если есть в инвентаре) replace(заменяет то, что есть в инвентаре) add(добавляет к тому, что есть в инвентаре)
- ITEM_BUYTYPE[1] = "single"
- ITEM_BUYTYPE[14] = "single"
- ITEM_BUYTYPE[15] = "single"
- local ITEM_TYPE = {} --item weapon(цветы, трость)
- ITEM_TYPE[1] = "item"
- ITEM_TYPE[14] = "weapon"
- ITEM_TYPE[15] = "weapon"
- local ITEM_SECONDPART = {} --вторая часть предмета (записывается в инвентарь)
- --делать в виде функций!
- ITEM_SECONDPART[1] = function() return 0 end
- ITEM_SECONDPART[14] = function() return 1 end
- ITEM_SECONDPART[15] = function() return 1 end
- local ITEM_NAME = {} --Не вижу смысла держать в БД
- ITEM_NAME[1] = "Канистра"
- ITEM_NAME[14] = "Цветы"
- ITEM_NAME[15] = "Трость"
- function s_mode_biz_cmd_buyitem(player, cmd, item)
- --Проверка синтаксиса, получение ID биза
- item = tonumber(item)
- if not item then return outputChatBox("Синтаксис: /"..cmd.." [item ID]", player, 255, 0, 0) end
- local bizid
- for i, r in pairs(bizs_buy) do
- if (player:isWithinColShape(r.colShape)) and (r.dimension==player.dimension) then
- bizid = i
- break
- end
- end
- if not bizid then return outputChatBox("Вы не около кассы", player, 255, 0, 0) end
- --Проверка наличия предмета на складе
- local inv = s_mode_biz_getInventory(bizid)
- local indexInInv = s_mode_biz_findItem(bizid,item)
- if indexInInv==nil then return outputChatBox("Ошибка #BIZ1", player, 255, 0, 0) end
- if indexInInv==false then return outputChatBox("Данного предмета нет на складе", player, 255, 0, 0) end
- --Проверка наличия предмета у игрока
- local amount
- if ITEM_TYPE[item]=="item" then
- for _, r in pairs(player:getData("inventory", false)) do
- if r[1]==item then
- amount = r[2]
- break
- end
- end
- if not amount then amount = 0 end
- elseif ITEM_TYPE[item]=="weapon" then
- local slot = getSlotFromWeapon(item)
- amount = (player:getWeapon(slot)==item) and player:getTotalAmmo(slot) or 0
- end
- if not amount then return outputChatBox("Ошибка #BIZ2", player, 255, 0, 0) end
- local secondPart
- if ITEM_BUYTYPE[item]=="single" then
- if amount>0 then return outputChatBox("Данный предмет у Вас уже есть", player, 255, 0, 0) end
- secondPart = ITEM_SECONDPART[item]()
- elseif ITEM_BUYTYPE[item]=="replace" then
- secondPart = ITEM_SECONDPART[item]()
- InvRemove(player, item)
- --тут что-то нужно придумать
- elseif ITEM_BUYTYPE[item]=="add" then
- secondPart = ITEM_SECONDPART[item]()
- else return outputChatBox("Ошибка #BIZ3", player, 255, 0, 0) end
- if not secondPart then return outputChatBox("Ошибка #BIZ4", player, 255, 0, 0) end
- --Списание денег
- if player.money<inv[indexInInv][3] then return outputChatBox("У Вас не достаточно денег", player, 255, 0, 0) end
- BankTransaction(player, "-", inv[indexInInv][3], "Покупка товара '"..ITEM_NAME[item].."'")
- --Обновление инвентаря магазина
- inv[indexInInv][2] = inv[indexInInv][2] - 1
- s_mode_biz_setInventory(bizid, inv)
- --Получение покупки
- if ITEM_TYPE[item]=="item" then
- InvAdd(player, item, secondPart)
- elseif ITEM_TYPE[item]=="weapon" then
- player:giveWeapon(item, 1)
- end
- dbExec(mysql_connection, "UPDATE `shops` SET `bank`=`bank`+? WHERE `id`=?", inv[indexInInv][3], bizid)
- return outputChatBox("Вы купили "..ITEM_NAME[item], player, 0, 255, 0)
- end
- addCommandHandler("buyitem", s_mode_biz_cmd_buyitem)
- function s_mode_biz_cmd_bizfee(player,cmd, id, price)
- --Проверка синтаксиса
- id, price = tonumber(id), tonumber(price)
- if not (id and price) then return outputChatBox("Синтаксис: /"..cmd.." [ID товара] [цена]", player, 255, 0,0) end
- price = math.floor(price)
- if price<=0 then return outputChatBox("Цена указана неверно", player, 255, 0, 0) end
- --Проверка на нахождение внутри бизнеса
- local bizid = player.dimension - START_DIMENSION
- if not bizs_entrance[bizid] then return outputChatBox("Вы не внутри бизнеса", player, 255, 0,0) end
- --Проверка на владельца
- local biz = player:s_mode_biz_isOwner(bizid)
- if not biz then return outputChatBox("Вы не владелец данного бизнеса", player, 255, 0, 0) end
- --Проверка существования товара
- if not ITEM_NAME[id] then return outputChatBox("Такого товара не существует", player, 255, 0,0) end
- local inv = s_mode_biz_getInventory(bizid)
- local indexInInv = s_mode_biz_findItem(bizid,id)
- iprint(indexInInv)
- if indexInInv==nil then return outputChatBox("Ошибка #BIZ5", player, 255, 0, 0) end
- --Установка новой цены
- if indexInInv==false then
- table.insert(inv,{id,0,price})
- else
- inv[indexInInv][3] = price
- end
- s_mode_biz_setInventory(bizid,inv)
- return outputChatBox("Товару '"..ITEM_NAME[id].."' установлена цена "..price.."$",player,0,255,0)
- end
- addCommandHandler("bizfee", s_mode_biz_cmd_bizfee)
- function s_mode_biz_cmd_bizbank(player, cmd, amount)
- --Проверка синтаксиса и денег
- amount = tonumber(amount)
- if not amount then return outputChatBox("Синтаксис: /"..cmd.." [сумма]", player, 255, 0,0) end
- amount = math.floor(amount)
- if player.money<amount then return outputChatBox("У Вас не достаточно денег", player, 255, 0,0) end
- if amount<=0 then return outputChatBox("Сумма денег для перевода указана неверно", player, 255, 0, 0) end
- --Проверка на нахождение внутри бизнеса
- local bizid = player.dimension - START_DIMENSION
- if not bizs_entrance[bizid] then return outputChatBox("Вы не внутри бизнеса", player, 255, 0,0) end
- --Проверка на владельца
- local biz = player:s_mode_biz_isOwner(bizid)
- if not biz then return outputChatBox("Вы не владелец данного бизнеса", player, 255, 0, 0) end
- BankTransaction(player, "-", amount, "Перевод денег на счет бизнеса")
- dbExec(mysql_connection, "UPDATE `shops` SET `bank`=`bank`+? WHERE `id`=?", amount, bizid)
- return outputChatBox("Вы перевели "..amount.."$ на счет бизнеса "..base64Decode(biz.name),player,0,255,0)
- end
- addCommandHandler("bizbank", s_mode_biz_cmd_bizbank)
- function s_mode_biz_cmd_bizwithdraw(player, cmd, amount)
- --Проверка синтаксиса
- amount = tonumber(amount)
- if not amount then return outputChatBox("Синтаксис: /"..cmd.." [сумма]", player, 255, 0,0) end
- amount = math.floor(amount)
- if amount<=0 then return outputChatBox("Сумма денег для снятия указана неверно", player, 255, 0, 0) end
- --Проверка на нахождение внутри бизнеса
- local bizid = player.dimension - START_DIMENSION
- if not bizs_entrance[bizid] then return outputChatBox("Вы не внутри бизнеса", player, 255, 0,0) end
- --Проверка на владельца
- local biz = player:s_mode_biz_isOwner(bizid)
- if not biz then return outputChatBox("Вы не владелец данного бизнеса", player, 255, 0, 0) end
- if biz.bank<amount then return outputChatBox("На счете бизнеса не достаточно денег", player, 255, 0,0) end
- BankTransaction(player, "+", amount, "Снятие денег со счета бизнеса")
- dbExec(mysql_connection, "UPDATE `shops` SET `bank`=`bank`-? WHERE `id`=?", amount, bizid)
- return outputChatBox("Вы сняли "..amount.."$ со счета бизнеса "..base64Decode(biz.name),player,0,255,0)
- end
- addCommandHandler("bizwithdraw", s_mode_biz_cmd_bizwithdraw)
- function s_mode_biz_cmd_bizlock(player,cmd,what,state) --протестить!!!!
- --Проверка синтаксиса
- local what_ = {["1"]="bizOpen",["0"]="deliveryOpen"}
- local state_ = {["1"]=1,["0"]=0}
- what, state = what_[what], state_[state]
- if not (what and state) then return outputChatBox("Синтаксис: /"..cmd.." [1/0 - бизнес/склад] [1/0 - закрыть/открыть]", player, 255, 0,0) end
- --Проверка на нахождение внутри бизнеса
- local bizid = player.dimension - START_DIMENSION
- if not bizs_entrance[bizid] then return outputChatBox("Вы не внутри бизнеса", player, 255, 0,0) end
- --Проверка на владельца
- local biz = player:s_mode_biz_isOwner(bizid)
- if not biz then return outputChatBox("Вы не владелец данного бизнеса", player, 255, 0, 0) end
- dbExec(mysql_connection, "UPDATE `shops` SET `"..what_.."`=? WHERE `id`=?", state, bizid)
- local what__ = {["bizOpen"]="бизнес",["deliveryOpen"]="склад"}
- local state__ = {[1]="открыли",[0]="закрыли"}
- outputChatBox("Вы "..what__[what].." "..state__[state].." "..base64Decode(biz.name), player, 0, 255, 0)
- end
- addCommandHandler("bizlock", s_mode_biz_cmd_bizlock)
Advertisement
Add Comment
Please, Sign In to add comment