Cronoss Posted January 28, 2022 Share Posted January 28, 2022 Hello I was wondering... it is possible to edit this script? so instead of triggering the Gui panel "on marker hit" , the trigger event happens when the player press a letter. If is it possible I would like the explanation too, because I'm new at this, you can tell by my recent posts addEventHandler("onPlayerMarkerHit", getRootElement(), function(markerHit, matchingDimension) for id, marker in pairs(_marker) do if (markerHit == marker.marker) then triggerClientEvent(source, "vehicles:CarshopShowMenu", source, marker.marker:getData("vehicles:shop_name"), marker.marker:getData("vehicles:shop_data"), marker.marker:getData("vehicles:name"), marker.marker:getData("vehicles:price")) end end end) Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) If you want to do this with the key, you will need to do a little more code. You have to bind the key both when you start the resource and when a new player enters the game. server: addEventHandler("onResourceStart", resourceRoot, function() for _,player in ipairs(getElementsByType("player")) do -- pull all players when resource starts bindKey(player, "B", "down", toggleCarShopMenu) -- bind the b key to the toggleCarShopMenu function for this player end end ) addEventHandler("onPlayerJoin", root, function() bindKey(source, "B", "down", toggleCarShopMenu) -- bind b key to toggleCarShopMenu function for newly joined player end ) function toggleCarShopMenu(player) for id,marker in pairs(_marker) do if(isElementWithinMarker(player, marker.marker)) then -- Is the player inside any marker found in this loop? triggerClientEvent(player, "vehicles:CarshopShowMenu", player, marker.marker:getData("vehicles:shop_name"), marker.marker:getData("vehicles:shop_data"), marker.marker:getData("vehicles:name"), marker.marker:getData("vehicles:price")) -- if so call menu break -- break loop end end end Edited January 28, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 29, 2022 Author Share Posted January 29, 2022 (edited) I wanted to add instructions when the player enter on a marker, I tested and it works, but, is there a better way to make the same action with another command? addEventHandler("onPlayerMarkerHit", root, function() outputChatBox("Presiona la H para acceder al panel", source) end ) ->this includes ALL the markers, that's why I'm asking Edited January 29, 2022 by Cronoss Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 (edited) 11 minutes ago, Cronoss said: I wanted to add instructions when the player enter on a marker, I tested and it works, but, is there a better way to make the same action with another command? addEventHandler("onPlayerMarkerHit", root, function() outputChatBox("Presiona la H para acceder al panel", source) end ) this code will work when you hit all the markers in the game only if you want it for the shop menu, check it with the marker hit by the player with the for loop other than that, your code looks good, there is no problem example: addEventHandler("onPlayerMarkerHit", root, function(markerHit, matchingDimension) for id,marker in pairs(_marker) do -- only for shop markers if(markerHit == marker.marker) then outputChatBox("Presiona la H para acceder al panel", source) end end end ) Edited January 29, 2022 by Burak5312 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