Skip to content

Commit

Permalink
Update server.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
dojwun committed Aug 2, 2024
1 parent 56691d5 commit e311079
Showing 1 changed file with 25 additions and 53 deletions.
78 changes: 25 additions & 53 deletions casino-slots/server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local QBCore = exports['qb-core']:GetCoreObject()
---@diagnostic disable: param-type-mismatch
QBCore = exports['qb-core']:GetCoreObject()
local UsedSlots = {}
local Slots = {}

Expand All @@ -8,13 +9,13 @@ local function table_matches(t1, t2)
if type1 ~= 'table' and type2 ~= 'table' then return t1 == t2 end

for k1,v1 in pairs(t1) do
local v2 = t2[k1]
if v2 == nil or not table_matches(v1,v2) then return false end
local v2 = t2[k1]
if v2 == nil or not table_matches(v1,v2) then return false end
end

for k2,v2 in pairs(t2) do
local v1 = t1[k2]
if v1 == nil or not table_matches(v1,v2) then return false end
local v1 = t1[k2]
if v1 == nil or not table_matches(v1,v2) then return false end
end
return true
end
Expand All @@ -28,12 +29,11 @@ local function LeaveSlot(source)
Slots[source] = {}
end

RegisterNetEvent('dc-casino:slots:server:enter', function(netID, ReelLocation1, ReelLocation2, ReelLocation3)
RegisterNetEvent('dc-casino:slots:server:enter', function(netID, ReelLocation1, ReelLocation2, ReelLocation3, SlotModel)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local PlayerCoords = GetEntityCoords(GetPlayerPed(src))
local SlotEntity = NetworkGetEntityFromNetworkId(netID)
local SlotModel = GetEntityModel(SlotEntity)
local SlotCoords = GetEntityCoords(SlotEntity)

if not SlotReferences[SlotModel] then return end
Expand All @@ -44,14 +44,16 @@ RegisterNetEvent('dc-casino:slots:server:enter', function(netID, ReelLocation1,
UsedSlots[netID] = true
TriggerClientEvent('dc-casino:slots:client:enter', src)
SetTimeout(1000, function()
local ReelEntity1 = CreateObject(SlotReferences[SlotModel].reela, ReelLocation1, true, false, false)
local ReelEntity2 = CreateObject(SlotReferences[SlotModel].reela, ReelLocation2, true, false, false)
local ReelEntity3 = CreateObject(SlotReferences[SlotModel].reela, ReelLocation3, true, false, false)
local ReelEntity1 = CreateObject(SlotReferences[SlotModel].reela, ReelLocation1.x, ReelLocation1.y, ReelLocation1.z, true, false, false)
local ReelEntity2 = CreateObject(SlotReferences[SlotModel].reela, ReelLocation2.x, ReelLocation2.y, ReelLocation2.z, true, false, false)
local ReelEntity3 = CreateObject(SlotReferences[SlotModel].reela, ReelLocation3.x, ReelLocation3.y, ReelLocation3.z, true, false, false)
while not DoesEntityExist(ReelEntity1) do Wait(0) end
while not DoesEntityExist(ReelEntity2) do Wait(0) end
while not DoesEntityExist(ReelEntity3) do Wait(0) end
---@diagnostic disable-next-line: need-check-nil
Slots[src] = {
Slot = NetworkGetEntityFromNetworkId(netID),
Model = SlotModel,
SlotNetID = netID,
Reel1 = ReelEntity1,
Reel2 = ReelEntity2,
Expand All @@ -77,33 +79,30 @@ RegisterNetEvent('dc-casino:slots:server:spin', function(ChosenBetAmount)
local SpinTime = math.random(4000, 6000)
local ReelRewards = {math.random(0, 15), math.random(0, 15), math.random(0, 15)}
local SlotHeading = GetEntityHeading(Slots[src].Slot)
local SlotModel = GetEntityModel(Slots[src].Slot)
local SlotModel = Slots[src].Model
local Player = QBCore.Functions.GetPlayer(src)

if not Slots[src] then return end
if not SlotReferences[SlotModel].betamounts[ChosenBetAmount] then return end
if UseCash and Player.Functions.RemoveMoney('cash', SlotReferences[SlotModel].betamounts[ChosenBetAmount], 'Casino Slot Spin')
or UseBank and Player.Functions.RemoveMoney('bank', SlotReferences[SlotModel].betamounts[ChosenBetAmount], 'Casino Slot Spin')
-- luacheck: ignore
or UseItem and Player.Functions.RemoveItem(ItemName, SlotReferences[SlotModel].betamounts[ChosenBetAmount]) then TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items['casino_goldchip'], "remove", ChosenBetAmount)

else TriggerClientEvent('QBCore:Notify', src, 'Nothing left to bet with', 'error') return end
or UseItem and Player.Functions.RemoveItem('casinochips', SlotReferences[SlotModel].betamounts[ChosenBetAmount]) then else TriggerClientEvent('QBCore:Notify', src, 'Not enough casino chips for this bet.', 'error') return end

for i = 1, #ReelRewards do
if SlotReferences[SlotModel].misschance > math.random(1, 100) then ReelRewards[i] = ReelRewards[i] + math.random(4, 6) / 10 end
end
local BlurryReel1 = CreateObject(SlotReferences[SlotModel].reelb, Slots[src].ReelLoc1, true, false, false)
local BlurryReel2 = CreateObject(SlotReferences[SlotModel].reelb, Slots[src].ReelLoc2, true, false, false)
local BlurryReel3 = CreateObject(SlotReferences[SlotModel].reelb, Slots[src].ReelLoc3, true, false, false)
local BlurryReel1 = CreateObject(SlotReferences[SlotModel].reelb, Slots[src].ReelLoc1.x, Slots[src].ReelLoc1.y, Slots[src].ReelLoc1.z, true, false, false)
local BlurryReel2 = CreateObject(SlotReferences[SlotModel].reelb, Slots[src].ReelLoc2.x, Slots[src].ReelLoc2.y, Slots[src].ReelLoc2.z, true, false, false)
local BlurryReel3 = CreateObject(SlotReferences[SlotModel].reelb, Slots[src].ReelLoc3.x, Slots[src].ReelLoc3.y, Slots[src].ReelLoc3.z, true, false, false)
while not DoesEntityExist(BlurryReel1) do Wait(0) end
while not DoesEntityExist(BlurryReel2) do Wait(0) end
while not DoesEntityExist(BlurryReel3) do Wait(0) end
FreezeEntityPosition(BlurryReel1, true)
FreezeEntityPosition(BlurryReel2, true)
FreezeEntityPosition(BlurryReel3, true)
SetEntityRotation(BlurryReel1, 0.0, 0.0, SlotHeading, 2, 1)
SetEntityRotation(BlurryReel2, 0.0, 0.0, SlotHeading, 2, 1)
SetEntityRotation(BlurryReel3, 0.0, 0.0, SlotHeading, 2, 1)
SetEntityRotation(BlurryReel1, 0.0, 0.0, SlotHeading, 2, true)
SetEntityRotation(BlurryReel2, 0.0, 0.0, SlotHeading, 2, true)
SetEntityRotation(BlurryReel3, 0.0, 0.0, SlotHeading, 2, true)
local RewardMultiplier = 0
for k, v in pairs(Rewards) do
if table_matches(k, ReelRewards) then
Expand All @@ -122,16 +121,13 @@ RegisterNetEvent('dc-casino:slots:server:spin', function(ChosenBetAmount)
TriggerClientEvent('dc-casino:slots:client:spinreels', src, SpinTime, ReelRewards, NetworkGetNetworkIdFromEntity(BlurryReel1), NetworkGetNetworkIdFromEntity(BlurryReel2), NetworkGetNetworkIdFromEntity(BlurryReel3), NetworkGetNetworkIdFromEntity(Slots[src].Reel1), NetworkGetNetworkIdFromEntity(Slots[src].Reel2), NetworkGetNetworkIdFromEntity(Slots[src].Reel3), RewardMultiplier)
SetTimeout(SpinTime, function()
local RewardAmount = SlotReferences[SlotModel].betamounts[ChosenBetAmount] * RewardMultiplier
-- TriggerEvent('qb-log:server:CreateLog', 'casino', 'Casino Slots', 'green', string.format("**%s** (CitizenID: %s | ID: %s) - Spinned a casino slot for %s and won %s",
-- GetPlayerName(src), Player.PlayerData.citizenid, src, SlotReferences[SlotModel].betamounts[ChosenBetAmount], RewardAmount))
TriggerEvent('qb-log:server:CreateLog', 'casino', 'Casino Slots', 'green', string.format("**%s** (CitizenID: %s | ID: %s) - Spinned a casino slot for %s and won %s",
GetPlayerName(src), Player.PlayerData.citizenid, src, SlotReferences[SlotModel].betamounts[ChosenBetAmount], RewardAmount))
if RewardMultiplier == 0 then return end
---@diagnostic disable-next-line: empty-block
if UseCash and Player.Functions.AddMoney('cash', RewardAmount, 'Casino Slot Spin')
or UseBank and Player.Functions.AddMoney('bank', RewardAmount, 'Casino Slot Spin')
-- luacheck: ignore
or UseItem and Player.Functions.AddItem(ItemName, RewardAmount) then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items['casino_goldchip'], "add", RewardAmount)
-- TriggerClientEvent('QBCore:Notify', src, 'You won '..tonumber(RewardAmount)..' chips!', 'success')
end
or UseItem and Player.Functions.AddItem('casinochips', RewardAmount) then end
end)
end)

Expand All @@ -143,28 +139,4 @@ AddEventHandler("playerDropped", function()
LeaveSlot(source)
end)

-- PerformHttpRequest('https://api.github.com/repos/Disabled-Coding/dc-casino/releases/latest', function(_, resultData, _)
-- if not resultData then print('Failed to check for updates') return end
-- local result = json.decode(resultData)
-- if GetResourceMetadata(GetCurrentResourceName(), 'version') ~= result.tag_name then
-- print('New version of '..GetCurrentResourceName()..' is available!')
-- end
-- end)

local ItemList = {
["casino_goldchip"] = 1
}
QBCore.Functions.CreateCallback('doj:server:CasinoChipsAmount', function(source, cb)
local retval = 0
local Player = QBCore.Functions.GetPlayer(source)
if Player.PlayerData.items ~= nil and next(Player.PlayerData.items) ~= nil then
for k, v in pairs(Player.PlayerData.items) do
if Player.PlayerData.items[k] ~= nil then
if ItemList[Player.PlayerData.items[k].name] ~= nil then
retval = retval + (ItemList[Player.PlayerData.items[k].name] * Player.PlayerData.items[k].amount)
end
end
end
end
cb(retval)
end)
lib.versionCheck('ChatDisabled/dc-casino')

0 comments on commit e311079

Please sign in to comment.