@@ -2,6 +2,8 @@ if Config.Framework == "esx" then
2
2
ESX = exports [' es_extended' ]:getSharedObject ()
3
3
elseif Config .Framework == " qb" then
4
4
QBCore = exports [' qb-core' ]:GetCoreObject ()
5
+ elseif Config .Framework == " ox" then
6
+ Ox = require ' @ox_core.lib.init'
5
7
else
6
8
ESX = exports [' es_extended' ]:getSharedObject ()
7
9
end
@@ -11,6 +13,8 @@ local function getPlayerObject(src) -- Get the player object
11
13
return QBCore .Functions .GetPlayer (src )
12
14
elseif Config .Framework == ' esx' then
13
15
return ESX .GetPlayerFromId (src )
16
+ elseif Config .Framework == ' ox' then
17
+ return Ox .GetPlayer (src )
14
18
end
15
19
end
16
20
@@ -37,6 +41,11 @@ local function TakeMoney(playerObject, method, amount) -- Take money from the pl
37
41
return true
38
42
end
39
43
end
44
+ elseif Config .Framework == ' ox' then
45
+ if exports .ox_inventory :GetItemCount (source , ' money' ) >= amount then
46
+ exports .ox_inventory :RemoveItem (source , ' money' , amount )
47
+ return true
48
+ end
40
49
end
41
50
42
51
return false
@@ -63,6 +72,8 @@ local function giveItem(src, playerObject, item, amount) -- Give the item to the
63
72
else
64
73
playerObject .addInventoryItem (item .name , amount )
65
74
end
75
+ elseif Config .Framework == ' ox' then
76
+ exports .ox_inventory :AddItem (source , item .name , amount )
66
77
end
67
78
end
68
79
@@ -91,53 +102,62 @@ local function findItemInSource(sourceData, itemName) -- Find the item in the so
91
102
return nil
92
103
end
93
104
94
- RegisterNetEvent (' muhaddil-machines:buy' , function (sourceType , sourceName , itemName , cantidad ) -- Event for buying the item
95
- local src = source
96
- local player = getPlayerObject (src )
97
-
98
- local sourceData
99
- if sourceType == ' machine' then
100
- sourceData = Config .machines [sourceName ]
101
- elseif sourceType == ' stand' then
102
- sourceData = Config .Stands [sourceName ]
103
- elseif sourceType == ' news' then
104
- sourceData = Config .NewsSellers [sourceName ]
105
- else
106
- TriggerClientEvent (' muhaddil-machines:Notify' , src , ' ' , ' El tipo de origen no es válido.' , ' error' )
107
- return
108
- end
105
+ RegisterNetEvent (' muhaddil-machines:buy' ,
106
+ function (sourceType , sourceName , itemName , cantidad ) -- Event for buying the item
107
+ local src = source
108
+ local player = getPlayerObject (src )
109
109
110
- local item = findItemInSource (sourceData , itemName )
111
- if item then
112
- local totalPrice = item .price * cantidad
113
- handlePurchase (src , player , item , sourceName , totalPrice , cantidad )
114
- else
115
- TriggerClientEvent (' muhaddil-machines:Notify' , src , ' ' , ' El artículo no está disponible' , ' error' )
116
- end
117
- end )
110
+ local sourceData
111
+ if sourceType == ' machine' then
112
+ sourceData = Config .machines [sourceName ]
113
+ elseif sourceType == ' stand' then
114
+ sourceData = Config .Stands [sourceName ]
115
+ elseif sourceType == ' news' then
116
+ sourceData = Config .NewsSellers [sourceName ]
117
+ else
118
+ TriggerClientEvent (' muhaddil-machines:Notify' , src , ' ' , ' El tipo de origen no es válido.' , ' error' )
119
+ return
120
+ end
121
+
122
+ local item = findItemInSource (sourceData , itemName )
123
+ if item then
124
+ local totalPrice = item .price * cantidad
125
+ handlePurchase (src , player , item , sourceName , totalPrice , cantidad )
126
+ else
127
+ TriggerClientEvent (' muhaddil-machines:Notify' , src , ' ' , ' El artículo no está disponible' , ' error' )
128
+ end
129
+ end )
118
130
119
131
RegisterServerEvent (' muhaddil-machines:RemoveThirst' ) -- Event for the watercoolers to remove thirst
120
132
AddEventHandler (' muhaddil-machines:RemoveThirst' , function ()
121
133
local src = source
122
-
134
+
123
135
if Config .Framework == ' qb' then
124
136
local player = QBCore .Functions .GetPlayer (src )
125
137
if player then
126
138
local currentThirst = player .PlayerData .metadata [' thirst' ] or 0
127
139
if currentThirst < 100 then
128
140
local newThirst = math.min (currentThirst + Config .ThirstRemoval , 100 )
129
141
player .Functions .SetMetaData (' thirst' , newThirst )
130
-
142
+
131
143
TriggerClientEvent (' hud:client:UpdateNeeds' , src , player .PlayerData .metadata .hunger or 50 , newThirst )
132
144
else
133
145
print (" [Info] El jugador " .. src .. " ya tiene la sed máxima (100)." )
134
146
end
135
147
else
136
148
print (" [Error] No se pudo obtener el jugador para src: " .. tostring (src ))
137
149
end
138
-
139
150
elseif Config .Framework == ' esx' then
140
151
TriggerClientEvent (' esx_status:add' , src , ' thirst' , Config .ThirstRemoval )
152
+ elseif Config .Framework == ' ox' then
153
+ local player = Ox .GetPlayer (src )
154
+ local beforeStatus = player .getStatus (' thirst' )
155
+ player .removeStatus (' thirst' , Config .ThirstRemoval )
156
+ local afterStatus = player .getStatus (' thirst' )
157
+ DebugPrint (" [Info] El jugador " ..
158
+ src .. " tenía " .. beforeStatus .. " de sed y ahora tiene " .. afterStatus .. " ." )
159
+ local statuses = player .getStatuses ()
160
+ DebugPrint (" [Info] Los estados del jugador " .. src .. " son: " .. json .encode (statuses ))
141
161
else
142
162
print (" [Error] Configuración de framework no válida." )
143
163
end
0 commit comments