All done. After screwing around with the callback it became very easy to test with console.logs to see what the code was doing. In doing so I also solved the menu issue and it navigates just fine now. Here is the final code -
Server Side -
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('DKGShops:addAmmo')
AddEventHandler('DKGShops:addAmmo', function(int)
local xPlayer = ESX.GetPlayerFromId(source)
if int == 1 then
if xPlayer.getMoney() >= 3500 then
xPlayer.removeMoney(3500)
xPlayer.addInventoryItem('clip', 1)
TriggerClientEvent('bulletin:send', source, 'You\'ve just bought an ~b~Ammor Box')
else
TriggerClientEvent('bulletin:send', source, 'You don\'t have enough money to buy that!')
end
elseif int == 2 then
if xPlayer.getMoney() >= 17500 then
xPlayer.removeMoney(17500)
xPlayer.addInventoryItem('clip', 5)
TriggerClientEvent('bulletin:send', source, 'You\'ve just bought ~y~five ~b~Ammor Box\'s')
else
TriggerClientEvent('bulletin:send', source, 'You don\'t have enough money to buy that!')
end
elseif int == 3 then
if xPlayer.getMoney() >= 35000 then
xPlayer.removeMoney(35000)
xPlayer.addInventoryItem('clip', 10)
TriggerClientEvent('bulletin:send', source, 'You\'ve just bought ~y~ten ~b~Ammor Box\'s')
else
TriggerClientEvent('bulletin:send', source, 'You don\'t have enough money to buy that!')
end
end
end)
Client Side -
RegisterNetEvent('DKGShops:openMenu')
AddEventHandler('DKGShops:openMenu', function()
SendNUIMessage({
type = "menu",
ammoMenu = true
})
end)
RegisterNetEvent('DKGShops:closeMenu')
AddEventHandler('DKGShops:closeMenu', function()
SendNUIMessage({
type = "menu",
ammoMenu = false
})
end)
RegisterNetEvent('DKGShops:nav')
AddEventHandler('DKGShops:nav', function(a)
if a then
SendNUIMessage({
type = "navMenu",
down = false
})
else
SendNUIMessage({
type = "navMenu",
down = true
})
end
end)
RegisterNetEvent('DKGShops:submit')
AddEventHandler('DKGShops:submit', function()
SendNUIMessage({
type = "menuSubmit",
submit = true
})
end)
RegisterNetEvent('DKGShops:randomShit')
AddEventHandler('DKGShops:randomShit', function()
exports.bulletin:Send("Yay, random shit!")
end)
RegisterNUICallback('menuSubmit', function(data, cb)
if data.indexNum == 0 then
TriggerServerEvent('DKGShops:addAmmo', 1)
elseif data.indexNum == 1 then
TriggerServerEvent('DKGShops:addAmmo', 2)
elseif data.indexNum == 2 then
TriggerServerEvent('DKGShops:addAmmo', 3)
end
cb('ok')
end)
Client Threads -
Citizen.CreateThread(function()
while true do
Wait(0)
local userVec = GetEntityCoords(GetPlayerPed(-1))
local vec1 = vector3(18.48, -1109.93, 29.6)
userDistFromMarker = #(userVec - vec1)
if userDistFromMarker <= 5.6 then
--DrawMarker(IconType, PosX, PosY, PosZ, DirX, DirY, DirZ, RotX, RotY, RotZ, ScaleX, ScaleY, ScaleZ, Red, Green, Blue, Opacity, BobUpAndDown, FaceCam, 2, false, false, false, false)
DrawMarker(20, 18.48, -1109.93, 29.6, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0, 230, 38, 100, false, true, 2, true, false, false, false)
end
if userDistFromMarker <= 0.4 then
userInMarker = true
SetTextComponentFormat('STRING')
AddTextComponentString('Press ~INPUT_CONTEXT~ to open ~y~Blanks & Tanks')
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlJustReleased(0, 38) then
TriggerEvent('DKGShops:openMenu')
end
else
userInMarker = false
TriggerEvent('DKGShops:closeMenu')
end
if userInMarker then
if IsControlJustPressed(0, 187) then
local moveUp = false
TriggerEvent('DKGShops:nav', moveUp)
elseif IsControlJustPressed(0, 188) then
local moveUp = true
TriggerEvent('DKGShops:nav', moveUp)
elseif IsControlJustPressed(0, 191) then
TriggerEvent('DKGShops:submit')
end
end
if IsControlJustPressed(0, 177) then
TriggerEvent('DKGShops:closeMenu')
end
end
end)
Listener -
$(function () {
window.onload = (e) => {
$('#wrapper').hide();
var index = 0;
window.addEventListener('message', (event) => {
var item = event.data;
if (item !== undefined && item.type == "menu") {
if (item.ammoMenu == true) {
$('#wrapper').show();
}
else {
$('#wrapper').hide();
}
}
if (item !== undefined && item.down == true) {
index++;
if (index == 3) {
index = 0;
}
//console.log("The index value is - " + index);
$('li').removeClass('active');
$($('li')[index]).addClass('active');
}
else if (item !== undefined && item.down == false) {
index--;
if (index == -1) {
index = 2;
}
//console.log("The index value is - " + index);
$('li').removeClass('active');
$($('li')[index]).addClass('active');
}
if (item !== undefined && item.type == "menuSubmit") {
switch (index) {
case 0:
itemText = "You just bought an ~b~Ammo Box";
break;
case 1:
itemText = "You just bought ~y~five ~b~Ammo box\'s";
break;
case 2:
itemText = "Like a true American, you bought ~y~ten ~b~Ammo Box\'s"
break;
}
$.post('http://DKGShops/menuSubmit', JSON.stringify({
itemString: itemText,
indexNum: index
}));
}
})
}
})
HTML -
<html>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="js/listener.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div id="content">
<div id="title">
<a>Blanks & Tanks</a>
</div>
<div id="sidebar"></div>
<ol id="table">
<li class="active">Ammo Box | $3500</li>
<li>Ammo Box x5 | $17,500</li>
<li>Ammo Box x10 | $35,000</li>
</ol>
</div>
</div>
</body>
</html>
CSS -
#wrapper {
width: 20%;
height: 55%;
position: relative;
left: 78%;
top: 43%;
}
#content {
background-color: rgba(26, 26, 0, 0.8);
padding: 3%;
}
#title {
background-color: rgb(220, 172, 11);
width: 100%;
height: 5%;
font-size: 27px;
text-align: center;
padding-top: 2px;
padding-bottom: 2px;
border-radius: 5px 5px 5px 0px;
}
#sidebar {
border-left: 1px solid rgb(220, 172, 11);
position: absolute;
left: 0px;
top: 10%;
left: 3%;
height: 41%;
}
li {
display: block;
position: relative;
color:white;
margin: 10px;
width: 100%;
height: 12%;
left: -8.5%;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
}
.active {
background-color: rgb(174, 9, 9);
color: gold;
border: 1px solid rgb(220, 172, 11);
font-size: 20px;
}
Now that it works I will start to improve on it. For instance a slider for multiple items instead of multiple entries for multiple items. Feel free to use the code here is what it looks like -

