IndeX' Posted April 20, 2014 Share Posted April 20, 2014 Hello, my question is this. I want to know if there is any resource that blocks auto respawn in certain "zones". For example: In CJ that people can not choose from the menu of auto F1. Is this possible?. Link to comment
justn Posted April 20, 2014 Share Posted April 20, 2014 What do you mean ? are you talking about the freeroam resource ? If yes then you can edit the places to respawn in the meta.xml file. Link to comment
IndeX' Posted April 20, 2014 Author Share Posted April 20, 2014 Sure, I have a freeroam server, and I want to do is that in certain areas I choose coordinate vehicles can not choose from the menu of F1. ( sorry for my english ) Link to comment
Moderators Citizen Posted April 20, 2014 Moderators Share Posted April 20, 2014 Ok, I just made a standalone script that will hide the panel immediatly if a player opens it in a forbidden area. You have to put this in your gamemode that must runs with the freeroam/play resource: local forbiddenAreas = { --x, y, width, height {0, 0, 50, 50}, --example1 (needs a ',' because it's not the last) {-500, -1613, 50, 50} --example2 (no need a ',' because it's the last) } addEventHandler("onResourceStart", resourceRoot, function() for k, i in ipairs(forbiddenAreas) do local col = createColRectangle(i[1], i[2], i[3], i[4]) addEventHandler("onColShapeHit", root, function ( hitElement ) if getElementType(hitElement) ~= "player" then return end setElementData(hitElement, "isInForbiddenArea", true) end) addEventHandler("onColShapeLeave" root, function( leaveElement ) if getElementType(leaveElement) ~= "player" then return end setElementData(leaveElement, "isInForbiddenArea", false) end) end end) addeEventHandler("onPlayerJoin", root, function() bindKey(source, "f1", "down" openF1) end) function openF1( player, preventLoop ) if preventLoop == false and getElementData(player, "isInForbiddenArea") then executeCommandHandler("fr", player, true) end end addCommandHandler("fr", openF1) (I didn't test the code, quote the errors if any.) Link to comment
IndeX' Posted April 26, 2014 Author Share Posted April 26, 2014 Hi Citizen thanks for taking the time to make that script. There are syntax errors. With respect to the operation of the code, I could not make it work local forbiddenAreas = { --x, y, width, height {1801, -1897, 250, 250}, --example1 (needs a ',' because it's not the last) {-500, -1613, 50, 50} --example2 (no need a ',' because it's the last) } addEventHandler('onResourceStart', resourceRoot, function() for k, i in ipairs(forbiddenAreas) do local col = createColRectangle(i[1], i[2], i[3], i[4]) addEventHandler('onColShapeHit', root, function ( hitElement ) if getElementType(hitElement) ~= 'player' then return end setElementData(hitElement, 'isInForbiddenArea', true) end) addEventHandler('onColShapeLeave', root, function( leaveElement ) if getElementType(leaveElement) ~= 'player' then return end setElementData(leaveElement, 'isInForbiddenArea', false) end) end end) addEventHandler('onPlayerJoin', root, function() bindKey(source, 'f1', 'down', openF1) end) function openF1( player, preventLoop ) if preventLoop == false and getElementData(player, 'isInForbiddenArea') then executeCommandHandler('fr', player, true) end end addCommandHandler('fr', openF1) Link to comment
Moderators Citizen Posted April 26, 2014 Moderators Share Posted April 26, 2014 There are syntax errors. Tell me the errors then EDIT: Try again with this: local forbiddenAreas = { --x, y, width, height {0, 0, 50, 50}, --example1 (needs a ',' because it's not the last) {-500, -1613, 50, 50} --example2 (no need a ',' because it's the last) } addEventHandler("onResourceStart", resourceRoot, function() for k, i in ipairs(forbiddenAreas) do local col = createColRectangle(i[1], i[2], i[3], i[4]) addEventHandler("onColShapeHit", col, function ( hitElement ) if getElementType(hitElement) ~= "player" then return end setElementData(hitElement, "isInForbiddenArea", true) outputChatBox("You entered in the forbidden area !", hitElement) end) addEventHandler("onColShapeLeave" col, function( leaveElement ) if getElementType(leaveElement) ~= "player" then return end setElementData(leaveElement, "isInForbiddenArea", false) outputChatBox("You left the forbidden area !", leaveElement) end) end end) addeEventHandler("onPlayerJoin", root, function() bindKey(source, "f1", "down" openF1) end) function openF1( player, preventLoop ) if preventLoop ~= true and getElementData(player, "isInForbiddenArea") then executeCommandHandler("fr", player, true) end end addCommandHandler("fr", openF1) I used root instead of col for the colshape events and replaced preventLoop == false with preventLoop ~= true. I also added 2 outputs to let you be sure you really are in a forbidden area. Link to comment
IndeX' Posted April 27, 2014 Author Share Posted April 27, 2014 syntax error, Example: Line 16: addEventHandler("onColShapeLeave" col, function( leaveElement ) --> addEventHandler("onColShapeLeave", col, function( leaveElement ) Line 25: addeEventHandler("onPlayerJoin", root, function() --> addEventHandler("onPlayerJoin", root, function() Line 26: bindKey(source, "f1", "down" openF1) --> bindKey(source, "f1", "down", openF1) --------------------------------------------------------------------------------------- The script seems to work, but not as it should: --------------------------------------------------------------------------------------- Warning: Thanks for your time Link to comment
Moderators Citizen Posted April 28, 2014 Moderators Share Posted April 28, 2014 Ah my bad, just replace lines 29 to 34 with this: local randomSecret = "secret_" + math.random(10000) --kind of bypass prevention function openF1( player, cmd, preventLoop ) if preventLoop ~= randomSecret and getElementData(player, "isInForbiddenArea") then executeCommandHandler("fr", player, randomSecret) end end addCommandHandler("fr", openF1) I added a random generated string to be used instead of "true" (as a string) because everyone would be able to bypass it by doing /fr true Link to comment
IndeX' Posted April 29, 2014 Author Share Posted April 29, 2014 still not working as it should but taking the match.random or secret, the script is activated but the menu is appearing F1 Link to comment
Moderators Citizen Posted April 29, 2014 Moderators Share Posted April 29, 2014 Replace + with .. for the randomSecret Link to comment
IndeX' Posted April 30, 2014 Author Share Posted April 30, 2014 I already made replacement but the menu still appears thanks for your time Link to comment
Moderators Citizen Posted April 30, 2014 Moderators Share Posted April 30, 2014 Ok I stopped trying to make it without testing it myself (didn't know I would get problems I had). I made it work, but there is something strange that should be reported to the bugtracker: the executeCommandHandler doesn't execute the comands on the other side (only tested from server-side to client side commands, but I'm pretty sure the other way doesn't work too). I mean that if I use executeCommandHandler("fr", player) on the server-side, then it will not execute this commands on the client-side of that player, only addCommandHandler for "fr" on the server-side only will work. So if you understood right, I had to make a triggerClientEvent to then run the executeCommandHandler on the client-side (as the freeroam resource added this command on the client-side). server: function bindF1( param ) if param then for k, i in ipairs(getElementsByType("player")) do bindKey(i, "f1", "down", openF1) end else bindKey(source, "f1", "down", openF1) end end addEventHandler("onResourceStart", resourceRoot, bindF1) addEventHandler("onPlayerJoin", root, bindF1) local randomSecret = "secret_" .. math.random(10000) --kind of bypass prevention function openF1( player, cmd, preventLoop ) if preventLoop ~= randomSecret and getElementData(player, "isInForbiddenArea") then triggerClientEvent("forcePressF1", player, randomSecret) end end addCommandHandler("fr", openF1) client: addEvent("forcePressF1", true) addEventHandler("forcePressF1", root, function ( secret ) executeCommandHandler("fr", secret) end) I have tested it and it works, but if you spam the F1 key, then you will just see it blicking, but you still can't use it Link to comment
IndeX' Posted May 1, 2014 Author Share Posted May 1, 2014 Thank you very much for your time regards Link to comment
Moderators Citizen Posted May 2, 2014 Moderators Share Posted May 2, 2014 No problem, and sorry because this script should have work since my 1st post (but wouldn't support a restart for players already in game and using F1 key). I didn't know the bug (I guess it's a non scripting behaviour) about that executeCommandHandler. Have fun coding. Link to comment
Moderators Citizen Posted May 8, 2014 Moderators Share Posted May 8, 2014 From PMs: Hi, how you doing?wanted to talk about the script block F1(freeroam), is there anyway to create the option to lock vehicles and not to block the entire menu?... I say this because I had a problem when loading the script to the server, when I approached the area blocked the F1 opened me and I just closed the whole menu, but I only spent ami if that happened to everyone Video (f1 bug): https://vimeo.com/94401909 --Sorry for my english Try with this: (check the comments to see what I added) server: local forbiddenAreas = { {0, 0, 50, 50}, {-500, -1613, 50, 50} } addEventHandler("onResourceStart", resourceRoot, function() for k, i in ipairs(forbiddenAreas) do local col = createColRectangle(i[1], i[2], i[3], i[4]) addEventHandler("onColShapeHit", root, function ( hitElement ) if getElementType(hitElement) ~= "player" then return end setElementData(hitElement, "isInForbiddenArea", true) if getElementData(hitElement, "isF1MenuOpened") then -- added triggerClientEvent("forcePressF1", hitElement, randomSecret) -- added end -- added end) addEventHandler("onColShapeLeave" root, function( leaveElement ) if getElementType(leaveElement) ~= "player" then return end setElementData(leaveElement, "isInForbiddenArea", false) end) end end) function bindF1( param ) if param then for k, i in ipairs(getElementsByType("player")) do bindKey(i, "f1", "down", openF1) end else bindKey(source, "f1", "down", openF1) end end addEventHandler("onResourceStart", resourceRoot, bindF1) addEventHandler("onPlayerJoin", root, bindF1) local randomSecret = "secret_" .. math.random(10000) function openF1( player, cmd, preventLoop ) setElementData(hitElement, "isF1MenuOpened", true) -- added if preventLoop ~= randomSecret and getElementData(player, "isInForbiddenArea") then triggerClientEvent("forcePressF1", player, randomSecret) end end addCommandHandler("fr", openF1) client: addEvent("forcePressF1", true) addEventHandler("forcePressF1", root, function ( secret ) executeCommandHandler("fr", secret) setElementData(localPlayer, "isF1MenuOpened", false) -- added end) If this is not working properly, then I'll just do the whole thing using another way. I didn't want to make modifications into the freeroam resource itself to keep this modification seperated. So I'll just export 2 freeroam functions and use them from your resource. 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