Jump to content

[HELP] How to save vehicule upgrades ?


chevaliern0ir

Recommended Posts

Hi guys :)

 

I'm running this script on my server --> https://community.multitheftauto.com/index.php?p=resources&s=details&id=2604

The ressource is great but it doesnt save tuning (vehiculeUpgrades) ! I'm trying to modifiy the code with getVehicleUpgrades but it doesn't work even if i think i wrote the correct syntax ! I don't want that somebody make a code for me but  can someone lead me in the right way ?

+ how do i set vehicule upgrades if setVehiculeUpgradedoesnt exist ?

xoxo :ph34r:

Code without modification

Spoiler

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 ("Vous n'avez pas de véhicle!", source, 255, 0, 0)
      end
    else
      outputChatBox ("Vous êtes déjà dans un véhicule!", 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 ("Voiture détruite", source, 255, 0, 0)
      else
        outputChatBox ("Ce n'est pas votre voiture!", 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 ("Voiture détruite", source, 255, 0, 0)
      removeElementData (source, "hisCar")
    end
  end
end
addEventHandler ("carDestroy", getRootElement(), carDestroy)

 

 

Edited by chevaliern0ir
Link to comment

Thank you IIYama i read your post and i tried that but the upgrades still don't save, where am i wrong ?  line 5, 48, 57

Mycode

Spoiler

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
      for i = 0, 16 do
        local upgrade = getVehicleUpgradeOnSlot (source, i)
        if ( upgrade ) then
          addVehicleUpgrade (source, i)
        end
      end
      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-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 ("Vous n'avez pas de véhicle!", source, 255, 0, 0)
      end
    else
      outputChatBox ("Vous êtes déjà dans un véhicule!", 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
        setElementData (getVehicleUpgrades( source, "hisCar" ))
        setElementHealth (getElementData (source, "hisCar"), 0)
        destroyElement (getPedOccupiedVehicle (source))
        removeElementData (source, "hisCar")
        outputChatBox ("Voiture détruite", source, 255, 0, 0)
      else
        outputChatBox ("Ce n'est pas votre voiture!", source, 255, 0, 0)
      end
    elseif (not (isPedInVehicle (source))) and (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) then
	  car=getElementData(source, "hisCar") and setElementData (getVehicleUpgrades (source, "hisCar"))
	  destroyElement(car)
      outputChatBox ("Voiture détruite", source, 255, 0, 0)
      removeElementData (source, "hisCar")
    end
  end
end
addEventHandler ("carDestroy", getRootElement(), carDestroy)

 

 

Edited by chevaliern0ir
Link to comment
  • Moderators

Line 5.

      for i = 0, 16 do
        local upgrade = getVehicleUpgradeOnSlot (source, i)
        if ( upgrade ) then
          addVehicleUpgrade (source, i)
        end
      end

What do you want to do here? Because I doubt this is what you want.

 

Maybe something like this:

local upgrades = getElementData (source, "upgrades")
if upgrades and type(upgrades) == "table" then
	iprint("upgrades found")
	for i=1, #upgrades do
		if upgrades[i] then
			addVehicleUpgrade (source, upgrades[i])
		end
	end
else
	iprint("no upgrades found")
end

(of course you need to set the elementdata first before this is going to work)

Untested

 


Line 48.

Please check the syntax of setElementData. You have now filled in one argument, but you need to fill in at least 3.

https://wiki.multitheftauto.com/wiki/SetElementData

 


Line 57.

local car = getElementData(source, "hisCar") and setElementData (getVehicleUpgrades (source, "hisCar"))

 

 

 

 

Edited by IIYAMA
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...