mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 14:26:03 +01:00
Update main.lua
* Added a version checker. * Updated the method to find identifiers to make sure it always uses the license. * Updated "exitGame" event so it's vulnerable to modders. * Made code cleaner and optimized a little more.
This commit is contained in:
@@ -6,24 +6,78 @@
|
|||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
expectedName = "ND_Core" -- This is the resource and is not suggested to be changed.
|
||||||
|
resource = GetCurrentResourceName()
|
||||||
|
|
||||||
|
-- check if resource is renamed
|
||||||
|
if resource ~= expectedName then
|
||||||
|
print("^1[^4" .. expectedName .. "^1] WARNING^0")
|
||||||
|
print("Change the resource name to ^4" .. expectedName .. " ^0or else it won't work!")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check if resource version is up to date
|
||||||
|
PerformHttpRequest("https://raw.githubusercontent.com/Andyyy7666/ND_Framework/main/ND_Core/fxmanifest.lua", function(error, res, head)
|
||||||
|
i, j = string.find(tostring(res), "version")
|
||||||
|
res = string.sub(tostring(res), i, j + 6)
|
||||||
|
res = string.gsub(res, "version ", "")
|
||||||
|
res = string.gsub(res, '"', "")
|
||||||
|
resp = tonumber(res)
|
||||||
|
verFile = GetResourceMetadata(expectedName, "version", 0)
|
||||||
|
|
||||||
|
if verFile then
|
||||||
|
if tonumber(verFile) < resp then
|
||||||
|
print("^1[^4" .. expectedName .. "^1] WARNING^0")
|
||||||
|
print("^4" .. expectedName .. " ^0is outdated. Please update it from ^5https://github.com/Andyyy7666/ND_Framework ^0| Current Version: ^1" .. verFile .. " ^0| New Version: ^2" .. resp .. " ^0|")
|
||||||
|
elseif tonumber(verFile) > tonumber(resp) then
|
||||||
|
print("^1[^4" .. expectedName .. "^1] WARNING^0")
|
||||||
|
print("^4" .. expectedName .. "s ^0version number is higher than we expected. | Current Version: ^3" .. verFile .. " ^0| Expected Version: ^2" .. resp .. " ^0|")
|
||||||
|
else
|
||||||
|
print("^1[^4" .. expectedName .. "^1] WARNING^0")
|
||||||
|
print("^4" .. expectedName .. " ^0is up to date | Current Versin: ^2" .. verFile .. " ^0|")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("^1[^4" .. expectedName .. "^1] WARNING^0")
|
||||||
|
print("You may not have the latest version of ^4" .. expectedName .. "^0. A newer, improved version may be present at ^5https://github.com/Andyyy7666/ND_Framework^0")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Get player identifier function (This will not change the identifier all the time)
|
||||||
|
function GetPlayerIdentifierFromType(type, source) -- Credits: xander1998, Post: https://forum.cfx.re/t/solved-is-there-a-better-way-to-get-lic-steam-and-ip-than-getplayeridentifiers/236243/2?u=andyyy7666
|
||||||
|
local identifiers = {}
|
||||||
|
local identifierCount = GetNumPlayerIdentifiers(source)
|
||||||
|
|
||||||
|
for a = 0, identifierCount do
|
||||||
|
table.insert(identifiers, GetPlayerIdentifier(source, a))
|
||||||
|
end
|
||||||
|
|
||||||
|
for b = 1, #identifiers do
|
||||||
|
if string.find(identifiers[b], type, 1) then
|
||||||
|
return identifiers[b]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Using the IsRolePresent function from discord.lua to check if the player has the roles.
|
||||||
RegisterNetEvent("checkPerms")
|
RegisterNetEvent("checkPerms")
|
||||||
AddEventHandler("checkPerms", function(role)
|
AddEventHandler("checkPerms", function(role)
|
||||||
local player = source
|
local player = source
|
||||||
local role = role
|
|
||||||
local rolePermission = IsRolePresent(player, role)
|
local rolePermission = IsRolePresent(player, role)
|
||||||
TriggerClientEvent("permsChecked", player, role, rolePermission)
|
TriggerClientEvent("permsChecked", player, role, rolePermission)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Disconnecting a player
|
||||||
RegisterNetEvent("exitGame")
|
RegisterNetEvent("exitGame")
|
||||||
AddEventHandler("exitGame", function(Player)
|
AddEventHandler("exitGame", function()
|
||||||
DropPlayer(Player, "Disconnected using framework.")
|
local player = source
|
||||||
|
DropPlayer(player, "Disconnected using framework.")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Inserting the players characters into characters table
|
||||||
RegisterNetEvent("getCharacters")
|
RegisterNetEvent("getCharacters")
|
||||||
AddEventHandler("getCharacters", function()
|
AddEventHandler("getCharacters", function()
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("SELECT * FROM characters WHERE license = ?", {GetPlayerIdentifierFromType("license", player)}, function(result)
|
||||||
exports.oxmysql:execute("SELECT * FROM characters WHERE license = ?", {license}, function(result)
|
|
||||||
if result then
|
if result then
|
||||||
characters = {}
|
characters = {}
|
||||||
for i = 1, #result do
|
for i = 1, #result do
|
||||||
@@ -35,14 +89,15 @@ AddEventHandler("getCharacters", function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Creating a new character and increasing the character id.
|
||||||
RegisterNetEvent("newCharacter")
|
RegisterNetEvent("newCharacter")
|
||||||
AddEventHandler("newCharacter", function(newCharacter)
|
AddEventHandler("newCharacter", function(newCharacter)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
local license = GetPlayerIdentifierFromType("license", player)
|
||||||
exports.oxmysql:execute("SELECT MAX(character_id) AS nextID FROM characters WHERE license LIKE ?", {license}, function(result)
|
exports.oxmysql:execute("SELECT MAX(character_id) AS nextID FROM characters WHERE license = ?", {license}, function(result)
|
||||||
if result then
|
if result then
|
||||||
character_id = result[1].nextID
|
character_id = result[1].nextID
|
||||||
if character_id == nil then
|
if not character_id then
|
||||||
character_id = 1
|
character_id = 1
|
||||||
else
|
else
|
||||||
character_id = character_id + 1
|
character_id = character_id + 1
|
||||||
@@ -56,99 +111,59 @@ AddEventHandler("newCharacter", function(newCharacter)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Delete character from database.
|
||||||
RegisterNetEvent("delCharacter")
|
RegisterNetEvent("delCharacter")
|
||||||
AddEventHandler("delCharacter", function(character_id)
|
AddEventHandler("delCharacter", function(character_id)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("DELETE FROM characters WHERE license = ? AND character_id = ?", {GetPlayerIdentifierFromType("license", player), character_id})
|
||||||
exports.oxmysql:execute("DELETE FROM characters WHERE license LIKE ? AND character_id LIKE ?", {license, character_id}, function(id)
|
|
||||||
if id then
|
|
||||||
print(id)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Update the character info when edited.
|
||||||
RegisterNetEvent("editCharacter")
|
RegisterNetEvent("editCharacter")
|
||||||
AddEventHandler("editCharacter", function(newCharacter)
|
AddEventHandler("editCharacter", function(newCharacter)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("UPDATE characters SET first_name = ?, last_name = ?, dob = ?, gender = ?, twt = ?, department = ? WHERE license = ? AND character_id = ?", {newCharacter.firstName, newCharacter.lastName, newCharacter.dateOfBirth, newCharacter.gender, newCharacter.twtName, newCharacter.department, GetPlayerIdentifierFromType("license", player), newCharacter.id})
|
||||||
exports.oxmysql:execute("UPDATE characters SET first_name = ?, last_name = ?, dob = ?, gender = ?, twt = ?, department = ? WHERE license = ? AND character_id = ?", {newCharacter.firstName, newCharacter.lastName, newCharacter.dateOfBirth, newCharacter.gender, newCharacter.twtName, newCharacter.department, license, newCharacter.id}, function(id)
|
|
||||||
if id then
|
|
||||||
print(id)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if config.shotSpotterEnabled then
|
-- Planning on moving everything money related to server.
|
||||||
RegisterNetEvent("shotSpotterActive")
|
|
||||||
AddEventHandler("shotSpotterActive", function(x, y, z, postal)
|
|
||||||
TriggerClientEvent("shotSpotterReport", -1, x, y, z, postal)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
RegisterNetEvent("bankPay")
|
RegisterNetEvent("bankPay")
|
||||||
AddEventHandler("bankPay", function(characterid, playerid, amount, playerSending, name)
|
AddEventHandler("bankPay", function(characterid, playerid, amount, playerSending, name)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("UPDATE characters SET bank = bank - ? WHERE license = ? AND character_id = ?", {amount, GetPlayerIdentifierFromType("license", player), characterid})
|
||||||
exports.oxmysql:execute("UPDATE characters SET bank = bank - ? WHERE license = ? AND character_id = ?", {amount, license, characterid}, function(bank)
|
|
||||||
if bank then
|
|
||||||
print(bank)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
TriggerClientEvent("receiveBank", playerid, amount, playerSending, name)
|
TriggerClientEvent("receiveBank", playerid, amount, playerSending, name)
|
||||||
TriggerClientEvent("updateMoney", player)
|
TriggerClientEvent("updateMoney", player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("addBank")
|
RegisterNetEvent("addBank")
|
||||||
AddEventHandler("addBank", function(amount, characterid)
|
AddEventHandler("addBank", function(amount, characterid)
|
||||||
local player = source
|
local player = source
|
||||||
license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("UPDATE characters SET bank = bank + ? WHERE license = ? AND character_id = ?", {amount, GetPlayerIdentifierFromType("license", player), characterid})
|
||||||
exports.oxmysql:execute("UPDATE characters SET bank = bank + ? WHERE license = ? AND character_id = ?", {amount, license, characterid}, function(bank)
|
|
||||||
if bank then
|
|
||||||
print(bank)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
TriggerClientEvent("updateMoney", player)
|
TriggerClientEvent("updateMoney", player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("cashPay")
|
RegisterNetEvent("cashPay")
|
||||||
AddEventHandler("cashPay", function(characterid, playerid, amount, playerSending, name)
|
AddEventHandler("cashPay", function(characterid, playerid, amount, playerSending, name)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("UPDATE characters SET cash = cash - ? WHERE license = ? AND character_id = ?", {amount, GetPlayerIdentifierFromType("license", player), characterid})
|
||||||
exports.oxmysql:execute("UPDATE characters SET cash = cash - ? WHERE license = ? AND character_id = ?", {amount, license, characterid}, function(cash)
|
|
||||||
if cash then
|
|
||||||
print(cash)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
TriggerClientEvent("receiveCash", playerid, amount, playerSending, name)
|
TriggerClientEvent("receiveCash", playerid, amount, playerSending, name)
|
||||||
TriggerClientEvent("updateMoney", player)
|
TriggerClientEvent("updateMoney", player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent("addCash")
|
RegisterNetEvent("addCash")
|
||||||
AddEventHandler("addCash", function(amount, characterid)
|
AddEventHandler("addCash", function(amount, characterid)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("UPDATE characters SET cash = cash + ? WHERE license = ? AND character_id = ?", {amount, GetPlayerIdentifierFromType("license", player), characterid})
|
||||||
exports.oxmysql:execute("UPDATE characters SET cash = cash + ? WHERE license = ? AND character_id = ?", {amount, license, characterid}, function(cash)
|
|
||||||
if cash then
|
|
||||||
print(cash)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
TriggerClientEvent("updateMoney", player)
|
TriggerClientEvent("updateMoney", player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- This is used to find out how much money the player has and use it in the client to show it on the ui.
|
||||||
RegisterNetEvent("getMoney")
|
RegisterNetEvent("getMoney")
|
||||||
AddEventHandler("getMoney", function(characterid)
|
AddEventHandler("getMoney", function(characterid)
|
||||||
local player = source
|
local player = source
|
||||||
local license = GetPlayerIdentifier(player, 1)
|
exports.oxmysql:execute("SELECT cash, bank FROM characters WHERE license = ? AND character_id = ?", {GetPlayerIdentifierFromType("license", player), characterid}, function(result)
|
||||||
exports.oxmysql:execute("SELECT cash, bank FROM characters WHERE license = ? AND character_id = ?", {license, characterid}, function(result)
|
|
||||||
if result then
|
if result then
|
||||||
for i = 1, #result do
|
for i = 1, #result do
|
||||||
cash = result[i].cash
|
cash = result[i].cash
|
||||||
bank = result[i].bank
|
bank = result[i].bank
|
||||||
print(cash)
|
|
||||||
print(bank)
|
|
||||||
end
|
end
|
||||||
|
TriggerClientEvent("returnMoney", player, cash, bank)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
Citizen.Wait(300)
|
|
||||||
TriggerClientEvent("returnMoney", player, cash, bank)
|
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user