aotlunla Posted March 12, 2019 Share Posted March 12, 2019 (edited) How can I make something like invisible wall to keep player in the area I want. I mean blocking them out to other area or city. in the sea and air too. sorry my for my English. Edited March 12, 2019 by aotlunla Link to comment
XaskeL Posted March 12, 2019 Share Posted March 12, 2019 (edited) function getCoordsSize(x,y,sx,sy) local data = {} if x > sx then data["max_x"] = x; data["min_x"] = sx; else data["max_x"] = sx; data["min_x"] = x; end if y > sy then data["max_y"] = y; data["min_y"] = sy; else data["max_y"] = sy; data["min_y"] = y; end return data["min_x"], data["min_y"], data["max_x"]-data["min_x"], data["max_y"]-data["min_y"] end function isElementInGameZone(element, areax, areay, sizex, sizey, maxz) local x,y,z = getElementPosition(element) local _,_, rotation = getElementRotation(element) local offset = math.rad(rotation + 90) local aX = x + (-0.3) * math.cos(offset) local aY = y + (-0.3) * math.sin(offset) if (x >= areax and x <= areax + sizex ) and ( y >= areay and y <= areay + sizey ) then setElementPosition(aX, aY, z + 0.1, false) -- borders elseif (maxz and z > maxz) then setElementPosition(x,y, maxz - 3, false) end end The functions are written which can be useful for this. I am not very good at math, so maybe something is wrong local g_GameZones = { { startx = 0, starty = 0, endx = 5, endy = 5, maxz = 30 }, } addEventHandler('onClientResourceStart', resourceRoot, function() for i, v in ipairs(g_GameZones) do local areax, areay, sizex, sizey = getCoordsSize(v.startx, v.starty, v.endx, v.endy) g_GameZones[i] = { startx = areax, starty = areay, endx = sizex, endy = sizey, maxz = v.maxz }; end end ); addEventHandler('onClientRender', root, function() local gZone = g_GameZones[1] -- zone id 1 isElementInGameZone(localPlayer, gZone.startx, gZone.starty, gZone.endx, gZone.endy, gZone.maxz) -- soft teleport end ); try Edited March 12, 2019 by XaskeL 1 Link to comment
aotlunla Posted March 12, 2019 Author Share Posted March 12, 2019 3 hours ago, XaskeL said: function getCoordsSize(x,y,sx,sy) local data = {} if x > sx then data["max_x"] = x; data["min_x"] = sx; else data["max_x"] = sx; data["min_x"] = x; end if y > sy then data["max_y"] = y; data["min_y"] = sy; else data["max_y"] = sy; data["min_y"] = y; end return data["min_x"], data["min_y"], data["max_x"]-data["min_x"], data["max_y"]-data["min_y"] end function isElementInGameZone(element, areax, areay, sizex, sizey, maxz) local x,y,z = getElementPosition(element) local _,_, rotation = getElementRotation(element) local offset = math.rad(rotation + 90) local aX = x + (-0.3) * math.cos(offset) local aY = y + (-0.3) * math.sin(offset) if (x >= areax and x <= areax + sizex ) and ( y >= areay and y <= areay + sizey ) then setElementPosition(aX, aY, z + 0.1, false) -- borders elseif (maxz and z > maxz) then setElementPosition(x,y, maxz - 3, false) end end The functions are written which can be useful for this. I am not very good at math, so maybe something is wrong local g_GameZones = { { startx = 0, starty = 0, endx = 5, endy = 5, maxz = 30 }, } addEventHandler('onClientResourceStart', resourceRoot, function() for i, v in ipairs(g_GameZones) do local areax, areay, sizex, sizey = getCoordsSize(v.startx, v.starty, v.endx, v.endy) g_GameZones[i] = { startx = areax, starty = areay, endx = sizex, endy = sizey, maxz = v.maxz }; end end ); addEventHandler('onClientRender', root, function() local gZone = g_GameZones[1] -- zone id 1 isElementInGameZone(localPlayer, gZone.startx, gZone.starty, gZone.endx, gZone.endy, gZone.maxz) -- soft teleport end ); try thanks bro. I'm gonna try. Link to comment
Ab-47 Posted March 13, 2019 Share Posted March 13, 2019 That way is more sophisticated and onClientRender will use a lot of memory, easiest and best way to do it is use create a table of positions then use createObject in a loop through the data in the table (positions), set a perimeter using any object you like, then create a loop that runs 1 time to setElementAlpha(object, 0) of all objects in the table. Easiest way to create the objects is literally map editor, create all of them then convert the .map file to .lua Whichever solution you find best, you can go with. XasKel's way seems better in the sense of reversing the position if it's out of bounds, with maps they're fixed objects and only obstruct a player, not stop them. So if an element is fast enough, it could warp through the map object but you'd need to be at a ridiculous speed to do that. I guess it's to do with the rendering of the model, so all depends on the clients CPU honestly. 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