mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-12-12 06:14:09 +01:00
gameplay: example money, money fountain, ped money drop and player ID systems
This commit is contained in:
41
resources/[gameplay]/[examples]/ped-money-drops/client.lua
Normal file
41
resources/[gameplay]/[examples]/ped-money-drops/client.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
AddEventHandler('gameEventTriggered', function(eventName, args)
|
||||
if eventName == 'CEventNetworkEntityDamage' then
|
||||
local victim = args[1]
|
||||
local culprit = args[2]
|
||||
local isDead = args[4] == 1
|
||||
|
||||
if isDead then
|
||||
local origCoords = GetEntityCoords(victim)
|
||||
local pickup = CreatePickupRotate(`PICKUP_MONEY_VARIABLE`, origCoords.x, origCoords.y, origCoords.z - 0.7, 0.0, 0.0, 0.0, 512, 0, false, 0)
|
||||
local netId = PedToNet(victim)
|
||||
|
||||
local undoStuff = { false }
|
||||
|
||||
CreateThread(function()
|
||||
local self = PlayerPedId()
|
||||
|
||||
while not undoStuff[1] do
|
||||
Wait(50)
|
||||
|
||||
if #(GetEntityCoords(self) - origCoords) < 2.5 and HasPickupBeenCollected(pickup) then
|
||||
TriggerServerEvent('money:tryPickup', netId)
|
||||
|
||||
RemovePickup(pickup)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
undoStuff[1] = true
|
||||
end)
|
||||
|
||||
SetTimeout(15000, function()
|
||||
if not undoStuff[1] then
|
||||
RemovePickup(pickup)
|
||||
undoStuff[1] = true
|
||||
end
|
||||
end)
|
||||
|
||||
TriggerServerEvent('money:allowPickupNear', netId)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,11 @@
|
||||
version '1.0.0'
|
||||
description 'An example money system client.'
|
||||
author 'Cfx.re <pr@fivem.net>'
|
||||
|
||||
fx_version 'bodacious'
|
||||
game 'gta5'
|
||||
|
||||
client_script 'client.lua'
|
||||
server_script 'server.lua'
|
||||
|
||||
lua54 'yes'
|
||||
42
resources/[gameplay]/[examples]/ped-money-drops/server.lua
Normal file
42
resources/[gameplay]/[examples]/ped-money-drops/server.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
local safePositions = {}
|
||||
|
||||
RegisterNetEvent('money:allowPickupNear')
|
||||
|
||||
AddEventHandler('money:allowPickupNear', function(pedId)
|
||||
local entity = NetworkGetEntityFromNetworkId(pedId)
|
||||
|
||||
Wait(250)
|
||||
|
||||
if not DoesEntityExist(entity) then
|
||||
return
|
||||
end
|
||||
|
||||
if GetEntityHealth(entity) > 100 then
|
||||
return
|
||||
end
|
||||
|
||||
local coords = GetEntityCoords(entity)
|
||||
safePositions[pedId] = coords
|
||||
end)
|
||||
|
||||
RegisterNetEvent('money:tryPickup')
|
||||
|
||||
AddEventHandler('money:tryPickup', function(entity)
|
||||
if not safePositions[entity] then
|
||||
return
|
||||
end
|
||||
|
||||
local source = source
|
||||
local playerPed = GetPlayerPed(source)
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
|
||||
if #(safePositions[entity] - coords) < 2.5 then
|
||||
exports['money']:addMoney(source, 'cash', 40)
|
||||
end
|
||||
|
||||
safePositions[entity] = nil
|
||||
end)
|
||||
|
||||
AddEventHandler('entityRemoved', function(entity)
|
||||
safePositions[entity] = nil
|
||||
end)
|
||||
Reference in New Issue
Block a user