Jump to content

DGS работает наполовину (грубо говоря)


Recommended Posts

 

Доброго времени суток, скриптеры. 
Я новичок в этом деле, по этому за говнокод не ругайтесь пожалуйста.

Подскажите что делаю не так? Первая часть кода (Армия) работает отлично, а вторая через раз. Опытный сразу думаю увидит. Я думаю слишком много elseif,  событие путается, как оптимизировать не знаю

function kek()
	showCursor(true)
	dgs:dgsSetVisible(window,true) 
	dgs:dgsSetVisible(imgposition1,true) 
	dgs:dgsSetVisible(imgposition2,true)
end

function kek1()
	dgs:dgsSetVisible(window,false) 
	dgs:dgsSetVisible(imgposition1,false) 
	dgs:dgsSetVisible(imgposition2,false) 
end


bindKey('1','down',kek)


addEventHandler('onDgsMouseClick',root,function(btn,state)

----------------Армия -------------------
		if state == "down" and btn == "left" and source == btnArmy then
		kek1()
		triggerEvent("PedCreate",localPlayer)
		showCursor(true)
		dgs:dgsSetVisible(but1,true) 
		dgs:dgsSetVisible(but2,true) 
		dgs:dgsSetVisible(but3,true) 
		si = 1
			if not si == 1 then si = 1 end
		skinid1 = 179
 		setCameraMatrix(247.96488952637,1861.4558105469,14.794466018677,248.35562133789,1764.9252929688,-11.315200805664)

		elseif state == "down" and btn == "left" and source == but1 then
			si = si - 1
			if si == 0 then si = 5 end
	

			elseif state == "down" and btn == "left" and source == but2 then

			dgs:dgsSetVisible(but1,false) 
			dgs:dgsSetVisible(but2,false) 
			dgs:dgsSetVisible(but3,false)
			setElementData(localPlayer,"skinid1",skinid1)
			triggerServerEvent("spawnPlayerArmy",localPlayer)
			setCameraTarget( localPlayer )
			showCursor(false)
			triggerEvent("PedDel",localPlayer)
	

		elseif state == "down" and btn == "left" and source == but3 then
				si = si + 1
				if si == 6 then si = 1 end

					elseif si == 1 then 
					skinid1 = 179
					setCameraMatrix(247.96488952637,1861.4558105469,14.794466018677,248.35562133789,1764.9252929688,-11.315200805664)
					elseif si == 2 then 
					skinid1 = 285
					setCameraMatrix(246.00991821289,1861.4471435547,14.794466018677,246.40065002441,1764.9166259766,-11.315200805664)
					--	outputChatBox ("Скин: = "..skinid)
						elseif si == 3 then 
						skinid1 = 287
						setCameraMatrix(243.98690795898,1861.4406738281,14.794466018677,244.37763977051,1764.91015625,-11.315200805664)
						--outputChatBox ("Скин: = "..skinid)
							elseif si == 4 then 
							skinid1 = 73
							setCameraMatrix(241.95097351074,1861.4321289063,14.794466018677,242.34170532227,1764.9016113281,-11.315200805664)
							--outputChatBox ("Скин: = "..skinid)
							elseif si == 5 then 
							skinid1 = 191
							setCameraMatrix(239.9241027832,1861.4228515625,14.794466018677,240.31483459473,1764.8923339844,-11.315200805664)
							--outputChatBox ("Скин: = "..skinid)

-------------Террористы -------------

		elseif state == "down" and btn == "left" and source == btnTerr then
		kek1()	
		showCursor(true)
		dgs:dgsSetVisible(but4,true) 
		dgs:dgsSetVisible(but5,true) 
		dgs:dgsSetVisible(but6,true)
		ti = 1
		if not ti == 1 then ti = 1 end
		triggerEvent("PedCreateTerr",localPlayer)
		skinid1 = 28
		setCameraMatrix(-274.44561767578,2588.4030761719,64.03636932373,-276.62969970703,2686.3229980469,43.863948822021)
	

		elseif state == "down" and btn == "left" and source == but4 then
			ti = ti - 1
			if ti == 0 then ti = 5 end

				elseif state == "down" and btn == "left" and source == but5 then
					dgs:dgsSetVisible(but4,false) 
					dgs:dgsSetVisible(but5,false) 
					dgs:dgsSetVisible(but6,false)
					setElementData(localPlayer,"skinid1",skinid1)
					triggerServerEvent("spawnPlayerTerr",localPlayer)
					setCameraTarget( localPlayer )
					showCursor(false)
					triggerEvent("PedDelTerr",localPlayer)
		

			elseif state == "down" and btn == "left" and source == but6 then
				ti = ti + 1
				if ti == 6 then ti = 1 end

					elseif ti == 1 then 
					skinid1 = 28
					setCameraMatrix(-274.44561767578,2588.4030761719,64.03636932373,-276.62969970703,2686.3229980469,43.863948822021)
					elseif ti == 2 then 
					skinid1 = 30
					setCameraMatrix(-272.44989013672,2588.4465332031,64.03636932373,-274.63397216797,2686.3664550781,43.863948822021)
					--	outputChatBox ("Скин: = "..skinid)
						elseif ti == 3 then 
						skinid1 = 126
						setCameraMatrix(-270.45120239258,2588.4909667969,64.03636932373,-272.63528442383,2686.4108886719,43.863948822021)
						--outputChatBox ("Скин: = "..skinid)
							elseif ti == 4 then 
							skinid1 = 93
							setCameraMatrix(-268.44940185547,2588.5341796875,64.03636932373,-270.63348388672,2686.4541015625,43.863948822021)
							--outputChatBox ("Скин: = "..skinid)
								elseif ti == 5 then 
								skinid1 = 150
								setCameraMatrix(-266.46176147461,2588.5773925781,64.03636932373,-268.64584350586,2686.4973144531,43.863948822021)
								--outputChatBox ("Скин: = "..skinid)
									elseif ti == 6 then 
									ti = ti - 1	
									end
end)

 

https://imgur.com/a/sSw81YI  Cкрины для наглядности

Link to comment

Еще забыл сказать :  Релогаешь ресурс, выбираешь армию, сколько угодно все хорошо. но когда выбираешь теров, код ломается, аналогично если после рестарта нажимаешь на терров, они работают топчик, но на армии ломаються.

 

Link to comment

Я точно не уверен, но вроде так

function kek()
	showCursor(true)
	dgs:dgsSetVisible(window,true) 
	dgs:dgsSetVisible(imgposition1,true) 
	dgs:dgsSetVisible(imgposition2,true)
end

function kek1()
	dgs:dgsSetVisible(window,false) 
	dgs:dgsSetVisible(imgposition1,false) 
	dgs:dgsSetVisible(imgposition2,false) 
end


bindKey('1','down',kek)


addEventHandler('onDgsMouseClick',root,function(btn,state)

----------------Армия -------------------
	if state == "down" and btn == "left" and source == btnArmy then
		kek1()
		triggerEvent("PedCreate",localPlayer)
		showCursor(true)
		dgs:dgsSetVisible(but1,true) 
		dgs:dgsSetVisible(but2,true) 
		dgs:dgsSetVisible(but3,true) 
		si = 1
		
		if not si == 1 then si = 1 end
		
		skinid1 = 179
		setCameraMatrix(247.96488952637,1861.4558105469,14.794466018677,248.35562133789,1764.9252929688,-11.315200805664)

	elseif state == "down" and btn == "left" and source == but1 then
		si = si - 1
		if si == 0 then si = 5 end


	elseif state == "down" and btn == "left" and source == but2 then

		dgs:dgsSetVisible(but1,false) 
		dgs:dgsSetVisible(but2,false) 
		dgs:dgsSetVisible(but3,false)
		setElementData(localPlayer,"skinid1",skinid1)
		triggerServerEvent("spawnPlayerArmy",localPlayer)
		setCameraTarget( localPlayer )
		showCursor(false)
		triggerEvent("PedDel",localPlayer)


	elseif state == "down" and btn == "left" and source == but3 then
			si = si + 1
			if si == 6 then 
				si = 1 
			end

			if si == 1 then 
				skinid1 = 179
				setCameraMatrix(247.96488952637,1861.4558105469,14.794466018677,248.35562133789,1764.9252929688,-11.315200805664)
			elseif si == 2 then 
				skinid1 = 285
				setCameraMatrix(246.00991821289,1861.4471435547,14.794466018677,246.40065002441,1764.9166259766,-11.315200805664)
			elseif si == 3 then 
				skinid1 = 287
				setCameraMatrix(243.98690795898,1861.4406738281,14.794466018677,244.37763977051,1764.91015625,-11.315200805664)
			elseif si == 4 then 
				skinid1 = 73
				setCameraMatrix(241.95097351074,1861.4321289063,14.794466018677,242.34170532227,1764.9016113281,-11.315200805664)
			elseif si == 5 then 
				skinid1 = 191
				setCameraMatrix(239.9241027832,1861.4228515625,14.794466018677,240.31483459473,1764.8923339844,-11.315200805664)
			end

-------------Террористы -------------

	elseif state == "down" and btn == "left" and source == btnTerr then
		kek1()	
		showCursor(true)
		dgs:dgsSetVisible(but4,true) 
		dgs:dgsSetVisible(but5,true) 
		dgs:dgsSetVisible(but6,true)
		ti = 1
		
		if not ti == 1 then ti = 1 end
		
		triggerEvent("PedCreateTerr",localPlayer)
		skinid1 = 28
		setCameraMatrix(-274.44561767578,2588.4030761719,64.03636932373,-276.62969970703,2686.3229980469,43.863948822021)


	elseif state == "down" and btn == "left" and source == but4 then
		ti = ti - 1
		if ti == 0 then ti = 5 end

	elseif state == "down" and btn == "left" and source == but5 then
		dgs:dgsSetVisible(but4,false) 
		dgs:dgsSetVisible(but5,false) 
		dgs:dgsSetVisible(but6,false)
		setElementData(localPlayer,"skinid1",skinid1)
		triggerServerEvent("spawnPlayerTerr",localPlayer)
		setCameraTarget( localPlayer )
		showCursor(false)
		triggerEvent("PedDelTerr",localPlayer)
	

	elseif state == "down" and btn == "left" and source == but6 then
		ti = ti + 1
		if ti == 6 then ti = 1 end

		if ti == 1 then 
			skinid1 = 28
			setCameraMatrix(-274.44561767578,2588.4030761719,64.03636932373,-276.62969970703,2686.3229980469,43.863948822021)
		elseif ti == 2 then 
			skinid1 = 30
			setCameraMatrix(-272.44989013672,2588.4465332031,64.03636932373,-274.63397216797,2686.3664550781,43.863948822021)
		elseif ti == 3 then 
			skinid1 = 126
			setCameraMatrix(-270.45120239258,2588.4909667969,64.03636932373,-272.63528442383,2686.4108886719,43.863948822021)
		elseif ti == 4 then 
			skinid1 = 93
			setCameraMatrix(-268.44940185547,2588.5341796875,64.03636932373,-270.63348388672,2686.4541015625,43.863948822021)
		elseif ti == 5 then 
			skinid1 = 150
			setCameraMatrix(-266.46176147461,2588.5773925781,64.03636932373,-268.64584350586,2686.4973144531,43.863948822021)
		elseif ti == 6 then 
			ti = ti - 1	
		end
	end
end)

Просто если бы ты написал в чем именно проблема, было бы легче понять что не так

  • Like 1
Link to comment
9 hours ago, AngelAlpha said:

Я точно не уверен, но вроде так

function kek()
	showCursor(true)
	dgs:dgsSetVisible(window,true) 
	dgs:dgsSetVisible(imgposition1,true) 
	dgs:dgsSetVisible(imgposition2,true)
end

function kek1()
	dgs:dgsSetVisible(window,false) 
	dgs:dgsSetVisible(imgposition1,false) 
	dgs:dgsSetVisible(imgposition2,false) 
end


bindKey('1','down',kek)


addEventHandler('onDgsMouseClick',root,function(btn,state)

----------------Армия -------------------
	if state == "down" and btn == "left" and source == btnArmy then
		kek1()
		triggerEvent("PedCreate",localPlayer)
		showCursor(true)
		dgs:dgsSetVisible(but1,true) 
		dgs:dgsSetVisible(but2,true) 
		dgs:dgsSetVisible(but3,true) 
		si = 1
		
		if not si == 1 then si = 1 end
		
		skinid1 = 179
		setCameraMatrix(247.96488952637,1861.4558105469,14.794466018677,248.35562133789,1764.9252929688,-11.315200805664)

	elseif state == "down" and btn == "left" and source == but1 then
		si = si - 1
		if si == 0 then si = 5 end


	elseif state == "down" and btn == "left" and source == but2 then

		dgs:dgsSetVisible(but1,false) 
		dgs:dgsSetVisible(but2,false) 
		dgs:dgsSetVisible(but3,false)
		setElementData(localPlayer,"skinid1",skinid1)
		triggerServerEvent("spawnPlayerArmy",localPlayer)
		setCameraTarget( localPlayer )
		showCursor(false)
		triggerEvent("PedDel",localPlayer)


	elseif state == "down" and btn == "left" and source == but3 then
			si = si + 1
			if si == 6 then 
				si = 1 
			end

			if si == 1 then 
				skinid1 = 179
				setCameraMatrix(247.96488952637,1861.4558105469,14.794466018677,248.35562133789,1764.9252929688,-11.315200805664)
			elseif si == 2 then 
				skinid1 = 285
				setCameraMatrix(246.00991821289,1861.4471435547,14.794466018677,246.40065002441,1764.9166259766,-11.315200805664)
			elseif si == 3 then 
				skinid1 = 287
				setCameraMatrix(243.98690795898,1861.4406738281,14.794466018677,244.37763977051,1764.91015625,-11.315200805664)
			elseif si == 4 then 
				skinid1 = 73
				setCameraMatrix(241.95097351074,1861.4321289063,14.794466018677,242.34170532227,1764.9016113281,-11.315200805664)
			elseif si == 5 then 
				skinid1 = 191
				setCameraMatrix(239.9241027832,1861.4228515625,14.794466018677,240.31483459473,1764.8923339844,-11.315200805664)
			end

-------------Террористы -------------

	elseif state == "down" and btn == "left" and source == btnTerr then
		kek1()	
		showCursor(true)
		dgs:dgsSetVisible(but4,true) 
		dgs:dgsSetVisible(but5,true) 
		dgs:dgsSetVisible(but6,true)
		ti = 1
		
		if not ti == 1 then ti = 1 end
		
		triggerEvent("PedCreateTerr",localPlayer)
		skinid1 = 28
		setCameraMatrix(-274.44561767578,2588.4030761719,64.03636932373,-276.62969970703,2686.3229980469,43.863948822021)


	elseif state == "down" and btn == "left" and source == but4 then
		ti = ti - 1
		if ti == 0 then ti = 5 end

	elseif state == "down" and btn == "left" and source == but5 then
		dgs:dgsSetVisible(but4,false) 
		dgs:dgsSetVisible(but5,false) 
		dgs:dgsSetVisible(but6,false)
		setElementData(localPlayer,"skinid1",skinid1)
		triggerServerEvent("spawnPlayerTerr",localPlayer)
		setCameraTarget( localPlayer )
		showCursor(false)
		triggerEvent("PedDelTerr",localPlayer)
	

	elseif state == "down" and btn == "left" and source == but6 then
		ti = ti + 1
		if ti == 6 then ti = 1 end

		if ti == 1 then 
			skinid1 = 28
			setCameraMatrix(-274.44561767578,2588.4030761719,64.03636932373,-276.62969970703,2686.3229980469,43.863948822021)
		elseif ti == 2 then 
			skinid1 = 30
			setCameraMatrix(-272.44989013672,2588.4465332031,64.03636932373,-274.63397216797,2686.3664550781,43.863948822021)
		elseif ti == 3 then 
			skinid1 = 126
			setCameraMatrix(-270.45120239258,2588.4909667969,64.03636932373,-272.63528442383,2686.4108886719,43.863948822021)
		elseif ti == 4 then 
			skinid1 = 93
			setCameraMatrix(-268.44940185547,2588.5341796875,64.03636932373,-270.63348388672,2686.4541015625,43.863948822021)
		elseif ti == 5 then 
			skinid1 = 150
			setCameraMatrix(-266.46176147461,2588.5773925781,64.03636932373,-268.64584350586,2686.4973144531,43.863948822021)
		elseif ti == 6 then 
			ti = ti - 1	
		end
	end
end)

Просто если бы ты написал в чем именно проблема, было бы легче понять что не так

Работает, капец, то есть я все правильно делал, проблема была в табуляциях?? она имеет значение?

Link to comment
10 hours ago, So4nij said:

Работает, капец, то есть я все правильно делал, проблема была в табуляциях?? она имеет значение?

нет, проблема была в условиях, пересмотри свою версию и мою

 

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