Jump to content

problema bindKey


Recommended Posts

..
function openDoor()
local data = DoorsTable[source]
	if data == nil then return end
	local rx,ry,rz=getElementRotation(data["door"])
	if getElementData(source,"Group") == data["camp"] or data.camp == "false" or not data["camp"] then
		moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,90)
		--setTimer(closeDoor,5000,1,source)
	end
end
--addEventHandler("onColShapeHit",resourceRoot,openDoor)

function bind(hitPlayer, matchingDimension) 
	if getElementType(hitPlayer) == "player" then 
		bindKey(hitPlayer, ",", "down", openDoor) 
		outputChatBox("onColShapeHit add bind")
	end 
end 
addEventHandler("onColShapeHit", resourceRoot, bind) 

..

Este é meu código.

Oque ele deveria fazer? Quando o player chegar nesse Col Shape (dar hit) o objeto se mover apenas quando o player aperta a bind "," porém não é isso que acontecesse, sinceramente nada acontece, não da warning nem erro e o objeto continua sem se mover... 

Se eu coloco o evento "onColShapeHit" ligado a função openDoor() funciona normal, no caso a porta abre só quando o player der hit no col shape..

Oque estou fazendo de errado?

Edited by Pedro Colto
Link to comment
  • Moderators

source está errado, não vai retornar nada, esses são os parâmetros para a função:

function functionName ( player keyPresser, string key, string keyState, [ var arguments, ... ] )

É só definir o elemento-jogador no parâmetro.

Link to comment
..
function openDoor(hitElement)
	local data = DoorsTable[source]
	if data == nil then return end
	local rx,ry,rz=getElementRotation(data["door"])
	if getElementData(hitElement,"gang") == data["camp"] or data.camp == "false" or not data["camp"] then
		moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,90)
		setTimer(closeDoor,5000,1,source)
	end
end
addEventHandler("onColShapeHit",resourceRoot,openDoor)
..

 

Edited by Pedro Colto
Link to comment
  • Moderators

Tente:

function openDoor(player, key, keyState, colshape)
	local data = DoorsTable[colshape]
	if data == nil then return end
	local rx,ry,rz=getElementRotation(data["door"])
	if getElementData(player,"gang") == data["camp"] or data.camp == "false" or not data["camp"] then
		moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,90)
		setTimer(closeDoor,5000,1,colshape)
	end
end

function bind(hitPlayer, matchingDimension) 
	if getElementType(hitPlayer) == "player" then
		if isKeyBound( hitPlayer, ",", "down", openDoor ) ~= true then
			bindKey(hitPlayer, ",", "down", openDoor, source)
			outputChatBox("onColShapeHit add bind")
		end
	end
end 
addEventHandler("onColShapeHit", resourceRoot, bind) 

 

Edited by DNL291
Link to comment
8 hours ago, DNL291 said:

Tente:

function openDoor(player, key, keyState, colshape)
	local data = DoorsTable[colshape]
	if data == nil then return end
	local rx,ry,rz=getElementRotation(data["door"])
	if getElementData(player,"gang") == data["camp"] or data.camp == "false" or not data["camp"] then
		moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,90)
		setTimer(closeDoor,5000,1,colshape)
	end
end

function bind(hitPlayer, matchingDimension) 
	if getElementType(hitPlayer) == "player" then
		if isKeyBound( hitPlayer, ",", "down", openDoor ) ~= true then
			bindKey(hitPlayer, ",", "down", openDoor, source)
			outputChatBox("onColShapeHit add bind")
		end
	end
end 
addEventHandler("onColShapeHit", resourceRoot, bind) 

 

Certo entendi, pode me explicar como consigo fazer para a mesma bind fechar a porta apos ela esta na rotação de "open"/"aberta"??

eu devo dar uma data para objeto ligado a rotação, isso que to meio confuso -'

Link to comment

Olha desta forma que eu tentei fazer, mas também sem sucesso..

 

function closeDoor(player,colshape)
	local data = DoorsTable[colshape]
	if data == nil then return end
	if getElementData(data["door"],"object.moved") == "moved"  and getElementData(player,"gang") == data["camp"] or data.camp == "false" or not data["camp"] then
			moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,-90)
			setElementRotation(data["door"],data.rot.x,data.rot.y,data.rot.z - -90)
			--setElementData(data["door"],"object.moved","notmoved")
			setElementData(data["door"],"object.moved","notmoved") 
			outputChatBox(getElementData(data["door"],"object.moved"))
			end
end
ahuh=false

function openDoor(player, key, keyState, colshape)
	local data = DoorsTable[colshape]
	if data == nil then return end
	local rx,ry,rz=getElementRotation(data["door"])
	if ahuh and getElementData(data["door"], "object.moved") == "notmoved" and getElementData(player,"gang") == data["camp"] or data.camp == "false" or not data["camp"] then
		ahuh=true
		moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,90)
		setElementData(data["door"],"object.moved","moved") 
		outputChatBox(getElementData(data["door"],"object.moved"))
				
		--setTimer(closeDoor,5000,1,colshape)
	end
		if getElementData(data["door"],"object.moved") == "moved" then
		closeDoor()
		outputChatBox("check")
		ahuh=false
end
end

function bind(hitPlayer, matchingDimension) 
	if getElementType(hitPlayer) == "player" then
		if isKeyBound( hitPlayer, ",", "down", openDoor ) ~= true then
			bindKey(hitPlayer, ",", "down", openDoor, source)
			outputChatBox("onColShapeHit add bind")
		end
	end
end 
addEventHandler("onColShapeHit", resourceRoot, bind) 

 

Link to comment
  • Moderators

Tente isto (não testei):

function closeDoor(player,colshape)
	local data = DoorsTable[colshape]
	if data == nil then return end
	if getElementData(data["door"],"object.moved") == "moved" then
		if moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,-90) then
			outputChatBox("Porta fechada com sucesso")
		end
		setElementRotation(data["door"],data.rot.x,data.rot.y,data.rot.z - -90) -- checar isso
		-- ^ A rotação já é definida em moveObject, e menos com menos vai ser uma adição na rotZ
		setElementData(data["door"],"object.moved","notmoved") 
	end
end

function toggleDoorOpen(player, key, keyState, colshape)
	if not isElementWithinColShape( player, colshape ) then return end;
	--[[ A bind só vai funcionar se tiver dentro do colshape,
		se quiser desativar só remover essa linha ]]
	
	local data = DoorsTable[colshape]
	if data == nil then return end
	local rx,ry,rz=getElementRotation(data["door"]) -- se não for usar isso pode remover
	local doorState = getElementData(data["door"], "object.moved")
	if doorState and doorState == "moved" and (getElementData(player,"gang") == data["camp"] or data.camp == "false" or not data["camp"]) then
		closeDoor( player, colshape )
		outputChatBox("fechando")
		return
	end
	if doorState and doorState == "notmoved" and (getElementData(player,"gang") == data["camp"] or data.camp == "false" or not data["camp"]) then
		moveObject(data["door"],2000,data.pos.x,data.pos.y,data.pos.z,0,0,90)
		setElementData(data["door"],"object.moved","moved") 
		outputChatBox("abrindo porta")
	end
end

function bind(hitPlayer, matchingDimension) 
	if getElementType(hitPlayer) == "player" then
		if type(getElementData( DoorsTable[source]["door"], "object.moved" )) ~= "string" then
			setElementData( DoorsTable[source]["door"], "object.moved", "notmoved" )
		end
		if isKeyBound( hitPlayer, ",", "down", toggleDoorOpen ) ~= true then
			bindKey(hitPlayer, ",", "down", toggleDoorOpen, source)
		end
		outputChatBox("onColShapeHit add bind")
	end
end 
addEventHandler("onColShapeHit", resourceRoot, bind)

Preste atenção nos comentários que deixei no código.

Edited by DNL291
  • Like 1
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...