Jump to content

[help] isElementWithinMarker


raynner

Recommended Posts

Posted (edited)
function PlayerHitInMarkerLeaveBox(hitElement)
	if (isElement(hitElement) and getElementType(hitElement) == "player") then
		if TbPlEmp[hitElement] and source == TbPlEmp[hitElement]["marker"] then
			if TbPlEmp[hitElement]["box"] and isElement(TbPlEmp[hitElement]["box"]) and isElementWithinMarker(TbPlEmp[hitElement]["box"],source) then
				outputChatBox("#FFAA00||#00FF00  ✔ #FFAA00||#00FF00 ok !",hitElement,255,255,255,true)
			else
				outputChatBox("#FFAA00||#FF0000  ✘ #FFAA00||#FF0000 error !",hitElement,255,255,255,true)
			end
		end
	end
end
addEventHandler("onMarkerHit",root,PlayerHitInMarkerLeaveBox)

My problem here is, everything works fine excerpt box check in marker does anyone have any idea why?

- Always returns false 

Edited by raynner
correction in text
Posted (edited)
13 hours ago, Citizen said:

What's the purpose of  TbPlEmp[hitElement]["marker"]  and how do you create it ?

TbPlEmp = {}

function StartJobEmpilhadeiraForPlayer()
	--> verifica se não há uma tabela e cria uma no nome do player !
	if not(TbPlEmp[source]) then
		TbPlEmp[source] = {}
	end
	--> Verifica se o player tem um veículo e destroy se houver !
	if TbPlEmp[source]["veh"] then
		destroyElement(TbPlEmp[source]["veh"])
		TbPlEmp[source]["veh"] = nil
	end
	TbPlEmp[source]["veh"] = createVehicle(530,2799,-2401,13,0,0,93)
	warpPedIntoVehicle(source,TbPlEmp[source]["veh"])
	TbPlEmp[source]["box"] = createObject(1558,2779.2048,-2485.4523,13.1577,0,0,0,false)
	TbPlEmp[source]["marker"] = createMarker(2724,-2398,12,"cylinder",3,0,255,150,255,source)
end
addEvent("GiveItensForJobEmpilhadeira",true)
addEventHandler("GiveItensForJobEmpilhadeira",root,StartJobEmpilhadeiraForPlayer)

function PlayerHitInMarkerLeaveBox(hitElement)
	if (isElement(hitElement) and getElementType(hitElement) == "player") then
		if TbPlEmp[hitElement] and source == TbPlEmp[hitElement]["marker"] then
			if TbPlEmp[hitElement]["box"] and isElement(TbPlEmp[hitElement]["box"]) and isElementWithinMarker(TbPlEmp[hitElement]["box"],source) then
				outputChatBox("#FFAA00||#00FF00  ✔ #FFAA00||#00FF00 ok !",hitElement,255,255,255,true)
			else
				outputChatBox("#FFAA00||#FF0000  ✘ #FFAA00||#FF0000 error !",hitElement,255,255,255,true)
			end
		end
	end
end
addEventHandler("onMarkerHit",root,PlayerHitInMarkerLeaveBox)

 

Edited by raynner
script ..
Posted

Try this:

TbPlEmp = {}

function StartJobEmpilhadeiraForPlayer()
	--> verifica se não há uma tabela e cria uma no nome do player !
	if not(TbPlEmp[source]) then
		TbPlEmp[source] = {}
	end
	--> Verifica se o player tem um veículo e destroy se houver !
	if TbPlEmp[source]["veh"] then
		destroyElement(TbPlEmp[source]["veh"])
		TbPlEmp[source]["veh"] = nil
	end
	TbPlEmp[source]["veh"] = createVehicle(530,2799,-2401,13,0,0,93)
	warpPedIntoVehicle(source,TbPlEmp[source]["veh"])
	TbPlEmp[source]["box"] = createObject(1558,2779.2048,-2485.4523,13.1577,0,0,0,false)
	TbPlEmp[source]["marker"] = createMarker(2724,-2398,12,"cylinder",3,0,255,150,255,source)
  	setElementPosition(TbPlEmp[source]["box"], 1558,2779.2048,-2485.4523)
end
addEvent("GiveItensForJobEmpilhadeira",true)
addEventHandler("GiveItensForJobEmpilhadeira",root,StartJobEmpilhadeiraForPlayer)

function PlayerHitInMarkerLeaveBox(hitElement)
	if (isElement(hitElement) and getElementType(hitElement) == "player") then
		if TbPlEmp[hitElement] and source == TbPlEmp[hitElement]["marker"] then
			if TbPlEmp[hitElement]["box"] and isElement(TbPlEmp[hitElement]["box"]) and isElementWithinMarker(TbPlEmp[hitElement]["box"],source) then
				outputChatBox("#FFAA00||#00FF00  ✔ #FFAA00||#00FF00 ok !",hitElement,255,255,255,true)
			else
				outputChatBox("#FFAA00||#FF0000  ✘ #FFAA00||#FF0000 error !",hitElement,255,255,255,true)
			end
		end
	end
end
addEventHandler("onMarkerHit",root,PlayerHitInMarkerLeaveBox)

All I did was set the box's position to the same position, you might think that it makes no sense but it should work.

Posted
9 hours ago, MIKI785 said:

All I did was set the box's position to the same position, you might think that it makes no sense but it should work.

note : not is postion (1558,2779.2048,-2485.4523) is correct: (2779.2048,-2485.4523,13.1577)

And it did not work

Posted (edited)
TbPlEmp = {}

function StartJobEmpilhadeiraForPlayer(source)
    --> verifica se não há uma tabela e cria uma no nome do player !
    if not(TbPlEmp[source]) then
        TbPlEmp[source] = {}
    end
    --> Verifica se o player tem um veículo e destroy se houver !
    if TbPlEmp[source]["veh"] then
        destroyElement(TbPlEmp[source]["veh"])
        TbPlEmp[source]["veh"] = nil
    end
    TbPlEmp[source]["veh"] = createVehicle(530,2799,-2401,13,0,0,93)
    warpPedIntoVehicle(source,TbPlEmp[source]["veh"])
    TbPlEmp[source]["box"] = createObject(1558,2779,-2401,13.3,0,0,0,false)
    TbPlEmp[source]["marker"] = createMarker(2724,-2401,12,"cylinder",3,0,255,150,255,source)
end

addCommandHandler("cc",function()
StartJobEmpilhadeiraForPlayer(getRandomPlayer())
end)

function PlayerHitInMarkerLeaveBox(hitElement)
    if (isElement(hitElement) and getElementType(hitElement) == "player") then
        if TbPlEmp[hitElement] and source == TbPlEmp[hitElement]["marker"] then
            if TbPlEmp[hitElement]["box"] and isElement(TbPlEmp[hitElement]["box"]) then
            local x,y,z = getElementPosition(TbPlEmp[hitElement]["box"])
            local x1,y1,z1 = getElementPosition(source)
            outputChatBox(getDistanceBetweenPoints3D ( x,y,z,x1,y1,z1 ))
            if getDistanceBetweenPoints3D ( x,y,z,x1,y1,z1 ) < 56 then    
            outputChatBox("#FFAA00||#00FF00  ✔ #FFAA00||#00FF00 ok !",hitElement,255,255,255,true)
            else
            outputChatBox("#FFAA00||#FF0000  ✘ #FFAA00||#FF0000 error !",hitElement,255,255,255,true)      
            end
            end
        end
    end
end
addEventHandler("onMarkerHit",root,PlayerHitInMarkerLeaveBox)

this might work.When in-game type /cc to check change the positions of object as per your need

Edited by Ayush Rathore
Posted
2 hours ago, Ayush Rathore said:

this might work.When in-game type /cc to check change the positions of object as per your need

I liked it more, it's still not correct because the player with or without box will always return true and I want it to really carry the box up to the marker!

I could see from your output that the box position is not updated as it moves .. why does this happen?

Posted
11 minutes ago, Ayush Rathore said:

the only solution to your problem is attaching object to forklift as gta physics engine do not capture the event when forklift picks up an oject

I can not think of any way to do this!
Any idea ?

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