Tails Posted November 17, 2016 Share Posted November 17, 2016 (edited) 1 hour ago, Dzsozi said: It is still not working for some reason. Oops, some of it was wrong haha -- I changed district[i] to district[i][1], since you're storing the -- colshapes in an array. remove the the {} brackets where you store -- the colshape, then you can do district[i]. Also again, a player check. -- Everything's working now. addEvent("onDistrictChange", true) function districtChangeEvent(hitElement) if hitElement == localPlayer then for i=1,#district do if district[i][1] == source then triggerEvent("onDistrictChange", hitElement, districts[i][5]) end end end end addEventHandler("onClientColShapeHit", root, districtChangeEvent) Edited November 17, 2016 by Tails Link to comment
Dzsozi (h03) Posted November 17, 2016 Author Share Posted November 17, 2016 It works now, thank you! I also had to make some changes in the test resource: function test2(districtName) outputChatBox(getPlayerName(getLocalPlayer()).." entered "..districtName) end addEventHandler("onDistrictChange", getRootElement(), test2) If anybody is interested here's the full script: local district = {} local districts = { -- x, y, width, height, name -- insert your custom districts here { 0, 0, 100, 100, "Example District Name", 255, 225, 255 }, -- last three variables are the color of the radar area } function createDistricts() for k, v in ipairs(districts) do --createRadarArea(v[1], v[2], v[3], v[4], v[6], v[7], v[8], 75) -- to make the districts visible on the radar, use setDevelopmentMode(true) and /showcol 1 command to see the colshapes in the real world with a wireframe around it table.insert(district, {createColCuboid(v[1], v[2], -50, v[3]/1.5, v[4]/1.5, 1000)}) end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), createDistricts) addEvent("onDistrictChange", true) function districtChangeEvent(hitElement) if hitElement and isElement(hitElement) then for i=1,#district do if district[i][1] == source then triggerEvent("onDistrictChange", hitElement, districts[i][5]) end end end end addEventHandler("onClientColShapeHit", root, districtChangeEvent) function getDistrictName(element) if isElement(element) then for i=1,#district do if isElementWithinColShape(element,district[i][1]) then return districts[i][5] end end return "" end end And the meta: <meta> <script src="districtC.lua" type="client" /> <export function="getDistrictName" type="client"/> <export function="onDistrictChange" type="client"/> </meta> 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