Jump to content

Vehicle System


yMassai

Recommended Posts

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.

Link to comment
  • Moderators
local button = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Veiculo :", true, theWindow, 255, 0, 0) 
addEventHandler("onClientGUIClick", button, root, 
function () 
      local vehicle = getPedOccupiedVehicle(source) 
      if vehicle then 
          outputChatBox("your current vehicle is: "..getVehicleName(vehicle).."") 
      else 
          outputChatBox("you dont have any vehicle") 
      end 
end 
) 
  

Edited by Guest
Link to comment
  • Moderators
local button = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Veiculo:", true, theWindow, 255, 0, 0) 
addEventHandler("onClientGUIClick", button, root, 
function () 
      local vehicle = getPedOccupiedVehicle(source) 
      if vehicle then 
           guiSetText( button, "Veiculo: "..getVehicleName(vehicle).."" ) 
      else 
          guiSetText( button, "Veiculo: nenhum" ) 
      end 
end 
) 

not sure if it works.

Edited by Guest
Link to comment

GUIEditor_Label = {} 
  
theWindow = guiCreateWindow(300,200,250,200,"Sistema de Veiculos",false) 
guiWindowSetSizable(theWindow,false) 
guiSetVisible (theWindow, false) 
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
spawnBut = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Vehiculo :", true, theWindow, 255, 0, 0) 
guiCreateButton(0.005, 0.250, 0.6, 0.130, "Vehiculo :", true, theWindow, 255, 0, 0) 
guiCreateButton(0.005, 0.400, 0.6, 0.130, "Vehiculo :", true, theWindow, 255, 0, 0) 
guiCreateButton(0.650,0.100,0.3,0.2,"Trancar / Destrancar",true,theWindow) 
guiCreateButton(0.650,0.330,0.3,0.2,"Blip",true,theWindow) 
destroyBut = guiCreateButton(0.650,0.560,0.3,0.2,"Visivel / Invisivel",true,theWindow) 
guiCreateButton(0.005,0.560,0.3,0.2,"Vender",true,theWindow) 
guiCreateButton(0.345,0.560,0.3,0.2,"Seila",true,theWindow) 
guiCreateLabel(0.080, 0.780, 0.6, 0.2, "Tabela feita por Ninguem", true, theWindow, 255, 0, 0) 
addEventHandler("onClientGUIClick", spawnBut, root, 
function () 
      local vehicle = getPedOccupiedVehicle(source) 
      if vehicle then 
           guiSetText( spawnBut, "Veiculo: "..vehicle.."" ) 
      else 
          guiSetText( spawnBut, "Veiculo: nenhum" ) 
      end 
end 
) 
  
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) 

dont work

Link to comment
  • Moderators
GUIEditor_Label = {} 
  
theWindow = guiCreateWindow(300,200,250,200,"Sistema de Veiculos",false) 
guiWindowSetSizable(theWindow,false) 
guiSetVisible (theWindow, false) 
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
guiCreateButton(0.005, 0.250, 0.6, 0.130, "Vehiculo :", true, theWindow) 
guiCreateButton(0.005, 0.400, 0.6, 0.130, "Vehiculo :", true, theWindow) 
guiCreateButton(0.650,0.100,0.3,0.2,"Trancar / Destrancar",true,theWindow) 
guiCreateButton(0.650,0.330,0.3,0.2,"Blip",true,theWindow) 
destroyBut = guiCreateButton(0.650,0.560,0.3,0.2,"Visivel / Invisivel",true,theWindow) 
guiCreateButton(0.005,0.560,0.3,0.2,"Vender",true,theWindow) 
guiCreateButton(0.345,0.560,0.3,0.2,"Seila",true,theWindow) 
guiCreateLabel(0.080, 0.780, 0.6, 0.2, "Tabela feita por Ninguem", true, theWindow) 
function buttonLabel() 
local theVehicle = getPedOccupiedVehicle(localPlayer) 
    if ( theVehicle ) then 
        spawnBut1 = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Veiculo: "..getVehicleName(theVehicle).."", true, theWindow) 
        destroyElement(spawnBut2) 
    else 
        spawnBut2 = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Veiculo: nenhum", true, theWindow) 
        destroyElement(spawnBut1) 
    end 
end 
  
function refreshLabel() 
    setTimer(buttonLabel, 50, 1) 
end 
addEventHandler("onClientVehicleEnter", root, refreshLabel) 
addEventHandler("onClientVehicleExit", root, refreshLabel) 
addEventHandler("onClientResourceStart", root, refreshLabel) 
  
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 () 
  if (source == spawnBut1 or source == spawnBut2) then 
    triggerServerEvent ("carSpawn", getLocalPlayer()) 
  elseif (source == destroyBut) then 
    triggerServerEvent ("carDestroy", getLocalPlayer()) 
  end 
end 
addEventHandler ("onClientGUIClick", getRootElement(), guiClick) 

Edited by Guest
Link to comment
guiCreateButton(0.005, 0.400, 0.6, 0.130, "Vehiculo :", true, theWindow, 255, 0, 0) 

Is not correct, maximum is 7 arguments, you're using 10.

Corrected would be:

guiCreateButton(0.005, 0.400, 0.6, 0.130, "Vehiculo :", true, theWindow) 

Link to comment
function createGUI ( ) 
theWindow = guiCreateWindow(300,200,250,200,"Sistema de Veiculos",false) 
guiWindowSetSizable(theWindow,false) 
guiSetVisible (theWindow, false) 
guiCreateButton(0.650,0.100,0.3,0.2,"Trancar / Destrancar",true,theWindow) 
guiCreateButton(0.650,0.330,0.3,0.2,"Blip",true,theWindow) 
destroyBut = guiCreateButton(0.650,0.560,0.3,0.2,"Visivel / Invisivel",true,theWindow) 
guiCreateButton(0.005,0.560,0.3,0.2,"Vender",true,theWindow) 
guiCreateButton(0.345,0.560,0.3,0.2,"Seila",true,theWindow) 
guiCreateLabel(0.080, 0.780, 0.6, 0.2, "Tabela feita por Ninguem", true, theWindow) 
if ( getPedOccupiedVehicle ( localPlayer ) ) then 
        spawnBut = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Veiculo: "..getVehicleName(getPedOccupiedVehicle(localPlayer)).."", true, theWindow) 
    else 
        spawnBut = guiCreateButton(0.005, 0.100, 0.6, 0.130, "Veiculo: Nenhum", true, theWindow) 
    end 
end 
  
function refreshLabel() 
    setTimer(createGUI, 50, 1) 
end 
addEventHandler("onClientVehicleEnter", root, refreshLabel) 
addEventHandler("onClientVehicleExit", root, refreshLabel) 
addEventHandler("onClientResourceStart", root, refreshLabel) 
  
bindKey ( 'f3', 'down', 
    function ( ) 
        guiSetVisible ( theWindow, not guiGetVisible ( theWindow ) ) 
        showCursor ( not isCursorShowing ( ) ) 
    end 
) 
  
function guiClick ( ) 
    if ( source == spawnBut ) then 
        triggerServerEvent ("carSpawn", localPlayer) 
    elseif ( source == destroyBut ) then 
        triggerServerEvent ("carDestroy", localPlayer) 
    end 
end 
addEventHandler ("onClientGUIClick", root, guiClick) 

Link to comment
still has an error, the name "nenhum" is not replaced by the name of the vehicle.

the label has been updated for me, when I enter and leave the vehicle

Don't start saying that your code works for you. It's a total mess.

Link to comment
  • Moderators

I think you better test on some server before speaking it. the label is updated when the player enters and exits the vehicle, though the script needs to be corrected.

but I will not do it all for him. he can learn.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...