Skip to content

Commit 29387b4

Browse files
authored
Update to new callback api (#15)
* Update server.lua - change to new callback api * Update client.lua - change to new callback api - housekeeping
1 parent 9becc54 commit 29387b4

File tree

2 files changed

+38
-44
lines changed

2 files changed

+38
-44
lines changed

client/client.lua

+33-41
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
local VORPcore = {}
21
local VORPMenu = {}
3-
local Portal
4-
local PromptGroup = GetRandomIntInRange(0, 0xffffff)
5-
local InMenu = false
6-
7-
TriggerEvent('getCore', function(core)
8-
VORPcore = core
9-
end)
102
TriggerEvent('vorp_menu:getData', function(cb)
113
VORPMenu = cb
124
end)
135

6+
local ClientRPC = exports.vorp_core:ClientRpcCall()
7+
8+
local Portal
9+
local PromptGroup = GetRandomIntInRange(0, 0xffffff)
10+
local InMenu = false
1411
-- Start Portals
1512
CreateThread(function()
1613
PortPrompt()
1714
while true do
1815
Wait(0)
19-
local player = PlayerPedId()
20-
local pCoords = GetEntityCoords(player)
16+
local playerPed = PlayerPedId()
17+
local pCoords = GetEntityCoords(playerPed)
2118
local sleep = true
2219
local hour = GetClockHours()
2320

24-
if not InMenu and not IsEntityDead(player) then
21+
if not InMenu and not IsEntityDead(playerPed) then
2522
for shop, shopCfg in pairs(Config.shops) do
2623
if shopCfg.shopHours then
2724
-- Using Shop Hours - Shop Closed
@@ -105,13 +102,12 @@ CreateThread(function()
105102
PromptSetEnabled(Portal, 1)
106103

107104
if Citizen.InvokeNative(0xC92AC953F0A982AE, Portal) then -- UiPromptHasStandardModeCompleted
108-
VORPcore.RpcCall('CheckPlayerJob', function(hasJob)
109-
if hasJob then
105+
local result = ClientRPC.Callback.TriggerAwait('bcc-portals:CheckPlayerJob', shop)
106+
if result then
110107
OpenMenu(pCoords, shop)
111108
else
112109
return
113110
end
114-
end, shop)
115111
end
116112
end
117113
end
@@ -173,13 +169,12 @@ CreateThread(function()
173169
PromptSetEnabled(Portal, 1)
174170

175171
if Citizen.InvokeNative(0xC92AC953F0A982AE, Portal) then -- UiPromptHasStandardModeCompleted
176-
VORPcore.RpcCall('CheckPlayerJob', function(hasJob)
177-
if hasJob then
178-
OpenMenu(pCoords,shop)
179-
else
180-
return
181-
end
182-
end, shop)
172+
local result = ClientRPC.Callback.TriggerAwait('bcc-portals:CheckPlayerJob', shop)
173+
if result then
174+
OpenMenu(pCoords,shop)
175+
else
176+
return
177+
end
183178
end
184179
end
185180
end
@@ -195,9 +190,9 @@ end)
195190
-- Portal Menu to Choose Destination
196191
function OpenMenu(pCoords, shop)
197192
VORPMenu.CloseAll()
198-
local player = PlayerPedId()
193+
local playerPed = PlayerPedId()
199194
local shopCfg = Config.shops[shop]
200-
TaskStandStill(player, -1)
195+
TaskStandStill(playerPed, -1)
201196
DisplayRadar(false)
202197
InMenu = true
203198
local MenuElements = {}
@@ -224,25 +219,24 @@ function OpenMenu(pCoords, shop)
224219
end
225220
if data.current.value then
226221
local travelInfo = {location = data.current.value, coords = pCoords}
227-
VORPcore.RpcCall("GetTravelData", function(travelData)
228-
if travelData then
229-
DestinationMenu(travelData, shop, pCoords)
230-
end
231-
end, travelInfo)
222+
local travelData = ClientRPC.Callback.TriggerAwait('bcc-portals:GetTravelData', travelInfo)
223+
if travelData then
224+
DestinationMenu(travelData, shop, pCoords)
225+
end
232226
end
233227
end,
234228
function(data, menu)
235229
menu.close()
236230
InMenu = false
237-
ClearPedTasks(player)
231+
ClearPedTasks(playerPed)
238232
DisplayRadar(true)
239233
end)
240234
end
241235

242236
function DestinationMenu(travelData, shop, pCoords)
243237
VORPMenu.CloseAll()
244238
InMenu = true
245-
local player = PlayerPedId()
239+
local playerPed = PlayerPedId()
246240
local MenuElements = {}
247241
local travelLoc = travelData.location
248242
local cashPrice = travelData.cash
@@ -318,21 +312,19 @@ function DestinationMenu(travelData, shop, pCoords)
318312
end
319313

320314
local canTravelInfo = {currency = data.current.value, price = data.current.info}
321-
VORPcore.RpcCall("GetPlayerCanTravel", function(canTravel)
322-
if canTravel then
323-
SendPlayer(travelLoc, travelData.travelTime)
324-
end
325-
end, canTravelInfo)
326-
327-
menu.close()
328-
InMenu = false
329-
ClearPedTasks(player)
330-
DisplayRadar(true)
315+
local canTravel = ClientRPC.Callback.TriggerAwait('bcc-portals:GetPlayerCanTravel', canTravelInfo)
316+
if canTravel then
317+
menu.close()
318+
SendPlayer(travelLoc, travelData.travelTime)
319+
InMenu = false
320+
ClearPedTasks(playerPed)
321+
DisplayRadar(true)
322+
end
331323
end,
332324
function(data, menu)
333325
menu.close()
334326
InMenu = false
335-
ClearPedTasks(player)
327+
ClearPedTasks(playerPed)
336328
DisplayRadar(true)
337329
end)
338330
end

server/server.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ TriggerEvent('getCore', function(core)
33
VORPcore = core
44
end)
55

6+
local ServerRPC = exports.vorp_core:ServerRpcCall()
7+
68
-- Get Travel Time and Price Data
7-
VORPcore.addRpcCallback("GetTravelData", function(source, cb, travelInfo)
9+
ServerRPC.Callback.Register('bcc-portals:GetTravelData', function(source, cb, travelInfo)
810
local travelLoc = travelInfo.location
911
local distance = #(travelInfo.coords - Config.shops[travelLoc].npcPos)
1012
local cashPrice = 0
@@ -21,7 +23,7 @@ VORPcore.addRpcCallback("GetTravelData", function(source, cb, travelInfo)
2123
end)
2224

2325
-- Buy Portal Passage
24-
VORPcore.addRpcCallback("GetPlayerCanTravel", function(source, cb, canTravelInfo)
26+
ServerRPC.Callback.Register('bcc-portals:GetPlayerCanTravel', function(source, cb, canTravelInfo)
2527
local src = source
2628
local Character = VORPcore.getUser(src).getUsedCharacter
2729
local currency = canTravelInfo.currency
@@ -49,7 +51,7 @@ VORPcore.addRpcCallback("GetPlayerCanTravel", function(source, cb, canTravelInfo
4951
end)
5052

5153
-- Get Player Job and Job Grade
52-
VORPcore.addRpcCallback('CheckPlayerJob', function(source, cb, shop)
54+
ServerRPC.Callback.Register('bcc-portals:CheckPlayerJob', function(source, cb, shop)
5355
local src = source
5456
local Character = VORPcore.getUser(src).getUsedCharacter
5557
local playerJob = Character.job

0 commit comments

Comments
 (0)