function(id, cost, name)
if (getPlayerMoney (source) >= tonumber(cost)) then
outputChatBox ("Kupiles woz " .. name, source, 255, 0, 0, false)
outputChatBox ("ID pojazdu: " .. id, source, 255, 0, 0, false)
outputChatBox ("Koszt: " .. cost, source, 255, 0, 0, false)
takePlayerMoney (source, tonumber (cost))
setAccountData (getPlayerAccount (source), "funmodev2-car", tonumber(id))
setAccountData (getPlayerAccount (source), "funmodev2-paintjob", 3)
setAccountData (getPlayerAccount (source), "funmodev2-carupg", 0)
else
outputChatBox ("Nie posiadasz tyle kasy!", source, 255, 0, 0, false)
end
end)
addEvent ("carSpawn", true)
addEvent ("carDestroy", true)
function carSpawn ()
if not (isGuestAccount (getPlayerAccount (source))) and not (isPedInVehicle(source)) then
if (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) and (getElementType(getElementData (source, "hisCar")) == "vehicle") then
setElementVelocity (getElementData (source, "hisCar"), 0,0,0)
local x,y,z = getElementPosition (source)
setVehicleRotation (getElementData (source, "hisCar"), 0, 0, 0)
setElementPosition (getElementData (source, "hisCar"), x+2,y,z +1)
outputChatBox ("Car spawned.", source, 255, 0, 0)
elseif not (getElementData (source, "hisCar")) then
local accountData = getAccountData (getPlayerAccount (source), "funmodev2-car")
if (accountData) then
carID = getAccountData (getPlayerAccount (source), "funmodev2-car")
x,y,z = getElementPosition (source)
vehicle = createVehicle (carID, x +2, y, z +1)
setElementID (vehicle, getAccountName (getPlayerAccount(source)))
setElementData (source, "hisCar", vehicle)
outputChatBox ("Pojazd zespawnowany.", source, 255, 0, 0)
if (getAccountData (getPlayerAccount(source), "funmodev2-carupg")) then
local upgrades = nil
local upgrades = {}
local upgrades = getAccountData (getPlayerAccount(source), "funmodev2-carupg")
for i,v in ipairs (upgrades) do
addVehicleUpgrade (vehicle, v)
end
end
if (getAccountData (getPlayerAccount(source), "funmodev2-paintjob")) then
local paintjob = getAccountData (getPlayerAccount(source), "funmodev2-paintjob")
setVehiclePaintjob (vehicle, paintjob)
end
if (getAccountData (getPlayerAccount(source), "funmodev2-carcolor1")) and (getAccountData (getPlayerAccount(source), "funmodev2-carcolor2")) then
local c1 = getAccountData (getPlayerAccount(source), "funmodev2-carcolor1")
local c2 = getAccountData (getPlayerAccount(source), "funmodev2-carcolor2")
setVehicleColor (vehicle, c1,c2,0,0)
end
else
outputChatBox ("Nie posiadasz pojazdu.", source, 255, 0, 0)
end
else
outputChatBox ("Nie siedzisz w pojezdzie!", source, 255, 0, 0)
end
end
end
addEventHandler ("carSpawn", getRootElement(), carSpawn)
function carDestroy ()
if not (isGuestAccount (getPlayerAccount (source))) then
if (isPedInVehicle (source)) then
if (getElementID(getPedOccupiedVehicle(source)) == getAccountName (getPlayerAccount(source))) then
setElementHealth (getElementData (source, "hisCar"), 0)
destroyElement (getPedOccupiedVehicle (source))
removeElementData (source, "hisCar")
outputChatBox ("Pojazd odspawnowany.", source, 255, 0, 0)
else
outputChatBox ("To nie twoj pojazd!", source, 255, 0, 0)
end
elseif (not (isPedInVehicle (source))) and (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) then
car=getElementData(source, "hisCar")
destroyElement(car)
outputChatBox ("Pojazd odspawnowany.", source, 255, 0, 0)
removeElementData (source, "hisCar")
end
end
end
addEventHandler ("carDestroy", getRootElement(), carDestroy)