All Snippets
Lua Snippet
Server-Side Entity Lockdown Spawning
Description & Usage
Avoids client-side vehicle spawning (which is vulnerable to injection exploits). The server creates the vehicle entity, assigns State Bags, and routes the network ID to the client.
Source Code (1 File)
| 1 | -- SERVER-SIDE |
| 2 | RegisterNetEvent('core:server:spawnVehicle', function(modelHash, coords, heading) |
| 3 | local src = source |
| 4 | local ped = GetPlayerPed(src) |
| 5 | local pCoords = GetEntityCoords(ped) |
| 6 | |
| 7 | -- Sanity check: prevent client from triggering distant spawn coordinates |
| 8 | if #(pCoords - coords) > 20.0 then return end |
| 9 | |
| 10 | local veh = CreateVehicleServerSetter(modelHash, 'automobile', coords.x, coords.y, coords.z, heading) |
| 11 | |
| 12 | while not DoesEntityExist(veh) do Wait(0) end |
| 13 | |
| 14 | -- Set entity state bag & network ownership |
| 15 | Entity(veh).state:set('owner', src, true) |
| 16 | Entity(veh).state:set('fuel', 100, true) |
| 17 | |
| 18 | local netId = NetworkGetNetworkIdFromEntity(veh) |
| 19 | TriggerClientEvent('core:client:vehicleReady', src, netId) |
| 20 | end) |
0 likes ·Sign in to like
Community Discussion (0)
Sign in to join the discussion and leave a comment.
Snippet Info
LanguageLua
Lines20
Chars766
Likes0