forked from Simnation/Main
neue sachen
This commit is contained in:
parent
e542e77789
commit
b992cdcfef
119 changed files with 5522 additions and 0 deletions
54
resources/[test]/qs-weed/server/custom/framework/esx.lua
Normal file
54
resources/[test]/qs-weed/server/custom/framework/esx.lua
Normal file
|
@ -0,0 +1,54 @@
|
|||
if Config.Framework ~= 'esx' then
|
||||
return
|
||||
end
|
||||
|
||||
ESX = exports['es_extended']:getSharedObject()
|
||||
|
||||
RegisterNetEvent('esx:playerLoaded', function(id, data)
|
||||
Wait(2000)
|
||||
Debug('Loaded player:', id)
|
||||
CreateQuests(id)
|
||||
end)
|
||||
|
||||
CreateThread(function()
|
||||
for k, v in pairs(ESX.Players) do
|
||||
if v and v.source then
|
||||
Debug('Loaded player:', v.source)
|
||||
CreateQuests(v.source)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function RegisterServerCallback(name, cb)
|
||||
ESX.RegisterServerCallback(name, cb)
|
||||
end
|
||||
|
||||
function RegisterUsableItem(name, cb)
|
||||
ESX.RegisterUsableItem(name, cb)
|
||||
end
|
||||
|
||||
function GetPlayerFromId(source)
|
||||
return ESX.GetPlayerFromId(source)
|
||||
end
|
||||
|
||||
function GetItem(player, item)
|
||||
return player.getInventoryItem(item)
|
||||
end
|
||||
|
||||
function AddItem(source, item, count)
|
||||
local player = GetPlayerFromId(source)
|
||||
local success = player.addInventoryItem(item, count)
|
||||
if GetResourceState('ox_inventory'):find('started') then
|
||||
Debug('ox_inventory add item success:::', success)
|
||||
return success
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
---@param source string
|
||||
---@param item string
|
||||
---@param count number
|
||||
function RemoveItem(source, item, count)
|
||||
local player = GetPlayerFromId(source)
|
||||
player.removeInventoryItem(item, count)
|
||||
end
|
47
resources/[test]/qs-weed/server/custom/framework/qb.lua
Normal file
47
resources/[test]/qs-weed/server/custom/framework/qb.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
if Config.Framework ~= 'qb' then
|
||||
return
|
||||
end
|
||||
|
||||
QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
|
||||
local src = source
|
||||
CreateQuests(src)
|
||||
end)
|
||||
|
||||
CreateThread(function()
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
if v then
|
||||
Debug('Loaded player:', v)
|
||||
CreateQuests(v)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function RegisterServerCallback(name, cb)
|
||||
QBCore.Functions.CreateCallback(name, cb)
|
||||
end
|
||||
|
||||
function RegisterUsableItem(name, cb)
|
||||
QBCore.Functions.CreateUseableItem(name, cb)
|
||||
end
|
||||
|
||||
function GetPlayerFromId(source)
|
||||
return QBCore.Functions.GetPlayer(source)
|
||||
end
|
||||
|
||||
function GetItem(player, item)
|
||||
local data = player.Functions.GetItemByName(item)
|
||||
data.count = data.amount
|
||||
return data
|
||||
end
|
||||
|
||||
function AddItem(source, item, count)
|
||||
local player = GetPlayerFromId(source)
|
||||
return player.Functions.AddItem(item, count)
|
||||
end
|
||||
|
||||
function RemoveItem(source, item, count, slot)
|
||||
local player = GetPlayerFromId(source)
|
||||
player.Functions.RemoveItem(item, count, slot)
|
||||
end
|
44
resources/[test]/qs-weed/server/custom/framework/qbx.lua
Normal file
44
resources/[test]/qs-weed/server/custom/framework/qbx.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
if Config.Framework ~= 'qbx' then
|
||||
return
|
||||
end
|
||||
|
||||
QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
|
||||
local src = source
|
||||
CreateQuests(src)
|
||||
end)
|
||||
|
||||
CreateThread(function()
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
if v then
|
||||
Debug('Loaded player:', v)
|
||||
CreateQuests(v)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function RegisterServerCallback(name, cb)
|
||||
QBCore.Functions.CreateCallback(name, cb)
|
||||
end
|
||||
|
||||
function RegisterUsableItem(name, cb)
|
||||
exports.qbx_core:CreateUseableItem(name, cb)
|
||||
end
|
||||
|
||||
function GetPlayerFromId(source)
|
||||
return exports.qbx_core:GetPlayer(source)
|
||||
end
|
||||
|
||||
function GetItem(player, item)
|
||||
local data = exports.ox_inventory:GetItem(player.PlayerData.source, item, nil, false)
|
||||
return data
|
||||
end
|
||||
|
||||
function AddItem(source, item, count)
|
||||
exports.ox_inventory:AddItem(source, item, count)
|
||||
end
|
||||
|
||||
function RemoveItem(source, item, count)
|
||||
exports.ox_inventory:RemoveItem(source, item, count)
|
||||
end
|
104
resources/[test]/qs-weed/server/custom/framework/standalone.lua
Normal file
104
resources/[test]/qs-weed/server/custom/framework/standalone.lua
Normal file
|
@ -0,0 +1,104 @@
|
|||
if Config.Framework ~= 'standalone' then
|
||||
return
|
||||
end
|
||||
|
||||
local oxHas = GetResourceState('ox_inventory') == 'started'
|
||||
|
||||
-- ESX Callbacks
|
||||
local serverCallbacks = {}
|
||||
|
||||
local clientRequests = {}
|
||||
local RequestId = 0
|
||||
|
||||
---@param eventName string
|
||||
---@param callback function
|
||||
RegisterServerCallback = function(eventName, callback)
|
||||
serverCallbacks[eventName] = callback
|
||||
end
|
||||
|
||||
exports('RegisterServerCallback', RegisterServerCallback)
|
||||
|
||||
RegisterNetEvent('weed:triggerServerCallback', function(eventName, requestId, invoker, ...)
|
||||
if not serverCallbacks[eventName] then
|
||||
return print(('[^1ERROR^7] Server Callback not registered, name: ^5%s^7, invoker resource: ^5%s^7'):format(eventName, invoker))
|
||||
end
|
||||
|
||||
local source = source
|
||||
|
||||
serverCallbacks[eventName](source, function(...)
|
||||
TriggerClientEvent('weed:serverCallback', source, requestId, invoker, ...)
|
||||
end, ...)
|
||||
end)
|
||||
|
||||
---@param player number playerId
|
||||
---@param eventName string
|
||||
---@param callback function
|
||||
---@param ... any
|
||||
TriggerClientCallback = function(player, eventName, callback, ...)
|
||||
clientRequests[RequestId] = callback
|
||||
|
||||
TriggerClientEvent('weed:triggerClientCallback', player, eventName, RequestId, GetInvokingResource() or 'unknown', ...)
|
||||
|
||||
RequestId = RequestId + 1
|
||||
end
|
||||
|
||||
RegisterNetEvent('weed:clientCallback', function(requestId, invoker, ...)
|
||||
if not clientRequests[requestId] then
|
||||
return print(('[^1ERROR^7] Client Callback with requestId ^5%s^7 Was Called by ^5%s^7 but does not exist.'):format(requestId, invoker))
|
||||
end
|
||||
|
||||
clientRequests[requestId](...)
|
||||
clientRequests[requestId] = nil
|
||||
end)
|
||||
|
||||
function RegisterUsableItem(name, cb)
|
||||
ImplementError('RegisterUsableItem is not supported with standalone')
|
||||
return false
|
||||
end
|
||||
|
||||
function GetPlayerFromId(source)
|
||||
return {
|
||||
source = source,
|
||||
identifier = GetIdentifier(source)
|
||||
}
|
||||
end
|
||||
|
||||
function GetPlayerFromIdentifier(identifier)
|
||||
identifier = string.gsub(identifier, ' ', '')
|
||||
local players = GetPlayers()
|
||||
for k, v in pairs(players) do
|
||||
if GetIdentifier(v) == identifier then
|
||||
return {
|
||||
source = v,
|
||||
identifier = identifier
|
||||
}
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function GetIdentifier(source)
|
||||
ImplementError('Get Identifier : You need to implement this function for your framework.')
|
||||
for k, v in pairs(GetPlayerIdentifiers(source)) do
|
||||
if string.sub(v, 1, string.len('license:')) == 'license:' then
|
||||
return v:gsub('license:', '')
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function GetItem(player, item)
|
||||
ImplementError('GetItem : You need to implement this function for your framework.')
|
||||
return true
|
||||
end
|
||||
|
||||
function AddItem(source, item, count)
|
||||
ImplementError('AddItem : You need to implement this function for your framework.')
|
||||
end
|
||||
|
||||
function RemoveItem(source, item, count, slot)
|
||||
if oxHas then
|
||||
return exports.ox_inventory:RemoveItem(source, item, count, nil)
|
||||
end
|
||||
ImplementError('RemoveItem : You need to implement this function for your framework.')
|
||||
end
|
54
resources/[test]/qs-weed/server/custom/missions.lua
Normal file
54
resources/[test]/qs-weed/server/custom/missions.lua
Normal file
|
@ -0,0 +1,54 @@
|
|||
function CreateQuests(source)
|
||||
if GetResourceState('qs-inventory') ~= 'started' then
|
||||
Debug('qs-inventory not started, skipping weed quest creation.')
|
||||
return
|
||||
end
|
||||
|
||||
local quest1 = exports['qs-inventory']:createQuest(source, {
|
||||
name = 'plant_weed_home',
|
||||
title = 'Green Beginnings',
|
||||
description = 'Plant your first weed plant inside your house.',
|
||||
reward = 200,
|
||||
requiredLevel = 1
|
||||
})
|
||||
|
||||
local quest2 = exports['qs-inventory']:createQuest(source, {
|
||||
name = 'feed_weed_home',
|
||||
title = 'Plant Caretaker',
|
||||
description = 'Give nutrition to a weed plant growing in your house.',
|
||||
reward = 150,
|
||||
requiredLevel = 1
|
||||
})
|
||||
|
||||
local quest3 = exports['qs-inventory']:createQuest(source, {
|
||||
name = 'harvest_weed_home',
|
||||
title = 'First Harvest',
|
||||
description = 'Harvest your first batch of home-grown weed.',
|
||||
reward = 300,
|
||||
requiredLevel = 2
|
||||
})
|
||||
|
||||
local quest4 = exports['qs-inventory']:createQuest(source, {
|
||||
name = 'remove_dead_plant',
|
||||
title = 'Clean Grower',
|
||||
description = 'Remove a dead weed plant from your house.',
|
||||
reward = 150,
|
||||
requiredLevel = 1
|
||||
})
|
||||
|
||||
local quest5 = exports['qs-inventory']:createQuest(source, {
|
||||
name = 'move_weed_plant',
|
||||
title = 'Rearranging Nature',
|
||||
description = 'Move a weed plant to a new position inside your house.',
|
||||
reward = 150,
|
||||
requiredLevel = 1
|
||||
})
|
||||
|
||||
Debug('Weed quests assigned to player:', source, {
|
||||
plant_weed_home = quest1,
|
||||
feed_weed_home = quest2,
|
||||
harvest_weed_home = quest3,
|
||||
remove_dead_plant = quest4,
|
||||
move_weed_plant = quest5
|
||||
})
|
||||
end
|
BIN
resources/[test]/qs-weed/server/main.lua
Normal file
BIN
resources/[test]/qs-weed/server/main.lua
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue