Skip to content
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

Ammo Bug #33

Open
Razzorone opened this issue Jan 21, 2022 · 2 comments
Open

Ammo Bug #33

Razzorone opened this issue Jan 21, 2022 · 2 comments

Comments

@Razzorone
Copy link

Hi. I use the inventory. With the following weapon shop
rsg_weaponshop

I added the ammo entries to the config.lua. I can buy anything without error.

But when I have a gun in hand. Open the inventory and drag the ammo to use, nothing happens. The ammo disappears but the gun doesn't get any ammo

Where is my mistake?

@Razzorone
Copy link
Author

rsg_weaponshop
server.lua

-- created by RexshackGaming : Discord : https://discord.gg/8gNCwDpQPb
-- youtube channel : https://www.youtube.com/channel/UCikEgGfXO-HCPxV5rYHEVbA

local data = {}
TriggerEvent("redemrp_inventory:getData",function(call)
data = call
end)

-- buy weapon
RegisterServerEvent('rsg_weaponshop:buyweapon')
AddEventHandler("rsg_weaponshop:buyweapon", function(price, item1, lvl)
TriggerEvent("redemrp:getPlayerFromId", source, function(user)
local _source = source
local level = user.getLevel()
if user.getMoney() >= price then
if level >= lvl then
user.removeMoney(price)
local ItemData = data.getItem(_source, item1)
print(ItemData.ItemAmount)
ItemData.AddItem(1)
TriggerClientEvent('rsg_weaponshop:equipitem1', _source, item1)
TriggerClientEvent("redemrp_notification:start", _source, "You purchased a weapon!", 3, "success")
else
TriggerClientEvent('rsg_weaponshop:alert', _source, "You are not a high enough level!")
end
else
TriggerClientEvent('rsg_weaponshop:alert', _source, "You dont have enough money!")
end
end)
end)

-- buy ammo
RegisterServerEvent('rsg_weaponshop:buyammo')
AddEventHandler("rsg_weaponshop:buyammo", function(price, item2, lvl)
TriggerEvent("redemrp:getPlayerFromId", source, function(user)
local _source = source
local level = user.getLevel()
if user.getMoney() >= price then
if level >= lvl then
user.removeMoney(price)
local ItemData = data.getItem(_source, item2)
print(ItemData.ItemAmount)
ItemData.AddItem(1)
TriggerClientEvent("redemrp_notification:start", _source, "You purchased some ammo!", 3, "success")
else
TriggerClientEvent('rsg_weaponshop:alert', _source, "You are not a high enough level!")
end
else
TriggerClientEvent('rsg_weaponshop:alert', _source, "You dont have enough money!")
end
end)
end)

-- ammo

-------- revolver_ammo
RegisterServerEvent("RegisterUsableItem:revolver_ammo")
AddEventHandler("RegisterUsableItem:revolver_ammo", function(source)
TriggerClientEvent('rsg_weaponshop:giveammo', source, "WEAPON_REVOLVER_CATTLEMAN")
local ItemData = data.getItem(source, 'revolver_ammo')
ItemData.RemoveItem(1)
end)

-------- pistol_ammo
RegisterServerEvent("RegisterUsableItem:pistol_ammo")
AddEventHandler("RegisterUsableItem:pistol_ammo", function(source)
TriggerClientEvent('rsg_weaponshop:giveammo', source, "WEAPON_PISTOL_VOLCANIC")
local ItemData = data.getItem(source, 'pistol_ammo')
ItemData.RemoveItem(1)
end)

-------- rifle_ammo
RegisterServerEvent("RegisterUsableItem:rifle_ammo")
AddEventHandler("RegisterUsableItem:rifle_ammo", function(source)
TriggerClientEvent('rsg_weaponshop:giveammo', source, "WEAPON_RIFLE_BOLTACTION")
local ItemData = data.getItem(source, 'rifle_ammo')
ItemData.RemoveItem(1)
end)

-------- repeater_ammo
RegisterServerEvent("RegisterUsableItem:repeater_ammo")
AddEventHandler("RegisterUsableItem:repeater_ammo", function(source)
TriggerClientEvent('rsg_weaponshop:giveammo', source, "WEAPON_REPEATER_EVANS")
local ItemData = data.getItem(source, 'repeater_ammo')
ItemData.RemoveItem(1)
end)

-------- shotgun_ammo
RegisterServerEvent("RegisterUsableItem:shotgun_ammo")
AddEventHandler("RegisterUsableItem:shotgun_ammo", function(source)
TriggerClientEvent('rsg_weaponshop:giveammo', source, "WEAPON_SHOTGUN_PUMP")
local ItemData = data.getItem(source, 'shotgun_ammo')
ItemData.RemoveItem(1)
end)


client.lua

-- created by RexshackGaming : Discord : https://discord.gg/8gNCwDpQPb
-- youtube channel : https://www.youtube.com/channel/UCikEgGfXO-HCPxV5rYHEVbA

MenuData = {}
TriggerEvent("redemrp_menu_base:getData",function(call)
MenuData = call
end)

-- add weaponshop locations
local weaponshop = {

{ x = -282.28, y = 780.59, z = 118.53 }, --val
{ x = 2715.9, y = -1285.04, z = 49.63 },  --saint
{ x = -856.95, y = -1391.59, z = 43.49 }, --blackwater
{ x= 1323.09, y = -1321.63, z = 77.89 }, --rhodes

}

local active = false
local ShopPrompt
local hasAlreadyEnteredMarker, lastZone
local currentZone = nil

function SetupShopPrompt()
Citizen.CreateThread(function()
local str = 'Browse Weapon Shop'
ShopPrompt = PromptRegisterBegin()
PromptSetControlAction(ShopPrompt, 0xE8342FF2)
str = CreateVarString(10, 'LITERAL_STRING', str)
PromptSetText(ShopPrompt, str)
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
PromptSetHoldMode(ShopPrompt, true)
PromptRegisterEnd(ShopPrompt)

end)

end

AddEventHandler('rsg_weaponshop:hasEnteredMarker', function(zone)
currentZone = zone
end)

AddEventHandler('rsg_weaponshop:hasExitedMarker', function(zone)
if active == true then
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
active = false
end
WarMenu.CloseMenu()
currentZone = nil
end)

Citizen.CreateThread(function()
SetupShopPrompt()
while true do
Citizen.Wait(0)
local player = PlayerPedId()
local coords = GetEntityCoords(player)
local isInMarker, currentZone = false

    for k,v in ipairs(weaponshop) do
        if (Vdist(coords.x, coords.y, coords.z, v.x, v.y, v.z) < 1.5) then
            isInMarker  = true
            currentZone = 'weaponshop'
            lastZone    = 'weaponshop'
        end
    end

	if isInMarker and not hasAlreadyEnteredMarker then
		hasAlreadyEnteredMarker = true
		TriggerEvent('rsg_weaponshop:hasEnteredMarker', currentZone)
	end

	if not isInMarker and hasAlreadyEnteredMarker then
		hasAlreadyEnteredMarker = false
		TriggerEvent('rsg_weaponshop:hasExitedMarker', lastZone)
	end

end

end)

-- menu start
Citizen.CreateThread(function()

WarMenu.CreateMenu('weaponshop', "Weapon Shop")
WarMenu.SetSubTitle('weaponshop', 'subtitle')
WarMenu.CreateSubMenu('buy_melee', 'weaponshop', '')
WarMenu.CreateSubMenu('buy_revolver', 'weaponshop', '')
WarMenu.CreateSubMenu('buy_pistol', 'weaponshop', '')
WarMenu.CreateSubMenu('buy_rifle', 'weaponshop', '')
WarMenu.CreateSubMenu('buy_shotgun', 'weaponshop', '')
WarMenu.CreateSubMenu('buy_ammo', 'weaponshop', '')

while true do

    if WarMenu.IsMenuOpened('weaponshop') then
        if WarMenu.MenuButton('Melee', 'buy_melee') then
        end
		if WarMenu.MenuButton('Revolvers', 'buy_revolver') then
        end
		if WarMenu.MenuButton('Pistols', 'buy_pistol') then
        end
		if WarMenu.MenuButton('Rifles and Repeaters', 'buy_rifle') then
        end
		if WarMenu.MenuButton('Shotgun', 'buy_shotgun') then
        end
		if WarMenu.MenuButton('Ammo', 'buy_ammo') then
        end
        WarMenu.Display()

    -- buy melee
    elseif WarMenu.IsMenuOpened('buy_melee') then
        
        if WarMenu.Button('Knife : ~pa~$50 [0]') then
            TriggerServerEvent("rsg_weaponshop:buyweapon", 50, "WEAPON_MELEE_KNIFE", 0)
        
        elseif WarMenu.Button('Throwing Knives : ~pa~$117 [0]') then
            TriggerServerEvent("rsg_weaponshop:buyweapon", 117, "WEAPON_THROWN_THROWING_KNIVES", 0)
        
        elseif WarMenu.Button('Lasso : ~pa~$50 [0]') then
            TriggerServerEvent("rsg_weaponshop:buyweapon", 50, "WEAPON_LASSO", 0)
        
        elseif WarMenu.Button('Bow : ~pa~$127 [0]') then
            TriggerServerEvent("rsg_weaponshop:buyweapon", 127, "WEAPON_BOW", 0)
        end                
        WarMenu.Display()
	
	
	-- buy revolvers
    elseif WarMenu.IsMenuOpened('buy_revolver') then
        
		if WarMenu.Button('Cattleman Revolver : ~pa~$50 [0]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 50, "WEAPON_REVOLVER_CATTLEMAN", 0)
		
		elseif WarMenu.Button('LeMat Revolver : ~pa~$317 [0]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 317, "WEAPON_REVOLVER_LEMAT", 0)
		
		elseif WarMenu.Button('Schofield Revolver : ~pa~$192 [0]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 192, "WEAPON_REVOLVER_LEMAT", 0)
		
		elseif WarMenu.Button('Double Action Revolver : ~pa~$127 [0]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 127, "WEAPON_REVOLVER_DOUBLEACTION", 0)
			
		elseif WarMenu.Button('High Roller Double-Action Revolver : ~pa~$190 [0]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 190, "WEAPON_REVOLVER_DOUBLEACTION_GAMBLER", 0)
		
		end
		WarMenu.Display()
	
	-- buy pistols
    elseif WarMenu.IsMenuOpened('buy_pistol') then
        
		if WarMenu.Button('Pistol Volcanic : ~pa~$270 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 270, "WEAPON_PISTOL_VOLCANIC", 1)
			
		elseif WarMenu.Button('Pistol Semi-Automatic : ~pa~$537 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 537, "WEAPON_PISTOL_SEMIAUTO", 1)
		
		elseif WarMenu.Button('Pistol Mauser : ~pa~$600 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 600, "WEAPON_PISTOL_MAUSER", 1)
			
        end
        WarMenu.Display()
	
	-- buy rifles
    elseif WarMenu.IsMenuOpened('buy_rifle') then
        
		if WarMenu.Button('Evans Repeater : ~pa~$456 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 300, "WEAPON_REPEATER_EVANS", 1)
		
		elseif WarMenu.Button('Bolt Action Rifle : ~pa~$216 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 216, "WEAPON_RIFLE_BOLTACTION", 1)
			
		elseif WarMenu.Button('Varmint Rifle : ~pa~$72 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 72, "WEAPON_RIFLE_VARMINT", 1)
			
		elseif WarMenu.Button('Rolling Block Rifle : ~pa~$411 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 411, "WEAPON_SNIPERRIFLE_ROLLINGBLOCK", 1)
			
		elseif WarMenu.Button('Springfield Rifle : ~pa~$156 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 156, "WEAPON_RIFLE_SPRINGFIELD", 1)
			
		elseif WarMenu.Button('Carcano Rifel : ~pa~$456 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 456, "WEAPON_SNIPERRIFLE_CARCANO", 1)
			
        end
        WarMenu.Display()
		
	-- buy shotgun
    elseif WarMenu.IsMenuOpened('buy_shotgun') then
        
		if WarMenu.Button('Pump-Action Shotgun : ~pa~$266 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 266, "WEAPON_SHOTGUN_PUMP", 1)
		
		elseif WarMenu.Button('Repeating Shotgun : ~pa~$434 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 434, "WEAPON_SHOTGUN_REPEATING", 1)
			
		elseif WarMenu.Button('Sawed-Off Shotgun : ~pa~$111 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 111, "WEAPON_SHOTGUN_SAWEDOFF", 1)
			
		elseif WarMenu.Button('Double-Barreled Shotgun : ~pa~$185 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 185, "WEAPON_SHOTGUN_DOUBLEBARREL", 1)
			
		elseif WarMenu.Button('Semi-Auto Shotgun : ~pa~$540 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyweapon", 540, "WEAPON_SHOTGUN_SEMIAUTO", 1)
			
        end
        WarMenu.Display()
	
	-- buy ammo	
    elseif WarMenu.IsMenuOpened('buy_ammo') then
		
		if WarMenu.Button('Revolver Ammo : ~pa~$1 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyammo", 1, "revolver_ammo", 1)
			
		elseif WarMenu.Button('Pistol Ammo : ~pa~$1 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyammo", 1, "pistol_ammo", 1)
			
		elseif WarMenu.Button('Rifle Ammo : ~pa~$2 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyammo", 2, "rifle_ammo", 1)
			
		elseif WarMenu.Button('Repeater Ammo : ~pa~$2 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyammo", 2, "repeater_ammo", 1)
			
		elseif WarMenu.Button('Shotgun Ammo : ~pa~$2 [1]') then
			TriggerServerEvent("rsg_weaponshop:buyammo", 2, "shotgun_ammo", 1)
			
        end
        WarMenu.Display()

    end
	
    Citizen.Wait(0)
end

end)
-- menu stop

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if currentZone then
if active == false then
PromptSetEnabled(ShopPrompt, true)
PromptSetVisible(ShopPrompt, true)
active = true
end
if PromptHasHoldModeCompleted(ShopPrompt) then
WarMenu.OpenMenu('weaponshop')
WarMenu.Display()
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
active = false

			currentZone = nil
		end
    else
		Citizen.Wait(500)
	end
end

end)

RegisterNetEvent('rsg_weaponshop:alert')
AddEventHandler('rsg_weaponshop:alert', function(txt)
SetTextScale(0.5, 0.5)
local str = Citizen.InvokeNative(0xFA925AC00EB830B9, 10, "LITERAL_STRING", txt, Citizen.ResultAsLong())
Citizen.InvokeNative(0xFA233F8FE190514C, str)
Citizen.InvokeNative(0xE9990552DEC71600)
end)

RegisterNetEvent('rsg_weaponshop:equipitem1')
AddEventHandler('rsg_weaponshop:equipitem1', function(item1)
Citizen.CreateThread(function()
local equipitem = GetHashKey(item1)
local playerPed = PlayerPedId()
Wait(1000)
GiveDelayedWeaponToPed(playerPed, equipitem, 100, true)
end, false)
end)

RegisterNetEvent('rsg_weaponshop:giveammo')
AddEventHandler('rsg_weaponshop:giveammo', function(type)
local player = GetPlayerPed()
local ammo = GetHashKey(type)
SetPedAmmo(player, ammo, 100)
end)

@BulgaRpl
Copy link
Contributor

Ask the weaponshop author for the fix. There is no issues in inventory for weapons atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants