|
| 1 | +Keys = {["E"] = 38, ["L"] = 182, ["G"] = 47} |
| 2 | + |
| 3 | +payAmount = 0 |
| 4 | +Basket = {} |
| 5 | + |
| 6 | +--[[ Gets the ESX library ]]-- |
| 7 | +ESX = nil |
| 8 | +Citizen.CreateThread(function() |
| 9 | + while ESX == nil do |
| 10 | + Citizen.Wait(10) |
| 11 | + |
| 12 | + TriggerEvent("esx:getSharedObject", function(obj) |
| 13 | + ESX = obj |
| 14 | + end) |
| 15 | + end |
| 16 | +end) |
| 17 | + |
| 18 | +DrawText3D = function(x, y, z, text) |
| 19 | + local onScreen,x,y = World3dToScreen2d(x, y, z) |
| 20 | + local factor = #text / 370 |
| 21 | + |
| 22 | + if onScreen then |
| 23 | + SetTextScale(0.35, 0.35) |
| 24 | + SetTextFont(4) |
| 25 | + SetTextProportional(1) |
| 26 | + SetTextColour(255, 255, 255, 215) |
| 27 | + SetTextEntry("STRING") |
| 28 | + SetTextCentre(1) |
| 29 | + AddTextComponentString(text) |
| 30 | + DrawText(x,y) |
| 31 | + DrawRect(x,y + 0.0125, 0.015 + factor, 0.03, 41, 11, 41, 120) |
| 32 | + end |
| 33 | +end |
| 34 | + |
| 35 | +--[[ Requests specified model ]]-- |
| 36 | +_RequestModel = function(hash) |
| 37 | + if type(hash) == "string" then hash = GetHashKey(hash) end |
| 38 | + RequestModel(hash) |
| 39 | + while not HasModelLoaded(hash) do |
| 40 | + Wait(0) |
| 41 | + end |
| 42 | +end |
| 43 | + |
| 44 | +--[[ Deletes the cashiers ]]-- |
| 45 | +DeleteCashier = function() |
| 46 | + for i=1, #Config.Locations do |
| 47 | + local cashier = Config.Locations[i]["cashier"] |
| 48 | + if DoesEntityExist(cashier["entity"]) then |
| 49 | + DeletePed(cashier["entity"]) |
| 50 | + SetPedAsNoLongerNeeded(cashier["entity"]) |
| 51 | + end |
| 52 | + end |
| 53 | +end |
| 54 | + |
| 55 | +Citizen.CreateThread(function() |
| 56 | + local defaultHash = 416176080 |
| 57 | + for i=1, #Config.Locations do |
| 58 | + local cashier = Config.Locations[i]["cashier"] |
| 59 | + if cashier then |
| 60 | + cashier["hash"] = cashier["hash"] or defaultHash |
| 61 | + _RequestModel(cashier["hash"]) |
| 62 | + if not DoesEntityExist(cashier["entity"]) then |
| 63 | + cashier["entity"] = CreatePed(4, cashier["hash"], cashier["x"], cashier["y"], cashier["z"], cashier["h"]) |
| 64 | + SetEntityAsMissionEntity(cashier["entity"]) |
| 65 | + SetBlockingOfNonTemporaryEvents(cashier["entity"], true) |
| 66 | + FreezeEntityPosition(cashier["entity"], true) |
| 67 | + SetEntityInvincible(cashier["entity"], true) |
| 68 | + end |
| 69 | + SetModelAsNoLongerNeeded(cashier["hash"]) |
| 70 | + end |
| 71 | + end |
| 72 | +end) |
| 73 | + |
| 74 | +--[[ Creates cashiers and blips ]]-- |
| 75 | +Citizen.CreateThread(function() |
| 76 | + for i=1, #Config.Locations do |
| 77 | + local blip = Config.Locations[i]["blip"] |
| 78 | + |
| 79 | + if blip then |
| 80 | + if not DoesBlipExist(blip["id"]) then |
| 81 | + blip["id"] = AddBlipForCoord(blip["x"], blip["y"], blip["z"]) |
| 82 | + SetBlipSprite(blip["id"], 52) |
| 83 | + SetBlipDisplay(blip["id"], 4) |
| 84 | + SetBlipScale(blip["id"], 1.0) |
| 85 | + SetBlipColour(blip["id"], 25) |
| 86 | + SetBlipAsShortRange(blip["id"], true) |
| 87 | + |
| 88 | + BeginTextCommandSetBlipName("shopblip") |
| 89 | + AddTextEntry("shopblip", "Shop") |
| 90 | + EndTextCommandSetBlipName(blip["id"]) |
| 91 | + end |
| 92 | + end |
| 93 | + end |
| 94 | +end) |
| 95 | + |
| 96 | +--[[ Function to trigger pNotify event for easier use :) ]]-- |
| 97 | +pNotify = function(message, messageType, messageTimeout) |
| 98 | + TriggerEvent("pNotify:SendNotification", { |
| 99 | + text = message, |
| 100 | + type = messageType, |
| 101 | + queue = "shopcl", |
| 102 | + timeout = messageTimeout, |
| 103 | + layout = "topRight" |
| 104 | + }) |
| 105 | +end |
| 106 | + |
| 107 | +Marker = function(pos) |
| 108 | + DrawMarker(25, pos["x"], pos["y"], pos["z"] - 0.98, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.75, 0.75, 0.75, 200, 200, 200, 60, false, false, 2, false, nil, nil, false) |
| 109 | + DrawMarker(25, pos["x"], pos["y"], pos["z"] - 0.98, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.8, 0.8, 0.8, 200, 200, 200, 60, false, false, 2, false, nil, nil, false) |
| 110 | +end |
| 111 | + |
| 112 | +--[[ Deletes the peds when the resource stops ]]-- |
| 113 | +AddEventHandler('onResourceStop', function(resourceName) |
| 114 | + if resourceName == GetCurrentResourceName() then |
| 115 | + TriggerServerEvent('esx:clientLog', "[am-shops]: Deleting peds...") |
| 116 | + DeleteCashier() |
| 117 | + end |
| 118 | +end) |
0 commit comments