Hello, i've made some changes to the default freeroam script so if a player tries to spawn a car while the player is in the despawn area, it will display a message that you can't spawn a vehicle in the despawn area and the vehicle is despawned.. However i have problems when i try to make if a vehicle enters the despawn area, it will be despawned.. can you help me? Here is the code:
local despawnArea = {x = -2280, y = 1694, z = 1522, width = 200, depth = 200, height = 200}
function isPlayerInDespawnArea(player)
local playerPosition = player.position
return playerPosition.x >= despawnArea.x and playerPosition.x <= despawnArea.x + despawnArea.width and
playerPosition.y >= despawnArea.y and playerPosition.y <= despawnArea.y + despawnArea.depth and
playerPosition.z >= despawnArea.z and playerPosition.z <= despawnArea.z + despawnArea.height
end
function createSelectedVehicle(leaf)
if not leaf then
leaf = getSelectedGridListLeaf(wndCreateVehicle, 'vehicles')
if not leaf then
return
end
end
if isPlayerInDespawnArea(localPlayer) then
outputChatBox("You cannot spawn a car in the despawn area.", 255, 0, 0)
return
end
server.giveMeVehicles(leaf.id)
end
wndCreateVehicle = {
'wnd',
text = 'Create vehicle',
width = 300,
controls = {
{
'lst',
id='vehicles',
width=280,
height=340,
columns={
{text='Vehicle', attr='name'}
},
rows={xml='data/vehicles.xml', attrs={'id', 'name'}},
onitemdoubleclick=createSelectedVehicle,
DoubleClickSpamProtected=true,
},
{'btn', id='create', onclick=createSelectedVehicle, ClickSpamProtected=true},
{'btn', id='close', closeswindow=true}
}
}
function createVehicleCommand(cmd, ...)
local args = {...}
if not ... then
return errMsg("Enter vehicle model please! Syntax: /cv [vehicle ID/name]")
end
vehID = getVehicleModelFromName(table.concat(args, " ")) or tonumber(args[1]) and math.floor(tonumber(args[1])) or false
if not vehID or not tostring(vehID) or not tonumber(vehID) then
return errMsg("Invalid vehicle model!")
end
if string.len(table.concat(args, " ")) > 25 or tonumber(vehID) and string.len(vehID) > 3 then
return errMsg("Invalid vehicle model!")
end
if vehID and vehID >= 400 and vehID <= 611 then
if isPlayerInDespawnArea(localPlayer) then
outputChatBox("You cannot spawn a car in the pvp area.", 255, 0, 0)
return
end
server.giveMeVehicles(vehID)
else
errMsg("Invalid vehicle model!")
end
end
addCommandHandler('createvehicle', createVehicleCommand)
addCommandHandler('cv', createVehicleCommand)