Jump to content

Help me please Create car loading is Mysql


Vadlmok

Recommended Posts

Help me please.
Write system one, booting (Mysql) works perfectly, in dialogs. So, I create a car, use the function "onVehicleStartEnter", the game shows me the Network Trouble.
Thanks for the tips

 

farmdata[id]["Combaine"] = createVehicle(532, farmdata[id]["x532"], farmdata[id]["y532"], farmdata[id]["z532"])

function enterVehicle ( thePlayer, seat, jacked )
  if farmdata[id]["Combaine"] then
    if farmdata[id]["Id"] ~= getElementData(thePlayer,"fjobs") then
      removePedFromVehicle ( thePlayer )
      outputChatBox ( "Вы не фермер!", thePlayer,255,255,255,true)
    end
  end
end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )

 

And for some reason does not work check 

if farmdata[id]["Combaine"] then

 

Link to comment
3 minutes ago, stPatrick said:

Paste the full script.

local Max_Farm = 4
local id_farm = {}
local farmdata = {}
local veh = {}
local dbpTime = 500
local ids = 0
local user_player = root
function loadfarm()
	local query = dbQuery(connect_db, "SELECT * FROM farm;" )
	local result, numrows = dbPoll(query, dbpTime)
	outputServerLog("_________________Load to farm_________________")
	if (result and numrows > 0) then
		for index, row in pairs(result) do
			local id = row['ID']
			local owner = row['Owner']
			local zowner1 = row['zOwner1']
			local zowner2 = row['zOwner2']
			local zowner3 = row['zOwner3']
			local farmer1 = row['Farmer1']
			local farmer2 = row['Farmer2']
			local farmer3 = row['Farmer3']
			local farmer4 = row['Farmer4']
			local farmer5 = row['Farmer5']
			local balance = row['Balance']
			local pricejob = row['PriceJob']
			local buycorn = row['BuyCorn']
			local cornsklad = row['CornSklad']
			local cornplant = row['CornPlant']
			local sellprod = row['SellProd']
			local prodsklad = row['ProdSklad']
			local priceprod = row['PriceProd']
			local car1prod = row['Car1Prod']
			local car2prod = row['Car2Prod']
			local posx = row['Posx']
			local posy = row['Posy']
			local posz = row['Posz']
			local posxinfo = row['Posxinf']
			local posyinfo = row['Posyinf']
			local poszinfo = row['Poszinf']
			local x532 = row['532x']
			local y532 = row['532y']
			local z532 = row['532z']
			outputServerLog("Farm number "..id.." is loaded!")
			ids = ids+1
			CreateFarm(id, owner, zowner1,zowner2,zowner3,farmer1,farmer2,farmer3,farmer4,farmer5,balance,pricejob,buycorn,cornsklad,cornplant,sellprod,prodsklad,priceprod,car1prod,car2prod,posx,posy,posz,posxinfo,posyinfo,poszinfo,x532,y532,z532)
		end
		dbFree(query)
	else
		error("Houses Table not Found/empty!")
	end
	outputServerLog("Farm load: "..ids)
	outputServerLog("_________________End Load to farm_________________")
end
addEventHandler("onResourceStart",resourceRoot,loadfarm)

function CreateFarm(id, owner, zowner1,zowner2,zowner3,farmer1,farmer2,farmer3,farmer4,farmer5,balance,pricejob,buycorn,cornsklad,cornplant,sellprod,prodsklad,priceprod,car1prod,car2prod,posx,posy,posz,posxinfo,posyinfo,poszinfo,x532,y532,z532)
	if(id) then
		id_farm[id] = createColSphere(posx,posy,posz, 1.5)
		farmdata[id] = {} 
		local farm = id_farm[id]
		setElementData(farm, "farm", true)
		createPickup(posx,posy,posz, 3, 1318, 100)
		createPickup(posxinfo,posyinfo,poszinfo, 3, 1239, 100)
		farmdata[id]["infocols"] = createColSphere(posxinfo,posyinfo,poszinfo, 1.5)
		createBlip(posx, posy, posz, 56, 2, 255, 0, 0, 255, 0, 250)

		farmdata[id]["Id"] = id
		farmdata[id]["Owner"] = owner
		farmdata[id]["zOwner1"] = zowner1
		farmdata[id]["zOwner2"] = zowner2
		farmdata[id]["zOwner3"] = zowner3
		farmdata[id]["Farmer1"] = farmer1
		farmdata[id]["Farmer2"] = farmer2
		farmdata[id]["Farmer3"] = farmer3
		farmdata[id]["Farmer4"] = farmer4
		farmdata[id]["Farmer5"] = farmer5
		farmdata[id]["Balance"] = balance
		farmdata[id]["PriceJob"] = pricejob
		farmdata[id]["BuyCorn"] = buycorn
		farmdata[id]["CornSklad"] = cornsklad
		farmdata[id]["CornPlant"] = cornplant
		farmdata[id]["SellProd"] = sellprod
		farmdata[id]["ProdSklad"] = prodsklad
		farmdata[id]["PriceProd"] = priceprod
		farmdata[id]["Car1Prod"] = car1prod
		farmdata[id]["Car2Prod"] = car2prod
		farmdata[id]["x532"] = x532
		farmdata[id]["y532"] = y532
		farmdata[id]["z532"] = z532
		
		farmdata[id]["Combaine"] = createVehicle(532, farmdata[id]["x532"], farmdata[id]["y532"], farmdata[id]["z532"])

		function enterVehicle ( thePlayer, seat, jacked )
		  if farmdata[id]["Combaine"] then
		    if farmdata[id]["Id"] ~= getElementData(thePlayer,"fjobs") then
		      removePedFromVehicle ( thePlayer )
		      outputChatBox ( "Вы не фермер!", thePlayer,255,255,255,true)
		    end
		  end
		end
		addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle )
		
		function enterVehicles ( thePlayer, seat, jacked )
			if farmdata[id]["Combaine"] and getElementModel ( getPedOccupiedVehicle(thePlayer) ) == 532 then
				if farmdata[id]["CornPlant"] ~= 0 then
				 removePedFromVehicle ( thePlayer )
	    			outputChatBox ( "На поле достаточно урожая!", thePlayer,255,255,255,true)
				else
					triggerClientEvent(thePlayer, "Go_plan_corn", thePlayer,"create")
				end
			end
		end
		addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicles )
		addEvent("farms_stop",true)
		addEventHandler("farms_stop",root,function()
			respawnVehicle(getPedOccupiedVehicle(client),false);
			removePedFromVehicle ( client )
			outputChatBox("Вы успешно накосили урожай!", client,255,255,255,true)
			if(farmdata[id]["CornSklad"] < 5000) and farmdata[id]["CornPlant"] == 0 then
				farmdata[id]["CornPlant"] = farmdata[id]["CornSklad"]
				farmdata[id]["CornSklad"] = 0
				else if farmdata[id]["CornSklad"] >= 5000 and farmdata[id]["CornPlant"] == 0 then
				farmdata[id]["CornPlant"] = 5000
				farmdata[id]["CornSklad"] = farmdata[id]["CornSklad"]-5000
			end	
		end)
		addEventHandler("onColShapeHit", farmdata[id]["infocols"], function(hitElement)
			if(getElementType(hitElement) == "player") and (getElementData(hitElement, "online") == 1) then
				triggerClientEvent ( hitElement, "Show_infof", hitElement,farmdata[id]["Id"],farmdata[id]["Owner"],farmdata[id]["zOwner1"],farmdata[id]["zOwner2"],farmdata[id]["zOwner3"],farmdata[id]["Farmer1"],farmdata[id]["Farmer2"],farmdata[id]["Farmer3"],farmdata[id]["Farmer4"],farmdata[id]["Farmer5"],farmdata[id]["Balance"],farmdata[id]["PriceJob"],farmdata[id]["BuyCorn"],farmdata[id]["CornSklad"],farmdata[id]["CornPlant"],farmdata[id]["SellProd"],farmdata[id]["ProdSklad"],farmdata[id]["PriceProd"])
			end
		end)
		addEventHandler("onColShapeHit", farm, function(hitElement)
			if(getElementType(hitElement) == "player") then
				triggerClientEvent ( user_player, "Show_informfarm", user_player)
			end
		end)
	end
end

 

number line 91

"id" works fine

Link to comment
  • Moderators
local id_farm = {}
local farmdata = {}
local dbpTime = 500
local ids = 0


function CreateFarm(dbRow)
	local id = dbRow['ID']
	
	id_farm[id] = createColSphere(row['Posx'],row['Posy'],row['Posz'], 1.5)
	setElementData(id_farm[id], "farm", true)
	
	farmdata[id] = dbRow -- paste all database data to farmdata table.
	farmdata[id]["infocols"] = createColSphere(dbRow['Posxinf'], dbRow['Posyinf'], dbRow['Poszinf'], 1.5)
	farmdata[id]["Combaine"] = createVehicle(532, dbRow['532x'], dbRow['532y'], dbRow['532z'])


	createPickup(row['Posx'],row['Posy'],row['Posz'], 3, 1318, 100)
	createPickup(row['Posxinf'],row['Posyinf'],row['Poszinf'], 3, 1239, 100)
	createBlip(row['Posx'],row['Posy'],row['Posz'], 56, 2, 255, 0, 0, 255, 0, 250)
	
	
	addEventHandle("onVehicleStartEnter", farmdata[id]["Combaine"], function(thePlayer) -- start to enter to Combaine
		if id ~= getElementData(thePlayer,"fjobs") then
			cancelEvent() -- cancel the event and not enter
			outputChatBox("Вы не фермер!", thePlayer, 255, 255, 255, true) -- info
			return
		end
		
		if farmdata[id]["CornPlant"] ~= 0 then
			cancelEvent() -- cancel the event and not enter
			outputChatBox("На поле достаточно урожая!", thePlayer, 255, 255, 255, true) -- info
		else
			triggerClientEvent(thePlayer, "Go_plan_corn", thePlayer, "create")
		end
	end)
	
	addEventHandler("onColShapeHit", farmdata[id]["infocols"], function(hitElement)
		if (getElementType(hitElement) == "player") and (getElementData(hitElement, "online") == 1) then
			triggerClientEvent(hitElement, "Show_infof", hitElement, dbRow['ID'], dbRow["Owner"], dbRow["zOwner1"], dbRow["zOwner2"], dbRow["zOwner3"], dbRow["Farmer1"], dbRow["Farmer2"], dbRow["Farmer3"], dbRow["Farmer4"], dbRow["Farmer5"], dbRow["Balance"], dbRow["PriceJob"], dbRow["BuyCorn"], dbRow["CornSklad"], dbRow["CornPlant"], dbRow["SellProd"], dbRow["ProdSklad"], dbRow["PriceProd"])
		end
	end)
	
	addEventHandler("onColShapeLeave", farmdata[id]["infocols"], function(hitElement)
		if (getElementType(hitElement) == "player") and (getElementData(hitElement, "online") == 1) then
			triggerClientEvent(hitElement, "Show_informfarm", hitElement)
		end
	end)
	
	outputServerLog("Farm number "..id.." is loaded!")
end

addEvent("farms_stop",true)
addEventHandler("farms_stop", root, function(id)
	local vehicle = getPedOccupiedVehicle(client)
	if vehicle then
		removePedFromVehicle(client)
		respawnVehicle(vehicle, false)
	end
	
	outputChatBox("Вы успешно накосили урожай!", client, 255, 255, 255, true)
	
	if (farmdata[id]["CornSklad"] < 5000) and farmdata[id]["CornPlant"] == 0 then
		farmdata[id]["CornPlant"] = farmdata[id]["CornSklad"]
		farmdata[id]["CornSklad"] = 0
	elseif farmdata[id]["CornSklad"] >= 5000 and farmdata[id]["CornPlant"] == 0 then
		farmdata[id]["CornPlant"] = 5000
		farmdata[id]["CornSklad"] = farmdata[id]["CornSklad"]-5000
	end	
end)



-- Place the load function end of the script, almost always
function loadfarm()
	outputServerLog("_________________Load to farm_________________")
	
	local query = dbQuery(connect_db, "SELECT * FROM farm;" )
	local result, numrows = dbPoll(query, dbpTime)
	
	if (result and numrows > 0) then
		for _, row in ipairs(result) do
			CreateFarm(row)
		end
		dbFree(query)
	else
		outputServerLog("Houses Table not Found/empty!")
	end
	
	outputServerLog("Farm load: "..numrows)
	outputServerLog("_________________End Load to farm_________________")
end
addEventHandler("onResourceStart", resourceRoot, loadfarm)

You need to modify the client side, when you trigger the farms_stop event, you need to send the farm's ID back.

 

(It's not working 100%, but you can to compare with your code and find your faults.)

Edited by stPatrick
  • Thanks 1
Link to comment
9 minutes ago, stPatrick said:

 

It is really hard to fix, because I can't test it and I don't know whats doing the client side, but maybe working.

(You need to modify the client side, need to send back the 'ID' to server, when you trigger the farms_stop event.)


local id_farm = {}local farmdata = {}local dbpTime = 500local ids = 0function CreateFarm(dbRow)	local id = dbRow['ID']		id_farm[id] = createColSphere(posx,posy,posz, 1.5)	setElementData(id_farm[id], "farm", true)		farmdata[id] = dbRow -- paste all database data to farmdata table.	farmdata[id]["infocols"] = createColSphere(dbRow['Posxinf'], dbRow['Posyinf'], dbRow['Poszinf'], 1.5)	farmdata[id]["Combaine"] = createVehicle(532, dbRow['532x'], dbRow['532y'], dbRow['532z'])	createPickup(posx,posy,posz, 3, 1318, 100)	createPickup(posxinfo,posyinfo,poszinfo, 3, 1239, 100)	createBlip(posx, posy, posz, 56, 2, 255, 0, 0, 255, 0, 250)			addEventHandle("onVehicleStartEnter", farmdata[id]["Combaine"], function(thePlayer) -- start to enter to Combaine		if id ~= getElementData(thePlayer,"fjobs") then			cancelEvent() -- cancel the event and not enter			outputChatBox("Вы не фермер!", thePlayer, 255, 255, 255, true) -- info			return		end				if farmdata[id]["CornPlant"] ~= 0 then			cancelEvent() -- cancel the event and not enter			outputChatBox("На поле достаточно урожая!", thePlayer, 255, 255, 255, true) -- info		else			triggerClientEvent(thePlayer, "Go_plan_corn", thePlayer, "create")		end	end)		addEventHandler("onColShapeHit", farmdata[id]["infocols"], function(hitElement)		if (getElementType(hitElement) == "player") and (getElementData(hitElement, "online") == 1) then			triggerClientEvent(hitElement, "Show_infof", hitElement, dbRow['ID'], dbRow["Owner"], dbRow["zOwner1"], dbRow["zOwner2"], dbRow["zOwner3"], dbRow["Farmer1"], dbRow["Farmer2"], dbRow["Farmer3"], dbRow["Farmer4"], dbRow["Farmer5"], dbRow["Balance"], dbRow["PriceJob"], dbRow["BuyCorn"], dbRow["CornSklad"], dbRow["CornPlant"], dbRow["SellProd"], dbRow["ProdSklad"], dbRow["PriceProd"])		end	end)		addEventHandler("onColShapeLeave", farmdata[id]["infocols"], function(hitElement)		if (getElementType(hitElement) == "player") and (getElementData(hitElement, "online") == 1) then			triggerClientEvent(hitElement, "Show_informfarm", hitElement)		end	end)		outputServerLog("Farm number "..id.." is loaded!")endaddEvent("farms_stop",true)addEventHandler("farms_stop", root, function(id)	local vehicle = getPedOccupiedVehicle(client)	if vehicle then		removePedFromVehicle(client)		respawnVehicle(vehicle, false)	end		outputChatBox("Вы успешно накосили урожай!", client, 255, 255, 255, true)		if (farmdata[id]["CornSklad"] < 5000) and farmdata[id]["CornPlant"] == 0 then		farmdata[id]["CornPlant"] = farmdata[id]["CornSklad"]		farmdata[id]["CornSklad"] = 0	elseif farmdata[id]["CornSklad"] >= 5000 and farmdata[id]["CornPlant"] == 0 then		farmdata[id]["CornPlant"] = 5000		farmdata[id]["CornSklad"] = farmdata[id]["CornSklad"]-5000	end	end)-- Place the load function end of the script, almost alwaysfunction loadfarm()	outputServerLog("_________________Load to farm_________________")		local query = dbQuery(connect_db, "SELECT * FROM farm;" )	local result, numrows = dbPoll(query, dbpTime)		if (result and numrows > 0) then		for _, row in ipairs(result) do			CreateFarm(row)		end		dbFree(query)	else		outputServerLog("Houses Table not Found/empty!")	end		outputServerLog("Farm load: "..numrows)	outputServerLog("_________________End Load to farm_________________")endaddEventHandler("onResourceStart", resourceRoot, loadfarm)

 

Thanks, I'll check

Error

 

[2019-03-04 15:42:10] ERROR: roleplay\bussines\bus_farm.lua:23: attempt to call global 'addEventHandle' (a nil value)
[2019-03-04 15:42:11] roleplay restarted successfully

@stPatrick

The mistake was addEventHandler*

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...