Skip to content

Commit

Permalink
Add mz-skills to Config
Browse files Browse the repository at this point in the history
Some General Linting, fixes for RNG and implemented Gated Level requirements and rewards for skill sytems.
  • Loading branch information
DonHulieo committed Mar 10, 2023
1 parent 731bc48 commit 04fccba
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 48 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ Jewellery Robbery for QBCore with 1 or 3 stores, Thermite, VarHack and auto-lock
## Dependencies

- [qb-core](https://github.com/qbcore-framework/qb-core)
- [qb-doorlock](https://github.com/qbcore-framework/qb-doorlock)
- [qb-target](https://github.com/qbcore-framework/qb-target)
- [ps-ui](https://github.com/Project-Sloth/ps-ui)

### *Optional Dependancies*

- [ps-dispatch](https://github.com/Project-Sloth/ps-dispatch)
- [qb-policejob](https://github.com/qbcore-framework/qb-policejob)
- [cd_dispatch](https://forum.cfx.re/t/paid-codesign-police-dispatch/2007097)
- [qb-doorlock](https://github.com/qbcore-framework/qb-doorlock)
- [ox_doorlock](https://github.com/overextended/ox_doorlock)
- [cd_doorlock](https://forum.cfx.re/t/paid-codesign-door-lock/5005862)
- [mz-skills](https://github.com/MrZainRP/mz-skills)

## New Features

Expand Down Expand Up @@ -114,13 +118,13 @@ Config.Dispatch = 'ps' --[[ 'ps' for ps-dispatch, 'qb' for base qb-policejob ale
- The cooldown is the time (in minutes) the doors will auto lock after a hack.
- The timeout is the time (in minutes) the cases will reset after smashing.
- If `Config.AutoLock` is set to false, the doors will always be unlocked.
- Set `Config.DoorLock` to 'qb' if using qb-doorlocks, 'ox' if using ox_doorlock. Make sure to uncomment '@ox_lib/init.lua' from the fxmanifest.lua if using ox.
- The required cops is the amount of cops online required for the store to be "thievable".
- Set `Config.Dispatch` to; 'ps' for ps-dispatch, 'qb' for base qb-policejob alerts, 'cd' for cd_dispatch.

#### 1.3. Door Locks

```lua

Config.DoorLock = 'qb' --[[ Doorlock System ]]--

Config.Stores = {
Expand Down Expand Up @@ -186,6 +190,33 @@ Config.VarHackSettings = {
- The hack item is the item you want to *check* for when hacking.
- The var hack settings are the settings for the variable hack.

#### 1.6. Skills

```lua
Config.Skills = {
enabled = false, -- Enable Skills
system = 'mz-skills',
['Thermite'] = {
skill = 'Heist Reputation', -- Skill to Use
['Limits'] = {
xp = 800 -- XP Required to do the Task
},
['Rewards'] = {
xp = 10, -- XP to give on success
multi = 1.5 -- Multiplier Based on Players Level
}
},
...
}
```

- Set `Config.Skills.enabled` to true to enable skills.
- Set `Config.Skills.system` to the name of the skills system you are using.
- Set `Config.Skills.[Task].skill` to the name of the skill you want to use.
- Set `Config.Skills.[Task].Limits.xp` to the amount of xp required to do the task.
- Set `Config.Skills.[Task].Rewards.xp` to the amount of xp you want to give on success.
- Set `Config.Skills.[Task].Rewards.multi` to the multiplier based on the players level/ current xp.

### 2. Door Configs

- Make a copy of the door config below and place it inside `qb-doorlocks/configs/` in it's own .lua file.
Expand Down
94 changes: 68 additions & 26 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ local function loadAnimDict(dict)
repeat Wait(0) until HasAnimDictLoaded(dict)
end

local function randumNum(min, max)
local function randomNum(min, max)
math.randomseed(GetGameTimer())
local num = math.random() * (max - min) + min
if num % 1 >= 0.5 and math.ceil(num) <= max then
return math.ceil(num)
else
return math.floor(num)
end
return math.floor(num)
end

local function isStoreHit(vitrine, isStore)
Expand Down Expand Up @@ -227,11 +226,33 @@ local function alertsCD(alertType)
end
end

local function checkSkill(hack)
local retval = false
local skill = exports[Config.Skills.system]:GetCurrentSkill(Config.Skills[hack].skill)
local currXP = skill['Current']
local reqXP = Config.Skills[hack]['Limits'].xp
if currXP >= reqXP then
retval = true
end
return retval
end

local function addSkillToPlayer(hack)
local reward = Config.Skills[hack]['Rewards'].xp
local multi = Config.Skills[hack]['Rewards'].multi
local skill = exports[Config.Skills.system]:GetCurrentSkill(Config.Skills[hack].skill)
local currXP = skill['Current']
if currXP <= 0 then currXP = 1 end
local xp = math.floor(reward * multi * (currXP * 0.001))
if xp < reward then xp = reward end
exports[Config.Skills.system]:UpdateSkill(Config.Skills[hack].skill, xp)
end

-------------------------------- HANDLERS --------------------------------

AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.TriggerCallback('don-jewellery:server:GetJewelleryState', function(result)
Config.Locations = result.Locations
Config.Vitrines = result.Locations
Config.Stores = result.Hacks
end)
local blip = GetFirstBlipInfoId(617)
Expand All @@ -241,8 +262,8 @@ AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
end)

AddEventHandler('QBCore:Client:OnPlayerUnload', function()
for i = 1, #Config.Locations do
if Config.Locations[i].isBusy then
for i = 1, #Config.Vitrines do
if Config.Vitrines[i].isBusy then
TriggerServerEvent('don-jewellery:server:SetVitrineState', false, i)
end
end
Expand All @@ -251,8 +272,8 @@ end)

AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then return end
for i = 1, #Config.Locations do
if Config.Locations[i].isBusy then
for i = 1, #Config.Vitrines do
if Config.Vitrines[i].isBusy then
TriggerServerEvent('don-jewellery:server:SetVitrineState', false, i)
end
end
Expand All @@ -262,8 +283,8 @@ end)

AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end
for i = 1, #Config.Locations do
if Config.Locations[i].isBusy then
for i = 1, #Config.Vitrines do
if Config.Vitrines[i].isBusy then
TriggerServerEvent('don-jewellery:server:SetVitrineState', false, i)
end
end
Expand All @@ -274,21 +295,28 @@ end)
AddEventHandler('don-jewellery:client:SmashCase', function(case)
QBCore.Functions.TriggerCallback('don-jewellery:server:GetCops', function(cops)
if not checkTime(Config.VangelicoHours.range.open, Config.VangelicoHours.range.close) then
if not Config.Locations[case]['isOpened'] then
if not Config.Vitrines[case].isOpened then
if Config.Skills.enabled then
if not checkSkill('Vitrine') then
QBCore.Functions.Notify(Lang:t('error.skill_fail', {value = Config.Skills['Vitrine'].skill}), 'error')
return
end
end
if cops >= Config.RequiredCops then
if isStoreHit(case, false) or isStoreHacked() then
local animDict = 'missheist_jewel'
local animName = 'smash_case'
local ped = PlayerPedId()
local plyCoords = GetOffsetFromEntityInWorldCoords(ped, 0, 0.6, 0)
local pedWeapon = GetSelectedPedWeapon(ped)
if randumNum(1, 100) <= 80 and not isWearingHandshoes() then
if randomNum(1, 100) <= 80 and not isWearingHandshoes() then
TriggerServerEvent('evidence:server:CreateFingerDrop', plyCoords)
elseif randumNum(1, 100) <= 5 and isWearingHandshoes() then
elseif randomNum(1, 100) <= 5 and isWearingHandshoes() then
TriggerServerEvent('evidence:server:CreateFingerDrop', plyCoords)
QBCore.Functions.Notify(Lang:t('error.fingerprints'), 'error')
end
smashing = true
if Config.Skills.enabled then addSkillToPlayer('Vitrine') end
QBCore.Functions.Progressbar('smash_vitrine', Lang:t('info.smashing_progress'), Config.WhitelistedWeapons[pedWeapon].timeOut, false, true, {
disableMovement = true,
disableCarMovement = true,
Expand Down Expand Up @@ -344,9 +372,9 @@ AddEventHandler('don-jewellery:client:SmashCase', function(case)
end)

AddEventHandler('don-jewellery:client:Thermite', function(store)
local AlertChance = randumNum(1, 100)
local AlertChance = randomNum(1, 100)
if checkTime(Config.VangelicoHours.alertmorn.start, Config.VangelicoHours.alertmorn.fin) or checkTime(Config.VangelicoHours.alertnight.start, Config.VangelicoHours.alertnight.fin) then
AlertChance = randumNum(1, 50)
AlertChance = randomNum(1, 50)
else
AlertChance = AlertChance
end
Expand All @@ -364,10 +392,16 @@ AddEventHandler('don-jewellery:client:Thermite', function(store)

QBCore.Functions.TriggerCallback('don-jewellery:server:GetCops', function(cops)
if not checkTime(Config.VangelicoHours.range.open, Config.VangelicoHours.range.close) then
if Config.Skills.enabled then
if not checkSkill('Thermite') then
QBCore.Functions.Notify(Lang:t('error.skill_fail', {value = Config.Skills['Thermite'].skill}), 'error')
return
end
end
if cops >= Config.RequiredCops then
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local printChance = randumNum(1, 100)
local printChance = randomNum(1, 100)
local dist = #(coords - Config.Stores[store]['Thermite'].coords)
if dist <= 1.5 then
if QBCore.Functions.HasItem(Config.DoorItem) then
Expand Down Expand Up @@ -406,6 +440,7 @@ AddEventHandler('don-jewellery:client:Thermite', function(store)
ClearPedTasks(ped)

Wait(100)
if Config.Skills.enabled then addSkillToPlayer('Thermite') end
loadPtfx('scr_ornate_heist')
local termcoords = GetEntityCoords(thermal_charge)
local effect = StartParticleFxLoopedAtCoord('scr_heist_ornate_thermal_burn', termcoords.x, termcoords.y + 1.0, termcoords.z, 0, 0, 0, 0x3F800000, 0, 0, 0, 0)
Expand Down Expand Up @@ -445,6 +480,12 @@ end)
AddEventHandler('don-jewellery:client:HackSecurity', function()
QBCore.Functions.TriggerCallback('don-jewellery:server:GetCops', function(cops)
if not checkTime(Config.VangelicoHours.range.open, Config.VangelicoHours.range.close) then
if Config.Skills.enabled then
if not checkSkill('Hack') then
QBCore.Functions.Notify(Lang:t('error.skill_fail', {value = Config.Skills['Hack'].skill}), 'error')
return
end
end
if cops >= Config.RequiredCops then
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
Expand All @@ -466,14 +507,15 @@ AddEventHandler('don-jewellery:client:HackSecurity', function()
end
end
end)
-- if randumNum(1, 100) <= 80 and not isWearingHandshoes() then
-- if randomNum(1, 100) <= 80 and not isWearingHandshoes() then
-- TriggerServerEvent("evidence:server:CreateFingerDrop", targetPosition)
-- elseif randumNum(1, 100) <= 5 and isWearingHandshoes() then
-- elseif randomNum(1, 100) <= 5 and isWearingHandshoes() then
-- TriggerServerEvent("evidence:server:CreateFingerDrop", targetPosition)
-- end
Wait(2500)
exports['ps-ui']:VarHack(function(success)
if success then
if Config.Skills.enabled then addSkillToPlayer('Hack') end
hacking = false
TriggerServerEvent('don-jewellery:server:StoreHit', 'all', true)
Wait(250)
Expand Down Expand Up @@ -552,13 +594,13 @@ end)
-------------------------------- EVENTS --------------------------------

RegisterNetEvent('don-jewellery:client:SetVitrineState', function(stateType, state, k)
Config.Locations[k][stateType] = state
Config.Vitrines[k][stateType] = state
if stateType == 'isBusy' and state == true then
CreateModelSwap(Config.Locations[k].coords, 0.1, Config.Locations[k].propStart, Config.Locations[k].propEnd, false)
CreateModelSwap(Config.Vitrines[k].coords, 0.1, Config.Vitrines[k].propStart, Config.Vitrines[k].propEnd, false)
end

if stateType == 'isOpened' and state == false then
RemoveModelSwap(Config.Locations[k].coords, 0.1, Config.Locations[k].propStart, Config.Locations[k].propEnd, false)
RemoveModelSwap(Config.Vitrines[k].coords, 0.1, Config.Vitrines[k].propStart, Config.Vitrines[k].propEnd, false)
end
end)

Expand All @@ -579,7 +621,7 @@ end)
-------------------------------- TARGET --------------------------------

if not Config.OneStore then
for k, v in pairs(Config.Locations) do
for k, v in pairs(Config.Vitrines) do
exports['qb-target']:AddBoxZone('jewelstore' .. k, v.coords, 1, 1, {
name = 'jewelstore' .. k,
heading = 40,
Expand Down Expand Up @@ -633,11 +675,11 @@ if not Config.OneStore then
end
else
for i = 1, 20, 1 do
exports['qb-target']:AddBoxZone('jewelstore' .. i, Config.Locations[i].coords, 1, 1, {
exports['qb-target']:AddBoxZone('jewelstore' .. i, Config.Vitrines[i].coords, 1, 1, {
name = 'jewelstore' .. i,
heading = 40,
minZ = Config.Locations[i].coords.z - 1,
maxZ = Config.Locations[i].coords.z + 1,
minZ = Config.Vitrines[i].coords.z - 1,
maxZ = Config.Vitrines[i].coords.z + 1,
debugPoly = false
},
{
Expand All @@ -657,7 +699,7 @@ else
end
end,
canInteract = function()
if Config.Locations[i].isOpened or Config.Locations[i].isBusy then return false end
if Config.Vitrines[i].isOpened or Config.Vitrines[i].isBusy then return false end
return true
end,
}
Expand Down
45 changes: 41 additions & 4 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ Config.VangelicoHours = { -- Store Hours
}
}

Config.Dispatch = 'ps' --[[ Police Dispatch System
Config.Dispatch = 'ps' -- Police Dispatch System
--[[
Set to 'ps' for police-script
Set to 'qb' for base qb-policejob alerts
Set to 'cd' for cd_policealerts ]
Set to 'cd' for cd_policealerts
]]--

Config.DoorLock = 'qb' --[[ Doorlock System
Config.DoorLock = 'qb' -- Doorlock System
--[[
Set to 'qb' for qb-doorlock
// Create a file named `jewellery_stores` in qb-doorlock/config/ and copy the Door Config from the README into it.
Set to 'ox' for ox_doorlock
Expand Down Expand Up @@ -182,7 +184,42 @@ Config.VitrineRewards = {
}
}

Config.Locations = {
Config.Skills = {
enabled = false, -- Enable Skills
system = 'mz-skills',
['Thermite'] = {
skill = 'Heist Reputation', -- Skill to Use
['Limits'] = {
xp = 800 -- XP Required to do the Task
},
['Rewards'] = {
xp = 10, -- XP to give on success
multi = 1.5 -- Multiplier Based on Players Level
}
},
['Hack'] = {
skill = 'Hacking',
['Limits'] = {
xp = 1600
},
['Rewards'] = {
xp = 25,
multi = 2.5
}
},
['Vitrine'] = {
skill = 'Heist Reputation',
['Limits'] = {
xp = 0
},
['Rewards'] = {
xp = 5,
multi = 1.25
}
}
}

Config.Vitrines = {
[1] = {
coords = vector3(-626.83, -235.35, 38.05),
isOpened = false,
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ game 'gta5'

author 'DonHulieo'
description 'Jewellery Store Heist for QBCore'
version '1.2.9'
version '1.3.0'

shared_scripts {
-- '@ox_lib/init.lua',
Expand Down
3 changes: 2 additions & 1 deletion locale/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ local Translations = {
wrong_item = 'You don\'t have the right item..',
too_far = 'You\'re too far away..',
stores_open = 'I should try after the store closes..',
fail_hack = 'You failed to hack the security system..'
fail_hack = 'You failed to hack the security system..',
skill_fail = 'Your %{value} skill is not high enough..'
},
success = {
thermite = 'You applied the thermite correctly..',
Expand Down
Loading

0 comments on commit 04fccba

Please sign in to comment.