Skip to content

Commit 313b647

Browse files
committed
laodAmmoFromDB
1 parent 36d7c0d commit 313b647

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

client/main.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
RegisterCommand("giveTestWeapon", function()
2-
TriggerServerEvent("giveTestWeapon")
3-
print("WAiting 10 secs")
4-
Wait(10000)
5-
print('giving 300 ammo')
6-
Citizen.InvokeNative(0x5FD1E1F011E76D7E, PlayerPedId(), joaat("AMMO_PISTOL"), 300, 0xCA3454E6)
1+
RegisterNetEvent("Feather:Character:Spawned", function(character)
2+
TriggerServerEvent("feather-weapons:Init", character.id)
73
end)

fxmanifest.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ shared_scripts {
1010
}
1111

1212
server_scripts {
13+
'@oxmysql/lib/MySQL.lua',
1314
"/server/imports.lua",
1415
"/server/services/*.lua",
1516
"/server/main.lua"

server/main.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,21 @@ RegisterServerEvent('giveTestWeapon', function()
99
FeatherInv.Items.AddItem('carcano_sniper', 1, nil, _source)
1010
FeatherInv.Items.AddItem('bow', 1, nil, _source)
1111
FeatherInv.Items.AddItem('bow', 1, nil, _source)
12+
end)
13+
14+
RegisterServerEvent("feather-weapons:Init", function(charId)
15+
local _source = source
16+
-- ensure the player has a row in the ammo table
17+
local ammo = MySQL.query.await("SELECT * FROM ammo WHERE char_id = ?", { charId })
18+
if #ammo <= 0 then
19+
-- Creating new row if player doesn't have one
20+
MySQL.query.await("INSERT INTO ammo (char_id) VALUES (?)", { charId })
21+
else
22+
-- Sending ammo to client if player has a row
23+
for k, v in pairs(AmmoTypes) do
24+
if ammo[1][string.lower(k)] > 0 then
25+
TriggerClientEvent("feather-weapons:AddAmmo", _source, k, ammo[1][string.lower(k)])
26+
end
27+
end
28+
end
1229
end)

tempSQL.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ CREATE TABLE IF NOT EXISTS ammo (
8989
char_id BIGINT UNSIGNED NOT NULL,
9090
ammo_22 INT UNSIGNED NOT NULL DEFAULT 0,
9191
ammo_22_tranquilizer INT UNSIGNED NOT NULL DEFAULT 0,
92-
ammow_arrow INT UNSIGNED NOT NULL DEFAULT 0,
92+
ammo_arrow INT UNSIGNED NOT NULL DEFAULT 0,
9393
ammo_arrow_confusion INT UNSIGNED NOT NULL DEFAULT 0,
9494
ammo_arrow_disorient INT UNSIGNED NOT NULL DEFAULT 0,
9595
ammo_arrow_drain INT UNSIGNED NOT NULL DEFAULT 0,
9696
ammo_arrow_dynamite INT UNSIGNED NOT NULL DEFAULT 0,
9797
ammo_arrow_fire INT UNSIGNED NOT NULL DEFAULT 0,
98-
ammo_arrow_improvised INT UNSIGNED NOT NULL DEFAULT 0,
98+
ammo_arrow_improved INT UNSIGNED NOT NULL DEFAULT 0,
9999
ammo_arrow_poison INT UNSIGNED NOT NULL DEFAULT 0,
100100
ammo_arrow_small_game INT UNSIGNED NOT NULL DEFAULT 0,
101101
ammo_arrow_tracking INT UNSIGNED NOT NULL DEFAULT 0,
@@ -122,7 +122,7 @@ CREATE TABLE IF NOT EXISTS ammo (
122122
ammo_molotov INT UNSIGNED NOT NULL DEFAULT 0,
123123
ammo_molotov_volatile INT UNSIGNED NOT NULL DEFAULT 0,
124124
ammo_moonshinejug INT UNSIGNED NOT NULL DEFAULT 0,
125-
ammo_moonshinejugmp INT UNSIGNED NOT NULL DEFAULT 0,
125+
ammo_moonshinejug_mp INT UNSIGNED NOT NULL DEFAULT 0,
126126
ammo_pistol INT UNSIGNED NOT NULL DEFAULT 0,
127127
ammo_pistol_express INT UNSIGNED NOT NULL DEFAULT 0,
128128
ammo_pistol_express_explosive INT UNSIGNED NOT NULL DEFAULT 0,
@@ -159,10 +159,10 @@ CREATE TABLE IF NOT EXISTS ammo (
159159
ammo_throwing_knives_trail INT UNSIGNED NOT NULL DEFAULT 0,
160160
ammo_throwing_knives_wound INT UNSIGNED NOT NULL DEFAULT 0,
161161
ammo_thrown_item INT UNSIGNED NOT NULL DEFAULT 0,
162-
ammo_tomohawk INT UNSIGNED NOT NULL DEFAULT 0,
163-
ammo_tomohawk_ancient INT UNSIGNED NOT NULL DEFAULT 0,
164-
ammo_tomohawk_homing INT UNSIGNED NOT NULL DEFAULT 0,
165-
ammo_tomohawk_improved INT UNSIGNED NOT NULL DEFAULT 0,
162+
ammo_tomahawk INT UNSIGNED NOT NULL DEFAULT 0,
163+
ammo_tomahawk_ancient INT UNSIGNED NOT NULL DEFAULT 0,
164+
ammo_tomahawk_homing INT UNSIGNED NOT NULL DEFAULT 0,
165+
ammo_tomahawk_improved INT UNSIGNED NOT NULL DEFAULT 0,
166166
ammo_turret INT UNSIGNED NOT NULL DEFAULT 0,
167167

168168
FOREIGN KEY (char_id) REFERENCES characters(id) ON DELETE CASCADE

0 commit comments

Comments
 (0)