Gui S
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 ("Car spawned.", 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 ("You haven't got a car.", source, 255, 0, 0)
end
else
outputChatBox ("You're already in a car!", 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 ("Car Destroyed.", source, 255, 0, 0)
else
outputChatBox ("This not your car!", source, 255, 0, 0)
end
elseif (not (isPedInVehicle (source))) and (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) then
setElementHealth (getElementData (source, "hisCar"), 0)
outputChatBox ("Car Destroyed.", source, 255, 0, 0)
removeElementData (source, "hisCar")
end
end
end
addEventHandler ("carDestroy", getRootElement(), carDestroy)
addEventHandler ("onVehicleExplode", getRootElement(),
function()
local theOwner = getAccountName (getPlayerAccount(getPlayerFromName (getElementID (source))))
if (theOwner) then
removeElementData (theOwner, "hisCar")
end
end)
addEventHandler ("onPlayerQuit", getRootElement(),
function(quitType, reason, responsibleElement)
if (getElementData (source, "hisCar")) then
blowVehicle (getElementData (source, "hisCar"))
removeElementData (source, "hisCar")
end
end)
addEventHandler( "onResourceStop", getResourceRootElement( getThisResource() ),
function ()
for i,v in ipairs (getElementsByType ("player")) do
if (getElementData (v, "hisCar")) then
setElementHealth (getElementData (v, "hisCar"), 0)
removeElementData (v, "hisCar")
end
end
end
)
function destroyOnExplode ()
setTimer (destroyElement, 2500, 1, source)
end
addEventHandler ("onVehicleExplode", getRootElement(), destroyOnExplode)
gui
GUIEditor_Label = {}
theWindow = guiCreateWindow(600,200,200,70,"Car Features",false)
guiWindowSetSizable(theWindow,false)
guiSetVisible (theWindow, false)
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false)
guiSetFont(GUIEditor_Label[1],"default-bold-small")
spawnBut = guiCreateButton(0.0604,0.320,0.4,0.6,"Spawn",true,theWindow)
destroyBut = guiCreateButton(0.490,0.320,0.4,0.6,"Destroy",true,theWindow)
function resourceStart ()
bindKey ("F3", "down", menuShow)
end
addEventHandler ("onClientResourceStart", getResourceRootElement ( getThisResource () ), resourceStart)
function menuShow ()
visableornot = guiGetVisible (theWindow)
if (visableornot == true) then
guiSetVisible (theWindow, false)
showCursor (false)
end
if (visableornot == false) then
guiSetVisible (theWindow, true)
showCursor (true)
end
end
addEvent ("carSpawn", true)
addEvent ("carDestroy", true)
function guiClick (button, state, absoluteX, absoluteY)
if (source == spawnBut) then
triggerServerEvent ("carSpawn", getLocalPlayer())
elseif (source == destroyBut) then
triggerServerEvent ("carDestroy", getLocalPlayer())
end
end
addEventHandler ("onClientGUIClick", getRootElement(), guiClick)
this https://community.multitheftauto.com/index.php?p=resources&s=details&id=2604
This script is basic and good.
But I would like to edit some things but not know how.
We can see that in the "F3", vehiculo is destroyed.
I would ask someone to swap to disappear and not destroy.
I also ask someone colocase button to lock and unlock the vehicle "F3", do an identification vehicle, and a button to sell the vehicle.
This script has a flaw, it allows them to buy several cars and does not save the last.
I would ask that only had room for three cars.