Cronoss Posted February 17, 2022 Share Posted February 17, 2022 I'm making a marker-system, when the player hit the marker it deletes the current one, and creates a new one, the problem is that debugscript send me "expected element at argument 2, got nil", if I use "root" or "getRootElement()" in that part, it works but FOR EVERY other marker, so it's kinda chaotic... (I'm scripting this in CLIENT-SIDE, because I only want the player who used the command can see the markers, not everybody) I used: ------------------------Initial marker--------------------- function startGH() ---------outputChatBox mark1 = createMarker(1888.5596923828,-2055.2121582031,13.3828125, "checkpoint", 1, 90, 255, 20) ------This is the first marker end addEvent("gah", true) addEventHandler("gah", root, startGH) --------------------------Marker Delete---------------- function markDelete(hitPlayer) iprint("1") if getElementType( hitPlayer ) == "player" and source == mark1 then destroyElement(mark1) local vehicle = getPedOccupiedVehicle(hitPlayer) setElementFrozen(vehicle, true) -------outputChatBox setTimer(function () -------outputChatBox setElementFrozen(vehicle, false) mark2 = createMarker() ---unnecessary info, second marker end, 5000, 1) end end end addEventHandler("onClientMarkerHit", mark1, markDelete) ------got nil Also, I tried using "onMarkerHit" but didn't work, so "onClientMarkerHit" it's the only way that I know that could make possible my system Maybe there's a better way to make a system like this but I don't know how, I tried using a table but it didn't work Link to comment
βurak Posted February 17, 2022 Share Posted February 17, 2022 (edited) you can limit it by using root and using if command actually so you can handle it in a single eventhandler The nil error could possibly be because mark1 has not been created yet example: function markerHandler(hitElement, matchingDimension) if(getElementType(hitElement) == "player") then if(source == mark1) then --codes here for mark1 end if(source == mark2) then --codes here for mark2 end end end addEventHandler("onClientMarkerHit", root, markerHandler) Edited February 17, 2022 by Burak5312 1 1 Link to comment
Cronoss Posted February 17, 2022 Author Share Posted February 17, 2022 My bad, I was trying to make a function for every marker, it caused a lot of problems, this is better than the 200 lines of code that I made, thank you! 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