0% found this document useful (0 votes)
120 views

Message

This document contains Lua code for handling player spawns, updates, and state in a FiveM roleplaying server. When players spawn or respawn, it loads their saved customization, inventory, health and position data. On death, it clears certain saved data like phone directories. It also contains functions for updating a player's position, weapons, customization and health to save to their database profile.

Uploaded by

Matei Mandru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views

Message

This document contains Lua code for handling player spawns, updates, and state in a FiveM roleplaying server. When players spawn or respawn, it loads their saved customization, inventory, health and position data. On death, it clears certain saved data like phone directories. It also contains functions for updating a player's position, weapons, customization and health to save to their database profile.

Uploaded by

Matei Mandru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

local cfg = module("cfg/player_state")

local lang = vRP.lang


local cfg2 = module("cfg/police")

-- client -> server events


AddEventHandler("vRP:playerSpawn", function(user_id, source, first_spawn)
Debug.pbegin("playerSpawned_player_state")
local player = source
local data = vRP.getUserDataTable(user_id)
local tmpdata = vRP.getUserTmpTable(user_id)

if first_spawn then
if data.customization == nil then
data.customization = cfg.default_customization
end

if data.position == nil and cfg.spawn_enabled then


local x = cfg.spawn_position[1]+math.random()*cfg.spawn_radius*2-
cfg.spawn_radius
local y = cfg.spawn_position[2]+math.random()*cfg.spawn_radius*2-
cfg.spawn_radius
local z = cfg.spawn_position[3]+math.random()*cfg.spawn_radius*2-
cfg.spawn_radius
data.position = {x=x,y=y,z=z}
end

if data.position ~= nil then -- teleport to saved pos


vRPclient.teleport(source,
{data.position.x,data.position.y,data.position.z})
end

if data.customization ~= nil then


vRPclient.setCustomization(source,{data.customization},function()
if data.weapons ~= nil then
vRPclient.giveWeapons(source,{data.weapons,true})

if data.health ~= nil then -- set health


vRPclient.setHealth(source,{data.health})
SetTimeout(5000, function()
vRPclient.isInComa(player,{},
function(in_coma)
vRPclient.killComa(player,{})
end)
end)
end
end
end)
else
if data.weapons ~= nil then -- load saved weapons
vRPclient.giveWeapons(source,{data.weapons,true})
end

if data.health ~= nil then


vRPclient.setHealth(source,{data.health})
end
end
SetTimeout(15000,function()vRPclient.notify(player,
{lang.common.welcome({tmpdata.last_login})})end)
else
vRP.setHunger(user_id,0)
vRP.setThirst(user_id,0)

for ky,vl in pairs(data.inventory) do


local amount = vRP.getInventoryItemAmount(user_id,ky)
if tonumber(amount) > 0 then
if(string.match(ky, "wbody")) or (string.match(ky,
"wammo"))then
if
vRP.tryGetInventoryItem(user_id,ky,amount,false) then
vRPclient.notify(player,{"~r~Angajatii
spitalului au predat politiei toate obiectele ilegale gasite asupra ta!"})
end
end
end
end
vRPclient.giveWeapons(player, {{}, true})

for k,v in pairs(cfg2.seizable_items) do -- transfer seizable


items
local amount = vRP.getInventoryItemAmount(user_id,v)
if amount > 0 then
local item = vRP.items[v]
if item then -- do transfer
if
vRP.tryGetInventoryItem(user_id,v,amount,false) then
vRPclient.notify(player,{"~r~Angajatii
spitalului au predat politiei toate obiectele ilegale gasite asupra ta!"})
end
end
end
end
end

if cfg.clear_phone_directory_on_death then
data.phone_directory = {} -- clear phone directory after death
end

if cfg.lose_aptitudes_on_death then
data.gaptitudes = {} -- clear aptitudes after death
end

-- disable handcuff
vRPclient.setHandcuffed(player,{false})

-- load character customization


if data.customization ~= nil then
vRPclient.setCustomization(source,{data.customization})
end

Debug.pend()
end)

function vRP.setPlayerJob(user_id, theJob)


local tmp = vRP.getUserTmpTable(user_id)
if tmp then
tmp.job = tostring(theJob)
end
end

-- updates

AddEventHandler("vRP:playerLeave", function(user_id, thePlayer)


vRPclient.savePlayerCoords(thePlayer,{})
end)

function tvRP.updatePos(x,y,z)
local user_id = vRP.getUserId(source)
if user_id ~= nil then
local data = vRP.getUserDataTable(user_id)
local tmp = vRP.getUserTmpTable(user_id)
if data ~= nil and (tmp == nil or tmp.home_stype == nil) then -- don't
save position if inside home slot
data.position = {x = tonumber(x), y = tonumber(y), z = tonumber(z)}
end
end
end

function tvRP.updateWeapons(weapons)
local user_id = vRP.getUserId(source)
if user_id ~= nil then
local data = vRP.getUserDataTable(user_id)
if data ~= nil then
data.weapons = weapons
end
end
end

function tvRP.updateCustomization(customization)
local user_id = vRP.getUserId(source)
if user_id ~= nil then
local data = vRP.getUserDataTable(user_id)
if data ~= nil then
data.customization = customization
end
end
end

function tvRP.updateHealth(health)
local user_id = vRP.getUserId(source)
if user_id ~= nil then
local data = vRP.getUserDataTable(user_id)
if data ~= nil then
data.health = health
end
end
end

You might also like