nurfaizfy19 Posted January 29, 2019 Share Posted January 29, 2019 (edited) Hello, sorry for my bad english i have turf war script, for example i have function to create area turf mysql = exports.mysql local pCuboid = nil local pArea = nil function loadAllTurf(res) local result = mysql:query("SELECT id FROM `turf` ORDER BY `id` ASC") if (result) then local run = true while run do local row = mysql:fetch_assoc(result) if not row then break end if res then loadOneTurf(row['id'], true) else loadOneTurf(row['id']) end end end mysql:free_result(result) exports['global']:sendMessageToAdmins("All area turf loaded") end addEventHandler("onResourceStart", getResourceRootElement(), loadAllTurf) function loadOneTurf(id, state) local row = mysql:query_fetch_assoc("SELECT * FROM turf WHERE id = '"..mysql:escape_string(id).."'") if row then local id = tonumber(row['id']) local name = row['turf_name'] local owner = tonumber(row['owner_id']) local r, g, b = tonumber(row['r']), tonumber(row['g']), tonumber(row['b']) local x, y, z = tonumber(row['turfx']), tonumber(row['turfy']), tonumber(row['turfz']) local long, width = tonumber(row['turflong']), tonumber(row['turfwidth']) local ownerName = exports.factions:getFactionName(owner) pCuboid = createColCuboid(x, y, z-10, long, width, z+30) pArea = createRadarArea(x, y, long, width, r, g, b, 100 ) hideTurf(pArea) exports.pool:allocateElement(pCuboid) setElementInterior(pCuboid, 0) setElementDimension(pCuboid, 0) addEventHandler("onColShapeHit", pCuboid, onTurfEnter) addEventHandler("onColShapeLeave", pCuboid, onTurfLeave) exports.anticheat:changeProtectedElementDataEx(pCuboid, "turf", true, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "id", id, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "x", x, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "y", y, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "z", z-10, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "name", name, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "owner", owner, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "long", long, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "width", width, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "friendly", owner, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "radar", pArea, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "payment", math.floor((long*width)/20), false) exports.anticheat:changeProtectedElementDataEx(pArea, "turf", true, false) exports.anticheat:changeProtectedElementDataEx(pArea, "x", x, false) exports.anticheat:changeProtectedElementDataEx(pArea, "y", y, false) exports.anticheat:changeProtectedElementDataEx(pArea, "long", long, false) exports.anticheat:changeProtectedElementDataEx(pArea, "width", width, false) exports.anticheat:changeProtectedElementDataEx(pArea, "owner", owner, false) exports.anticheat:changeProtectedElementDataEx(pArea, "r", r, false) exports.anticheat:changeProtectedElementDataEx(pArea, "g", g, false) exports.anticheat:changeProtectedElementDataEx(pArea, "b", b, false) end end and I want to hide the turf area on players who are not in faction by checking every 5 seconds, I've tried using the script below but it doesn't work function checkPlayersInTeam(area) for _, player in ipairs(exports.pool:getPoolElementsByType("player")) do if getElementData(player, "loggedin") then local Team = getPlayerTeam(player) local factionType = getElementData(Team, "type") or 99 if (factionType==0) then setElementVisibleTo(area, player, true) -- i want to show the area to player who factiontype is 0 (when i change player with root it works show the area) else setElementVisibleTo(area, player, false) -- i want to hide the area to player who factiontype is not 0 (when i change player with root it works hide the area) end end end end function hideTurf(area) setTimer(checkPlayersInTeam, 5000, 0, area) end can anyone help me? thank you very much Edited January 29, 2019 by nurfaizfy19 added some code Link to comment
Simple. Posted January 29, 2019 Share Posted January 29, 2019 (edited) 1 hour ago, nurfaizfy19 said: Hello, sorry for my bad english i have turf war script, for example i have function to create area turf mysql = exports.mysql local pCuboid = nil local pArea = nil function loadAllTurf(res) local result = mysql:query("SELECT id FROM `turf` ORDER BY `id` ASC") if (result) then local run = true while run do local row = mysql:fetch_assoc(result) if not row then break end if res then loadOneTurf(row['id'], true) else loadOneTurf(row['id']) end end end mysql:free_result(result) exports['global']:sendMessageToAdmins("All area turf loaded") end addEventHandler("onResourceStart", getResourceRootElement(), loadAllTurf) function loadOneTurf(id, state) local row = mysql:query_fetch_assoc("SELECT * FROM turf WHERE id = '"..mysql:escape_string(id).."'") if row then local id = tonumber(row['id']) local name = row['turf_name'] local owner = tonumber(row['owner_id']) local r, g, b = tonumber(row['r']), tonumber(row['g']), tonumber(row['b']) local x, y, z = tonumber(row['turfx']), tonumber(row['turfy']), tonumber(row['turfz']) local long, width = tonumber(row['turflong']), tonumber(row['turfwidth']) local ownerName = exports.factions:getFactionName(owner) pCuboid = createColCuboid(x, y, z-10, long, width, z+30) pArea = createRadarArea(x, y, long, width, r, g, b, 100 ) hideTurf(pArea) exports.pool:allocateElement(pCuboid) setElementInterior(pCuboid, 0) setElementDimension(pCuboid, 0) addEventHandler("onColShapeHit", pCuboid, onTurfEnter) addEventHandler("onColShapeLeave", pCuboid, onTurfLeave) exports.anticheat:changeProtectedElementDataEx(pCuboid, "turf", true, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "id", id, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "x", x, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "y", y, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "z", z-10, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "name", name, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "owner", owner, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "long", long, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "width", width, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "friendly", owner, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "radar", pArea, false) exports.anticheat:changeProtectedElementDataEx(pCuboid, "payment", math.floor((long*width)/20), false) exports.anticheat:changeProtectedElementDataEx(pArea, "turf", true, false) exports.anticheat:changeProtectedElementDataEx(pArea, "x", x, false) exports.anticheat:changeProtectedElementDataEx(pArea, "y", y, false) exports.anticheat:changeProtectedElementDataEx(pArea, "long", long, false) exports.anticheat:changeProtectedElementDataEx(pArea, "width", width, false) exports.anticheat:changeProtectedElementDataEx(pArea, "owner", owner, false) exports.anticheat:changeProtectedElementDataEx(pArea, "r", r, false) exports.anticheat:changeProtectedElementDataEx(pArea, "g", g, false) exports.anticheat:changeProtectedElementDataEx(pArea, "b", b, false) end end and I want to hide the turf area on players who are not in faction by checking every 5 seconds, I've tried using the script below but it doesn't work function checkPlayersInTeam(area) for _, player in ipairs(exports.pool:getPoolElementsByType("player")) do if getElementData(player, "loggedin") then local Team = getPlayerTeam(player) local factionType = getElementData(Team, "type") or 99 if (factionType==0) then setElementVisibleTo(area, player, true) -- i want to show the area to player who factiontype is 0 (when i change player with root it works show the area) else setElementVisibleTo(area, player, false) -- i want to hide the area to player who factiontype is not 0 (when i change player with root it works hide the area) end end end end function hideTurf(area) setTimer(checkPlayersInTeam, 5000, 0, area) end can anyone help me? thank you very much the code is working for me but try to make a table for areas like this pArea = {} pArea[id] = createRadarArea(50, 100, 200, 500, 255, 0, 0, 100 ) Edited January 29, 2019 by Simple. Link to comment
nurfaizfy19 Posted January 29, 2019 Author Share Posted January 29, 2019 6 hours ago, Simple. said: the code is working for me but try to make a table for areas like this pArea = {} pArea[id] = createRadarArea(50, 100, 200, 500, 255, 0, 0, 100 ) how can it work for you? i tried your suggest but i've got error Quote turf\server.lua:87: attempt to index local 'pArea' (a userdata value) function checkPlayersInTeam() for _, player in ipairs(exports.pool:getPoolElementsByType("player")) do if getElementData(player, "loggedin") then local Team = getPlayerTeam(player) local factionType = getElementData(Team, "type") or 99 for key, pArea in ipairs(pArea) do if (factionType==0) then setElementVisibleTo(pArea[key], player, true) else setElementVisibleTo(pArea[key], player, false) -- line 87 end end end end end function hideTurf() setTimer(checkPlayersInTeam, 5000, 0) end Link to comment
nurfaizfy19 Posted January 29, 2019 Author Share Posted January 29, 2019 Oke, i solve this problem. I just add setElementVisibleTo to root and player, and now its work normally. Thanks for your helping Link to comment
Moderators IIYAMA Posted January 29, 2019 Moderators Share Posted January 29, 2019 (edited) 40 minutes ago, nurfaizfy19 said: Oke, i solve this problem. I just add setElementVisibleTo to root and player, and now its work normally. Thanks for your helping If you do that every 5 seconds forever, then ask the question: "is your network activity not in progress forever?" Make sure to check that! /shownetstat Edited January 29, 2019 by IIYAMA 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