2022-02-26 23:19:00 +01:00
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
2022-07-08 23:24:04 +02:00
local selectedCharacter
local characterAmount = 0
function SetDisplay ( bool , typeName , bg )
if not bg then
background = config.backgrounds [ math.random ( 1 , # config.backgrounds )]
end
SetNuiFocus ( bool , bool )
SendNUIMessage ({
type = typeName ,
background = background ,
status = bool ,
serverName = config.serverName ,
characterAmount = characterAmount .. "/" .. config.characterLimit
})
end
function getCharacterInfo ()
return selectedCharacter
end
function start ( switch )
TriggerServerEvent ( "checkPerms" )
TriggerServerEvent ( "getCharacters" )
TriggerServerEvent ( "getAop" )
Citizen.Wait ( 100 )
if switch then
local ped = PlayerPedId ()
SwitchOutPlayer ( ped , 0 , 1 )
FreezeEntityPosition ( ped , true )
SetEntityVisible ( ped , false , 0 )
end
SendNUIMessage ({
type = "onStart" ,
enableMoneySystem = config.enableMoneySystem ,
maxStartingBank = config.maxStartingBank ,
maxStartingCash = config.maxStartingCash
})
end
AddEventHandler ( "onResourceStart" , function ( resourceName )
if ( GetCurrentResourceName () ~= resourceName ) then
return
end
Citizen.Wait ( 1000 )
start ( false )
end )
AddEventHandler ( "playerSpawned" , function ()
print ( "^0This framework is created by ^5Andyyy#7666 ^0for support you can join the ^5discord: ^0https://discord.gg/Z9Mxu72zZ6" )
start ( true )
end )
2021-12-23 22:40:54 +01:00
2021-12-24 23:27:09 +01:00
-- This is used to add department drop down on the ui.
2021-12-23 22:40:54 +01:00
RegisterNetEvent ( "permsChecked" )
2022-07-08 23:24:04 +02:00
AddEventHandler ( "permsChecked" , function ( allowedRoles )
for _ , dept in pairs ( allowedRoles ) do
2022-02-26 01:40:26 +01:00
SendNUIMessage ({
type = "givePerms" ,
2022-07-08 23:24:04 +02:00
deptRole = dept
2022-02-26 01:40:26 +01:00
})
2021-12-23 22:40:54 +01:00
end
end )
2022-07-08 23:24:04 +02:00
-- Notification when you recieve money.
RegisterNetEvent ( "receiveBank" )
AddEventHandler ( "receiveBank" , function ( amount , playerSending , playerId )
BeginTextCommandThefeedPost ( "STRING" )
AddTextComponentSubstringPlayerName ( "Received $" .. amount .. " from " .. playerSending .. " [" .. playerId .. "]" )
EndTextCommandThefeedPostMessagetext ( "CHAR_BANK_FLEECA" , "CHAR_BANK_FLEECA" , true , 9 , "FleecaBank" , "" )
2022-02-26 01:40:26 +01:00
end )
2022-07-08 23:24:04 +02:00
-- Notification when you receive cash.
RegisterNetEvent ( "receiveCash" )
AddEventHandler ( "receiveCash" , function ( amount , playerSending , playerId )
BeginTextCommandThefeedPost ( "STRING" )
AddTextComponentSubstringPlayerName ( playerSending .. " gave you $" .. amount .. "." )
EndTextCommandThefeedPostMessagetext ( "CHAR_DEFAULT" , "CHAR_DEFAULT" , true , 9 , playerSending .. " [" .. playerId .. "]" , "" )
2021-12-23 22:40:54 +01:00
end )
2022-07-08 23:24:04 +02:00
RegisterNetEvent ( "updateMoney" )
AddEventHandler ( "updateMoney" , function ( cash , bank )
selectedCharacter.cash = cash
selectedCharacter.bank = bank
2021-12-23 22:40:54 +01:00
end )
2022-07-08 23:24:04 +02:00
-- Gets all the characters and displays them on the ui.
2021-12-23 22:40:54 +01:00
RegisterNetEvent ( "returnCharacters" )
AddEventHandler ( "returnCharacters" , function ( characters )
2022-02-26 01:40:26 +01:00
characterAmount = 0
2022-01-10 00:56:58 +01:00
SendNUIMessage ({
type = "refresh"
})
2022-02-26 01:40:26 +01:00
for _ , character in pairs ( characters ) do
2021-12-23 22:40:54 +01:00
SendNUIMessage ({
type = "character" ,
2022-02-26 01:40:26 +01:00
id = character.id ,
firstName = character.firstName ,
lastName = character.lastName ,
dateOfBirth = character.dob ,
gender = character.gender ,
twtName = character.twt ,
department = character.department ,
startingCash = character.cash ,
startingBank = character.bank
2021-12-23 22:40:54 +01:00
})
2022-02-26 01:40:26 +01:00
characterAmount = characterAmount + 1
2021-12-23 22:40:54 +01:00
end
2022-01-10 00:56:58 +01:00
SetDisplay ( true , "ui" , background )
2021-12-23 22:40:54 +01:00
end )
2022-07-08 23:24:04 +02:00
-- Selecting a player from the iu.
RegisterNUICallback ( "setMainCharacter" , function ( data )
selectedCharacter = {
firstName = data.firstName ,
lastName = data.lastName ,
dob = data.dateOfBirth ,
gender = data.gender ,
twt = data.twtName ,
department = data.department ,
cash = data.startingCash ,
bank = data.startingBank ,
id = data.character
}
for _ , spawn in pairs ( config.spawns [ selectedCharacter.department ]) do
SendNUIMessage ({
type = "setSpawns" ,
x = spawn.x ,
y = spawn.y ,
z = spawn.z ,
name = spawn.name
})
end
TriggerServerEvent ( "characterOnline" , selectedCharacter.id )
TriggerEvent ( "characterChanged" , selectedCharacter )
end )
-- Creating a character from the ui.
2021-12-23 22:40:54 +01:00
RegisterNUICallback ( "newCharacter" , function ( data )
if characterAmount < config.characterLimit then
2022-07-08 23:24:04 +02:00
TriggerServerEvent ( "newCharacter" , {
2021-12-23 22:40:54 +01:00
firstName = data.firstName ,
lastName = data.lastName ,
dateOfBirth = data.dateOfBirth ,
gender = data.gender ,
twtName = data.twtName ,
department = data.department ,
startingCash = data.startingCash ,
startingBank = data.startingBank
2022-07-08 23:24:04 +02:00
})
2021-12-23 22:40:54 +01:00
end
end )
2022-07-08 23:24:04 +02:00
-- editing a character from the ui.
2021-12-23 22:40:54 +01:00
RegisterNUICallback ( "editCharacter" , function ( data )
2022-07-08 23:24:04 +02:00
TriggerServerEvent ( "editCharacter" , {
2021-12-23 22:40:54 +01:00
firstName = data.firstName ,
lastName = data.lastName ,
dateOfBirth = data.dateOfBirth ,
gender = data.gender ,
twtName = data.twtName ,
department = data.department ,
id = data.id
2022-07-08 23:24:04 +02:00
})
2021-12-23 22:40:54 +01:00
end )
2022-07-08 23:24:04 +02:00
-- deleting a character from the ui.
2021-12-23 22:40:54 +01:00
RegisterNUICallback ( "delCharacter" , function ( data )
TriggerServerEvent ( "delCharacter" , data.character )
characterAmount = characterAmount - 1
SendNUIMessage ({
characterAmount = characterAmount .. "/" .. config.characterLimit
})
end )
2022-07-08 23:24:04 +02:00
-- Quit button from ui.
RegisterNUICallback ( "exitGame" , function ( data )
TriggerServerEvent ( "exitGame" )
2021-12-23 22:40:54 +01:00
end )
2022-07-08 23:24:04 +02:00
-- Teleporting using ui.
2021-12-23 22:40:54 +01:00
RegisterNUICallback ( "tpToLocation" , function ( data )
local ped = PlayerPedId ()
FreezeEntityPosition ( ped , false )
SetEntityCoords ( ped , tonumber ( data.x ), tonumber ( data.y ), tonumber ( data.z ), false , false , false , false )
FreezeEntityPosition ( ped , true )
SwitchInPlayer ( ped )
Citizen.Wait ( 500 )
SetDisplay ( false , "ui" )
Citizen.Wait ( 500 )
FreezeEntityPosition ( ped , false )
SetEntityVisible ( ped , true , 0 )
2022-07-08 23:24:04 +02:00
TriggerServerEvent ( "getMoney" , selectedCharacter.id )
2021-12-23 22:40:54 +01:00
end )
2021-12-24 23:27:09 +01:00
-- Choosing the do not tp button.
2022-04-13 20:35:21 +02:00
RegisterNUICallback ( "tpDoNot" , function ()
2021-12-23 22:40:54 +01:00
local ped = PlayerPedId ()
SwitchInPlayer ( ped )
Citizen.Wait ( 500 )
SetDisplay ( false , "ui" )
Citizen.Wait ( 500 )
SetEntityVisible ( ped , true , 0 )
FreezeEntityPosition ( ped , false )
2022-07-08 23:24:04 +02:00
TriggerServerEvent ( "getMoney" , selectedCharacter.id )
2021-12-23 22:40:54 +01:00
end )
2022-07-09 16:18:33 -06:00
-- discord rich presence will show on a users profile.
if config.enableRichPresence then
2021-12-23 22:40:54 +01:00
Citizen.CreateThread ( function ()
while true do
SetDiscordAppId ( config.appId )
2022-07-08 23:24:04 +02:00
if selectedCharacter then
SetRichPresence ( " Playing : " .. config.serverName .. " as " .. selectedCharacter.firstName .. " " .. selectedCharacter.lastName )
2021-12-23 22:40:54 +01:00
SetDiscordRichPresenceAsset ( config.largeLogo )
SetDiscordRichPresenceAssetText ( "Playing: " .. config.serverName )
SetDiscordRichPresenceAssetSmall ( config.smallLogo )
2022-07-08 23:24:04 +02:00
SetDiscordRichPresenceAssetSmallText ( "Playing as: " .. selectedCharacter.firstName .. " " .. selectedCharacter.lastName )
2021-12-23 22:40:54 +01:00
SetDiscordRichPresenceAction ( 0 , config.firstButtonName , config.firstButtonLink )
SetDiscordRichPresenceAction ( 1 , config.secondButtonName , config.secondButtonLink )
end
2022-07-08 23:24:04 +02:00
Citizen.Wait ( config.updateIntervall * 1000 )
2021-12-23 22:40:54 +01:00
end
end )
end
2022-07-08 23:24:04 +02:00
-- show server name, first name, last name, and the amount of money the character has in the pause menu.
if config.customPauseMenu then
2021-12-23 22:40:54 +01:00
Citizen.CreateThread ( function ()
while true do
Citizen.Wait ( 0 )
2022-07-08 23:24:04 +02:00
if selectedCharacter then
2021-12-24 23:27:09 +01:00
if IsPauseMenuActive () then
BeginScaleformMovieMethodOnFrontendHeader ( "SET_HEADING_DETAILS" )
AddTextEntry ( "FE_THDR_GTAO" , config.serverName )
2022-07-08 23:24:04 +02:00
ScaleformMovieMethodAddParamPlayerNameString ( selectedCharacter.firstName .. " " .. selectedCharacter.lastName )
if config.enableMoneySystem then
PushScaleformMovieFunctionParameterString ( "Cash: $" .. tostring ( selectedCharacter.cash ))
PushScaleformMovieFunctionParameterString ( "Bank: $" .. tostring ( selectedCharacter.bank ))
2022-02-26 01:40:26 +01:00
end
2021-12-24 23:27:09 +01:00
EndScaleformMovieMethod ()
2021-12-23 22:40:54 +01:00
end
end
end
end )
end
2022-07-08 23:24:04 +02:00
-- Change character command
RegisterCommand ( config.changeCharacterCommand , function ()
SwitchOutPlayer ( PlayerPedId (), 0 , 1 )
Citizen.Wait ( 2000 )
FreezeEntityPosition ( ped , true )
SetEntityVisible ( ped , false , 0 )
SetDisplay ( true , "ui" )
end , false )
2022-01-10 00:56:58 +01:00
2022-07-08 23:24:04 +02:00
-- chat suggestions
TriggerEvent ( "chat:addSuggestion" , "/" .. config.changeCharacterCommand , "Switch your framework character." )
if config.enableMoneySystem then
TriggerEvent ( "chat:addSuggestion" , "/" .. config.payCommand , "Transfer money to player" , {{ name = "id" , help = "Player server id" }, { name = "amount" , help = "amount to pay" }})
TriggerEvent ( "chat:addSuggestion" , "/" .. config.giveCommand , "Give money to closeby player" , {{ name = "amount" , help = "amount to give" }})
2022-07-09 16:18:33 -06:00
end