fairyoggy Posted June 15, 2021 Share Posted June 15, 2021 function duty(thePlayer) local jobs = getElementsByType("marker") for index, jobs in pairs(jobs) do local checkjob = getElementByID("1") local checkjob2 = getElementByID("2") if isElementWithinMarker(thePlayer, jobs) then if jobs == checkjob then outputChatBox("1 job", thePlayer, 255, 0, 0) elseif jobs == checkjob2 then outputChatBox("2 job", thePlayer, 255, 0, 0) end else outputChatBox("not marker", thePlayer, 255, 0, 0) end end end addCommandHandler("duty", duty) Everything works as I want, but there is one nuance. If the player is outside the markers, then the message is duplicated. I guess this is because 2 markers were created, so 2 message. How to fix it? What would be one message Screen Link to comment
SpecT Posted June 15, 2021 Share Posted June 15, 2021 You don't need to use loop since you already got the elements (markers) by ID. So you just check if the player is within them. function duty(thePlayer) local checkjob = getElementByID("1") local checkjob2 = getElementByID("2") if type(checkjob) == "marker" and type(checkjob) == "marker" then -- just to be sure they are markers if isElementWithinMarker(thePlayer, checkjob) then outputChatBox("1 job", thePlayer, 255, 0, 0) elseif isElementWithinMarker(thePlayer, checkjob2) then outputChatBox("2 job", thePlayer, 255, 0, 0) else outputChatBox("not marker", thePlayer, 255, 0, 0) end end end addCommandHandler("duty", duty) 1 Link to comment
fairyoggy Posted June 16, 2021 Author Share Posted June 16, 2021 On 15/06/2021 at 09:05, SpecT said: You don't need to use loop since you already got the elements (markers) by ID. So you just check if the player is within them. function duty(thePlayer) local checkjob = getElementByID("1") local checkjob2 = getElementByID("2") if type(checkjob) == "marker" and type(checkjob) == "marker" then -- just to be sure they are markers if isElementWithinMarker(thePlayer, checkjob) then outputChatBox("1 job", thePlayer, 255, 0, 0) elseif isElementWithinMarker(thePlayer, checkjob2) then outputChatBox("2 job", thePlayer, 255, 0, 0) else outputChatBox("not marker", thePlayer, 255, 0, 0) end end end addCommandHandler("duty", duty) Okay, but how to convert this code if adding "setElementID" without code I mean, no code editing like this: local checkjob = getElementByID("1") local checkjob2 = getElementByID("2") local checkjob3 = getElementByID("3") local checkjob4 = getElementByID("4") local checkjob5 = getElementByID("5") local checkjob6 = getElementByID("6") local checkjob7 = getElementByID("7") local checkjob8 = getElementByID("8") local checkjob9 = getElementByID("9") I made the creation of these objects through the game, but how can I make the correct check for this. Link to comment
fairyoggy Posted June 16, 2021 Author Share Posted June 16, 2021 (edited) or let's do it differently function duty(thePlayer) local marker = getElementsByType("marker") for i, marx in pairs(marker) do local id = getElementID(marx) outputChatBox(id, thePlayer, 255, 0, 0) end end addCommandHandler("duty", duty) Let's say we have 2 markers with ElementID Quote 1) ElementID("1") 2) ElementID("2") How can I correctly implement a check for an element id ? use this: isElementWithinMarker -- or isElementWithinColShape There should be something similar to the code above, but without using(if there are more objects): local checkjob = getElementByID("1") local checkjob2 = getElementByID("2") local checkjob3 = getElementByID("3") local checkjob4 = getElementByID("4") local checkjob5 = getElementByID("5") local checkjob6 = getElementByID("6") local checkjob7 = getElementByID("7") local checkjob8 = getElementByID("8") local checkjob9 = getElementByID("9") The idea is that when a player steps on a marker and writes a command, a message appears with a element ID Edited June 16, 2021 by oggygod Link to comment
SpecT Posted June 16, 2021 Share Posted June 16, 2021 (edited) Well, you will need to use tables when it comes to more elements (jobs). I don't know maybe something like this ? function duty(thePlayer) local jobsCount = 10 local foundJob = false for i=1, jobsCount do local checkjob = getElementByID(tostring(i)) if type(checkjob) == "marker" then if isElementWithinMarker(thePlayer, checkjob) then outputChatBox("this marker is for job number "..i, thePlayer, 255, 0, 0) foundJob = true break -- if it finds the marker the player is in => stop the loop end end end if not foundJob then outputChatBox("not within a marker", thePlayer, 255, 0, 0) end end addCommandHandler("duty", duty) Edited June 16, 2021 by SpecT removed the duplicated "type" check; 1 Link to comment
fairyoggy Posted June 16, 2021 Author Share Posted June 16, 2021 42 minutes ago, SpecT said: Well, you will need to use tables when it comes to more elements (jobs). I don't know maybe something like this ? function duty(thePlayer) local jobsCount = 10 local foundJob = false for i=1, jobsCount do local checkjob = getElementByID(tostring(i)) if type(checkjob) == "marker" and type(checkjob) == "marker" then if isElementWithinMarker(thePlayer, checkjob) then outputChatBox("this marker is for job number "..i, thePlayer, 255, 0, 0) foundJob = true break -- if it finds the marker the player is in => stop the loop end end end if not foundJob then outputChatBox("not within a marker", thePlayer, 255, 0, 0) end end addCommandHandler("duty", duty) Exactly what is needed. This will help me. Thank you so much 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now