Jump to content

Would someone help me with this?


Pedro001

Recommended Posts

function loadOneVehicle(id)
	local queryHandle = dbQuery( connection, "SELECT * FROM vehicles WHERE id = " .. id )
	local queryResult, rows = dbPoll ( queryHandle , -1 )
	if rows > 0 then
		for k,row in pairs(queryResult) do
			loadedVehicle[id] = createVehicle(row.model, row.x, row.y, row.z, row.rx, row.ry, row.rz)
			if loadedVehicle[id] then
				local thex = tonumber(row.x) or 0
				if thex < -4125 then
					setElementData(loadedVehicle[id], "parked", false)
				else
					setElementData(loadedVehicle[id], "parked", true)
				end
				
				setElementHealth(loadedVehicle[id], row.health)
				setVehicleColor ( loadedVehicle[id], row.r, row.g, row.b, row.r1, row.g1, row.b1 )
				setVehicleHeadLightColor ( loadedVehicle[id], row.lightr, row.lightg, row.lightb )
				setElementData(loadedVehicle[id], "dbid", row.id)
				setElementData(loadedVehicle[id], "veh.owner", row.owner)
				setElementData(loadedVehicle[id], "veh.modelid", row.model)
				setElementData(loadedVehicle[id], "veh.fuelData", row.fuel)
				setElementData(loadedVehicle[id], "veh.engine", 0)
				setElementData(loadedVehicle[id], "veh.lights", 0)
				setElementData(loadedVehicle[id], "veh.x", row.x)
				setElementData(loadedVehicle[id], "veh.y", row.y)
				setElementData(loadedVehicle[id], "veh.z", row.z)
				
				setElementData(loadedVehicle[id], "veh.rx", row.rx)
				setElementData(loadedVehicle[id], "veh.ry", row.ry)
				setElementData(loadedVehicle[id], "veh.rz", row.rz)	
				setElementData(loadedVehicle[id], "veh.faction", row.faction)
				setElementData(loadedVehicle[id], "veh.airride", row.airride)	
				setElementData(loadedVehicle[id], "tuning.neon", row.neon)
				setElementData(loadedVehicle[id], "customhorn", row.paintjob)
			
				local bulletProofTires =  tostring(row.bulletProofTires) or false
				
				if bulletProofTires == "true" then
				setElementData(loadedVehicle[id], "tuning.bulletProofTires", true)
				else 
                setElementData(loadedVehicle[id], "tuning.bulletProofTires", false)
				end
				
				vehicleModel = loadedVehicle[id]
				local steeringLock =  row.steeringLock
				local driveType = tostring(row.driveType) or getVehicleHandling(vehicleModel)["steeringLock"]
				
				setVehicleHandling(loadedVehicle[id], "steeringLock", steeringLock, false)
				setVehicleHandling(loadedVehicle[id], "driveType", driveType, false)
				setElementData(loadedVehicle[id], "steeringLock", row.steeringLock)
				setElementData(loadedVehicle[id], "driveType", row.driveType)
				
				local lsdDoors =  tostring(row.lsdDoor) or false
				local airRideOn =  tostring(row.airRideOn) or false
				
				if airRideOn == "true" then
				setElementData(loadedVehicle[id], "tuning.airRide", true)
				else 
                setElementData(loadedVehicle[id], "tuning.airRide", false)
				end
				
				if lsdDoors == "true" then
				setElementData(loadedVehicle[id], "tuning.lsdDoor", true)
				else 
                setElementData(loadedVehicle[id], "tuning.lsdDoor", false)
				end
				
			function setVehicleHandlingFlags(vehicle, byte, value)
	            if vehicle then
		            local handlingFlags = string.format("%X", getVehicleHandling(vehicle)["handlingFlags"])
		            local reversedFlags = string.reverse(handlingFlags) .. string.rep("0", 8 - string.len(handlingFlags))
		            local currentByte, flags = 1, ""
		
		    for values in string.gmatch(reversedFlags, ".") do
			    if type(byte) == "table" then
				for _, v in ipairs(byte) do
					if currentByte == v then
						values = string.format("%X", tonumber(value))
					    end
				    end
			        else
				        if currentByte == byte then
					        values = string.format("%X", tonumber(value))
				        end
			        end		
			        flags = flags .. values
			        currentByte = currentByte + 1
		        end	
		            setVehicleHandling(vehicle, "handlingFlags", tonumber("0x" .. string.reverse(flags)), false)
	            end
            end
			
		        setVehicleHandlingFlags(loadedVehicle[id], 3, row.frontWheel)
		        setVehicleHandlingFlags(loadedVehicle[id], 4, row.rearWheel)
				setElementData(loadedVehicle[id], "frontWheel", row.frontWheel)
				setElementData(loadedVehicle[id], "rearWheel", row.rearWheel)
				
				if row.handbrake == 1 then
					setElementFrozen(loadedVehicle[id], true)
				end
				setElementData(loadedVehicle[id], "handbrake", row.handbrake)

				setElementData(loadedVehicle[id], "veh.locked", row.locked)
				if row.locked == 1 then
					setVehicleLocked(loadedVehicle[id], true)
				end
				
				if row.numberPlate == 0 then
				plate = row.id
				elseif row.numberPlate > 0 then
				plate = row.numberPlate
				end
				setVehicleFuelTankExplodable(loadedVehicle[id], false)
				setVehiclePlateText(loadedVehicle[id], " BPH-".. plate)
				
				if (tonumber(row.health)<=400) then
					setElementData(loadedVehicle[id], "veh.engineCrash", 1)
				else
					setElementData(loadedVehicle[id], "veh.engineCrash", 0)
				end
				setElementInterior(loadedVehicle[id], row.interior)
				setElementData(loadedVehicle[id], "veh.int", row.interior)	
				setElementDimension(loadedVehicle[id], row.dimension)
				setElementData(loadedVehicle[id], "veh.dim", row.dimension)	
						
				setVehicleEngineState(loadedVehicle[id], false)
						
				setVehicleRespawnPosition(loadedVehicle[id], row.x, row.y, row.z, row.rx, row.ry, row.rz)

				local upgrades = fromJSON(row.upgrades)
				for slot, upgrade in ipairs(upgrades) do
					if upgrade and tonumber(upgrade) > 0 then
						setElementData(loadedVehicle[id], "veh.upgrade"..slot, upgrade)
						addVehicleUpgrade(loadedVehicle[id], upgrade)
					end
				end
				
				local panelState = fromJSON(row.upgrades)
				for panel, state in ipairs(panelState) do
					if state and tonumber(state) > 0 then
						setVehiclePanelState(loadedVehicle[id], panel, state)
					end
				end
			   engine = row.engine
			   turbo = row.turbo
			   nitro = row.nitro
			   tires = row.tires
			   brakes = row.brakes
			   weightreduction = row.weightreduction
			   
			   setElementData(loadedVehicle[id], "tuning.engine", row.engine)
			   setElementData(loadedVehicle[id], "tuning.turbo", row.turbo)
			   setElementData(loadedVehicle[id], "tuning.nitroLevel", row.nitro)
			   setElementData(loadedVehicle[id], "tuning.tires", row.tires)
			   setElementData(loadedVehicle[id], "tuning.brakes", row.brakes)
			   setElementData(loadedVehicle[id], "tuning.weightreduction", row.weightreduction)
			   
			    dengineAcceleration = getVehicleHandling(vehicleModel)["engineAcceleration"]
			    dmaxVelocity = getVehicleHandling(vehicleModel)["maxVelocity"]
				dengineInertia = getVehicleHandling(vehicleModel)["engineInertia"]
			    dtractionMultiplier = getVehicleHandling(vehicleModel)["tractionMultiplier"]
			    dtractionLoss = getVehicleHandling(vehicleModel)["tractionLoss"]
				dbrakeDeceleration = getVehicleHandling(vehicleModel)["brakeDeceleration"]
			    dbrakeBias = getVehicleHandling(vehicleModel)["brakeBias"]
				dmass = getVehicleHandling(vehicleModel)["mass"]
				
				

			if engine == 1 then			    
			    setVehicleHandling(loadedVehicle[id], "engineAcceleration", nil, false)
			    setVehicleHandling(loadedVehicle[id], "maxVelocity", nil, false)
	        elseif engine == 2 then					
			    setVehicleHandling(loadedVehicle[id], "engineAcceleration", dengineAcceleration + 2, false)
				setVehicleHandling(loadedVehicle[id], "maxVelocity", dmaxVelocity + 10, false)
	        elseif engine == 3 then
			    setVehicleHandling(loadedVehicle[id], "engineAcceleration", dengineAcceleration + 6, false)
				setVehicleHandling(loadedVehicle[id], "maxVelocity", dmaxVelocity + 20, false)
	        elseif engine == 4 then			
			    setVehicleHandling(loadedVehicle[id], "engineAcceleration", dengineAcceleration + 8, false)
				setVehicleHandling(loadedVehicle[id], "maxVelocity", dmaxVelocity + 30, false)
	        end
			

			if turbo == 1 then
			    setVehicleHandling(loadedVehicle[id], "engineInertia", nil, false)
	        elseif turbo == 2 then					
				setVehicleHandling(loadedVehicle[id], "engineInertia", dengineInertia - 10, false)
	        elseif turbo == 3 then
				setVehicleHandling(loadedVehicle[id], "engineInertia", dengineInertia - 20, false)
	        elseif turbo == 4 then			
				setVehicleHandling(loadedVehicle[id], "engineInertia", dengineInertia - 30, false)
	        end			
			

			if tires == 1 then
			    setVehicleHandling(loadedVehicle[id], "tractionMultiplier", nil, false)
			    setVehicleHandling(loadedVehicle[id], "tractionLoss", nil, false)
	        elseif tires == 2 then					
			    setVehicleHandling(loadedVehicle[id], "tractionMultiplier", dtractionMultiplier + 0.05, false)
				setVehicleHandling(loadedVehicle[id], "tractionLoss", dtractionLoss + 0.02, false)
	        elseif tires == 3 then
			    setVehicleHandling(loadedVehicle[id], "tractionMultiplier", dtractionMultiplier + 0.1, false)
				setVehicleHandling(loadedVehicle[id], "tractionLoss", dtractionLoss + 0.03, false)
	        elseif tires == 4 then			
			    setVehicleHandling(loadedVehicle[id], "tractionMultiplier", dtractionMultiplier + 0.15, false)
				setVehicleHandling(loadedVehicle[id], "tractionLoss", dtractionLoss + 0.04, false)
	        end			
			

			if brakes == 1 then
			    setVehicleHandling(loadedVehicle[id], "brakeDeceleration", nil, false)
			    setVehicleHandling(loadedVehicle[id], "brakeBias", nil, false)
	        elseif brakes == 2 then					
			    setVehicleHandling(loadedVehicle[id], "brakeDeceleration", dbrakeDeceleration + 0.05, false)
				setVehicleHandling(loadedVehicle[id], "brakeBias", dbrakeBias + 0.1, false)
	        elseif brakes == 3 then
			    setVehicleHandling(loadedVehicle[id], "brakeDeceleration", dbrakeDeceleration + 0.1, false)
				setVehicleHandling(loadedVehicle[id], "brakeBias", dbrakeBias + 0.175, false)
	        elseif brakes == 4 then			
			    setVehicleHandling(loadedVehicle[id], "brakeDeceleration", dbrakeDeceleration + 0.15, false)
				setVehicleHandling(loadedVehicle[id], "brakeBias", dbrakeBias + 0.25, false)
	        end			
	
			if weightreduction == 1 then			    
			    setVehicleHandling(loadedVehicle[id], "mass", nil, false)
	        elseif weightreduction == 2 then					
				setVehicleHandling(loadedVehicle[id], "mass", dmass - 100, false)
	        elseif weightreduction == 3 then
				setVehicleHandling(loadedVehicle[id], "mass", dmass - 200, false)
	        elseif weightreduction == 4 then			
				setVehicleHandling(loadedVehicle[id], "mass", dmass - 300, false)
	        end	
	
				exports.vz_handling:loadHandling(loadedVehicle[id])
			end
		end
	end
end



function loadAllVehicle()
  setTimer(function()
    exports.vz_handling:loadHandlings()
   end, 5000, 1)
	dbQuery(
		function (queryHandler)
			local result, numAffectedRows, errorMsg = dbPoll(queryHandler, 0)
			if numAffectedRows > 0 then
				for k,row in pairs(result) do
					loadOneVehicle(row.id)
				end
			end
		end,
		connection,
		"SELECT * FROM vehicles"
	)
end
addEventHandler("onResourceStart", resourceRoot, loadAllVehicle)

Would someone please help me with this thing. Every time I start this script, all the cars spawn at the same time, I can't get to understand it. Please help me, I need it so bad! 

Link to comment
13 hours ago, Pedro001 said:

Would someone please help me with this thing.

 

11 hours ago, IIYAMA said:

Scripting/resource requests should be posted in resources

@IIYAMAI believe you misunderstood the thread and moved it to the incorrect location, this man was asking for help, someone could make small changes to the code and he'd be set. He isn't asking for a whole resource, nor displaying one.

  • Like 1
Link to comment
  • Moderators
1 hour ago, ShayF said:

I believe you misunderstood

You are correct in general, but not this time since the following unwillingness applies to Pedro001 for all scripting posts that I have seen until this far:

Quote

The Scripting section is not meant for those unwilling to learn, whose only intent is to try get others to finish the scripts they need, line by line. We see this happening way too often -  someone with seemingly zero scripting skills does not react on-topic to the set of functions they can use that other users provide them, and does not seem to take any pushes in the right direction forward; they are just waiting for a collective effort from other scripters to develop what they want. This is what we do not want to see.

Therefore it is considered as a scripting request. Please prove me otherwise if I made the wrong decision.

Feel free to help him with his request, it is not as if the topic is locked.

 

Edited by IIYAMA
Link to comment

I never asked for an entire resource in this forum, Everytime I posted something here was asking for help, never to ask someone to do something for me. 

The headline of the scripting section says "All Lua scripting topics related to Multi Theft Auto"  Also, there is an "importante note" about posting something in the scripting section, which says. It must contain specific questions about either:

  • the code you will include that is problematic or you are asking direct support for, or
  • asking for help in finding the best approach to achieve something (which I did every single time) Just asked for help, not to someone do something for me, or to share a script.

That is the only reason I always posted in this section, since the guide says, this section is indeed to ask for help. 

But I'm sorry @IIYAMA , it was not a question of unwillingness, I only did what I believed was right following the rules I read in this forum. 

And thank you @ShayF,  for understanding what I did. I appreciate it.

Link to comment
  • Moderators
1 hour ago, Pedro001 said:

Everytime I posted something here was asking for help, never to ask someone to do something for me.

How is that even possible, when you can't script and never ask pure scripting related questions nor showing a bit of interest? Doesn't that mean that the only thing the helper can do, is doing it for you? Think about it.

 

1 hour ago, Pedro001 said:

I only did what I believed was right following the rules I read in this forum. 

Read it again, since you clearly mist something.

 

You can request here for fixing resources, which is in your case the right match, don't you think?

Link to comment
  • Administrators

The Scripting Section is for receiving guidance and assistance with code. Given you have taken the code from existing resources online, it explains why you're not able to debug it yourself. You were previously warned against adding hundreds of lines of code to your threads as it isn't reasonable to ask others to debug entire resources for you.

On 23/06/2020 at 11:07, Pedro001 said:

I'm not a programmer y'know, I found the resource on a free website. I see that there's a file that should be the databese I suppose, but seems like it's not working. 

 

Going forwards please utilise the Looking for staff section for hiring programmers or learn debugging!

Link to comment
  • Tut locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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