-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(esx_shops): ✨ Add support for multiple paymenth methods, revert … #26
Open
Arctos2win
wants to merge
3
commits into
esx-framework:dev
Choose a base branch
from
Arctos2win:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,99 @@ | ||
local hasAlreadyEnteredMarker, lastZone | ||
local currentAction, currentActionMsg, currentActionData = nil, nil, {} | ||
|
||
local currentZone, TextUI, inMenu | ||
local function openShopMenu(zone) | ||
local elements = { | ||
{unselectable = true, icon = "fas fa-shopping-basket", title = TranslateCap('shop') } | ||
} | ||
|
||
for i=1, #Config.Zones[zone].Items, 1 do | ||
local item = Config.Zones[zone].Items[i] | ||
if not Config.Zones[zone] then return end | ||
local elements = {} | ||
for i, item in ipairs(Config.Zones[zone].Items) do | ||
elements[i] = { | ||
label = ('%s - <span style="color:green;">%s</span>'):format(item.label, | ||
TranslateCap('shop_item', ESX.Math.GroupDigits(item.price))), | ||
name = item.name, | ||
value = 1, | ||
type = "slider", | ||
min = 1, | ||
max = 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be a good idea to add |
||
} | ||
end | ||
|
||
inMenu = true | ||
ESX.UI.Menu.Open("default", GetCurrentResourceName(), "SHOP_MENU", { | ||
title = TranslateCap('shop'), | ||
align = Config.MenuAlign, | ||
elements = elements | ||
}, function(data, menu) | ||
if not currentZone then | ||
return menu.close() | ||
end | ||
|
||
TriggerServerEvent("esx_shops:buyItem", data.current.name, data.current.value, currentZone) | ||
end, function(data, menu) | ||
inMenu = false | ||
menu.close() | ||
end) | ||
end | ||
|
||
elements[#elements+1] = { | ||
icon = "fas fa-shopping-basket", | ||
title = ('%s - <span style="color:green;">%s</span>'):format(item.label, TranslateCap('shop_item', ESX.Math.GroupDigits(item.price))), | ||
itemLabel = item.label, | ||
item = item.name, | ||
price = item.price | ||
} | ||
end | ||
function AddShopBlip(pos, settings) | ||
if not settings.ShowBlip then return end | ||
|
||
ESX.OpenContext("right", elements, function(menu,element) | ||
local elements2 = { | ||
{unselectable = true, icon = "fas fa-shopping-basket", title = element.title}, | ||
{icon = "fas fa-shopping-basket", title = TranslateCap('amount'), input = true, inputType = "number", inputPlaceholder = TranslateCap('amount_placeholder'), inputMin = 1, inputMax = 25}, | ||
{icon = "fas fa-check-double", title = TranslateCap('confirm'), val = "confirm"} | ||
} | ||
local blip = AddBlipForCoord(pos) | ||
|
||
ESX.OpenContext("right", elements2, function(menu2,element2) | ||
local amount = menu2.eles[2].inputValue | ||
ESX.CloseContext() | ||
TriggerServerEvent('esx_shops:buyItem', element.item, amount, zone) | ||
end, function(menu) | ||
currentAction = 'shop_menu' | ||
currentActionMsg = TranslateCap('press_menu', ESX.GetInteractKey()) | ||
currentActionData = {zone = zone} | ||
end) | ||
end, function(menu) | ||
currentAction = 'shop_menu' | ||
currentActionMsg = TranslateCap('press_menu', ESX.GetInteractKey()) | ||
currentActionData = {zone = zone} | ||
end) | ||
end | ||
SetBlipSprite(blip, settings.Type) | ||
SetBlipScale(blip, settings.Size) | ||
SetBlipColour(blip, settings.Color) | ||
SetBlipAsShortRange(blip, true) | ||
|
||
local function hasEnteredMarker(zone) | ||
currentAction = 'shop_menu' | ||
currentActionMsg = TranslateCap('press_menu', ESX.GetInteractKey()) | ||
currentActionData = {zone = zone} | ||
BeginTextCommandSetBlipName("STRING") | ||
AddTextComponentSubstringPlayerName(TranslateCap('shops')) | ||
EndTextCommandSetBlipName(blip) | ||
end | ||
|
||
local function hasExitedMarker(zone) | ||
currentAction = nil | ||
ESX.CloseContext() | ||
function createShopPoint(pos, zone, ShowMarker) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be consistent with variable naming. Why is ShowMarker capitalized? |
||
ESX.Point:new({ | ||
coords = pos, | ||
distance = Config.DrawDistance, | ||
enter = function() | ||
end, | ||
leave = function() | ||
ESX.HideUI() | ||
end, | ||
|
||
inside = function(point) | ||
if ShowMarker then | ||
DrawMarker(Config.MarkerType, point.coords.x, point.coords.y, point.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.MarkerSize.x, | ||
Config.MarkerSize.y, Config.MarkerSize.z, Config.MarkerColor.r, Config.MarkerColor.g, | ||
Config.MarkerColor.b, 100, false, true, 2, false, nil, nil, false) | ||
end | ||
|
||
currentZone = point.currDistance < Config.MarkerSize.x and zone | ||
if currentZone and not inMenu and not TextUI then | ||
TextUI = true | ||
ESX.TextUI(Translate("press_menu", ESX.GetInteractKey())) | ||
elseif (not currentZone or inMenu) then | ||
if not currentZone and inMenu then | ||
ESX.UI.Menu.Close("default", GetCurrentResourceName(), "SHOP_MENU") | ||
inMenu = false | ||
end | ||
|
||
if TextUI then | ||
ESX.HideUI() | ||
TextUI = false | ||
end | ||
end | ||
end | ||
}) | ||
end | ||
|
||
-- Create Blips | ||
CreateThread(function() | ||
for k,v in pairs(Config.Zones) do | ||
for i = 1, #v.Pos, 1 do | ||
if not v.ShowBlip then return end | ||
|
||
local blip = AddBlipForCoord(v.Pos[i]) | ||
|
||
SetBlipSprite (blip, v.Type) | ||
SetBlipScale (blip, v.Size) | ||
SetBlipColour (blip, v.Color) | ||
SetBlipAsShortRange(blip, true) | ||
|
||
BeginTextCommandSetBlipName('STRING') | ||
AddTextComponentSubstringPlayerName(TranslateCap('shops')) | ||
EndTextCommandSetBlipName(blip) | ||
end | ||
end | ||
end) | ||
|
||
-- Enter / Exit marker events | ||
CreateThread(function() | ||
while true do | ||
local sleep = 1500 | ||
|
||
local playerCoords = GetEntityCoords(ESX.PlayerData.ped) | ||
local isInMarker, currentZone = false, nil | ||
|
||
for k,v in pairs(Config.Zones) do | ||
for i = 1, #v.Pos, 1 do | ||
local distance = #(playerCoords - v.Pos[i]) | ||
|
||
if distance < Config.DrawDistance then | ||
sleep = 0 | ||
if v.ShowMarker then | ||
DrawMarker(Config.MarkerType, v.Pos[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, nil, nil, false) | ||
end | ||
if distance < 2.0 then | ||
isInMarker = true | ||
currentZone = k | ||
lastZone = k | ||
end | ||
end | ||
end | ||
end | ||
|
||
if isInMarker and not hasAlreadyEnteredMarker then | ||
hasAlreadyEnteredMarker = true | ||
hasEnteredMarker(currentZone) | ||
ESX.TextUI(currentActionMsg) | ||
end | ||
|
||
if not isInMarker and hasAlreadyEnteredMarker then | ||
hasAlreadyEnteredMarker = false | ||
ESX.HideUI() | ||
hasExitedMarker(lastZone) | ||
end | ||
|
||
Wait(sleep) | ||
end | ||
for zone, v in pairs(Config.Zones) do | ||
for i = 1, #v.Pos, 1 do | ||
local pos = v.Pos[i] | ||
AddShopBlip(pos, v) | ||
createShopPoint(pos, zone, v.ShowMarker) | ||
end | ||
end | ||
end) | ||
|
||
ESX.RegisterInteraction("shop_menu", function() | ||
openShopMenu(currentActionData.zone) | ||
openShopMenu(currentZone) | ||
end, function() | ||
return currentAction and currentAction == 'shop_menu' | ||
end) | ||
return not inMenu | ||
end) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be consistent with variable naming. Why is TextUI capitalized?