Wow, thats harder than i thought ...
I've made something wrong but ... what. The cars are spawned but the older isn't destroyed.
local playerData = {}
function getPlayerVehicle (player)
if playerData[player] then
return playerData[player].vehicle -- maybe you can just return this, but dunno if it triggers error
else
return nil
end
end
function createPlayerData (player)
if playerData[player] then
return
end
playerData[player] = {}
end
function destroyVehicle (player)
if playerData[player] then
if playerData[player].vehicle then
destroyElement (playerData[player].vehicle)
playerData[player].vehicle = nil
else
return false
end
end
end
addEvent ("carBuy", true)
addEventHandler ("carBuy", getRootElement(),
function(id2, cost2, name2,x, y, z, sRz, thePlayer)
if (getPlayerMoney (source) >= tonumber(cost2)) then
outputChatBox ("Achat de " .. name2, source, 255, 0, 0, false)
outputChatBox ("Prix: " .. cost2, source, 255, 0, 0, false)
takePlayerMoney (source, tonumber (cost2))
local x,y,z = getElementPosition (source)
local vehicle = createVehicle (id2, x, y, z, 0, 0, sRz )
destroyVehicle (player)
playerData[thePlayer].vehicle = createVehicle (vehicle)
warpPedIntoVehicle(source, vehicle)
local blii = createBlipAttachedTo ( vehicle, 56, source )
setElementVisibleTo ( blii, getRootElement ( ), false )
setElementVisibleTo ( blii, source, true )
else
outputChatBox ("Vous ne pouvez acheter ce produit [pas assez d'argent]", source, 255, 0, 0, false)
end
end)