Hunter567T Posted August 28, 2011 Share Posted August 28, 2011 I know how to make gates work fine by just opening and closing. But what I am trying to do here is make so, that if someone of the same team in in the colsphere it does not close. It opens fine. It is just the closing part I cannot make work fully. It will close fine. But if someone of the same team is in the colsphere it still closes. local SWATgate1 = createObject(3115, 1286, -1651.69, 10, 180, 90) local SWATColSphere1 = createColSphere(1286.67, -1652.15, 13.54, 10) function SWATopen1 (player) if (player and isElement(player) and getElementType(player) == "player") then local t = getPlayerTeam(player) if (getTeamName(t) == "SWAT Team") then moveObject(SWATgate1, 2500, 1286, -1635.2, 10) end end end addEventHandler("onColShapeHit", SWATColSphere1, SWATopen1) function SWATclose1 (player) if (player and isElement(player) and getElementType(player) == "player") then local t1 = getPlayerTeam(player) if (getTeamName(t1) == "SWAT Team") then local detection = isElementWithinColShape (player, SWATColSphere1) if detection == false then moveObject(SWATgate1, 2500, 1286, -1651.69, 10) end end end end addEventHandler("onColShapeLeave", SWATColSphere1, SWATclose1) Link to comment
Castillo Posted August 30, 2011 Share Posted August 30, 2011 (edited) local SWATgate1 = createObject(3115, 1286, -1651.69, 10, 180, 90) local SWATColSphere1 = createColSphere(1286.67, -1652.15, 13.54, 10) function SWATopen1 (player) if (player and isElement(player) and getElementType(player) == "player") then local t = getPlayerTeam(player) if not t1 then return end if (getTeamName(t) == "SWAT Team") then moveObject(SWATgate1, 2500, 1286, -1635.2, 10) end end end addEventHandler("onColShapeHit", SWATColSphere1, SWATopen1) function SWATclose1 (player) if (player and isElement(player) and getElementType(player) == "player") then local t1 = getPlayerTeam(player) if not t1 then return end if (getTeamName(t1) == "SWAT Team") then if countPlayersInColshape(SWATColSphere1) <= 0 then moveObject(SWATgate1, 2500, 1286, -1651.69, 10) end end end end addEventHandler("onColShapeLeave", SWATColSphere1, SWATclose1) function countPlayersInColshape(colshape) local count = 0 for index, player in pairs(getElementsWithinColShape(colshape, "player")) do if getPlayerTeam(player) and getTeamName(getPlayerTeam(player)) == "SWAT Team" then count = count +1 end end return count end Not sure if'll work, I haven't got time to test it. Edited August 31, 2011 by Guest Link to comment
Hunter567T Posted August 30, 2011 Author Share Posted August 30, 2011 Does not work. I tried using "getElementsWithinColSphere" in different ways, but still did not work. Gates do not close at all. However if these 2 lines are removed, they do close. But this does not really help considering I need the gates to close only if someone of the same team is not in the colsphere. for index, player in pairs(getElementsWithinColShape(SWATColSphere1, "player")) do if index <= 0 then Link to comment
NotAvailable Posted August 30, 2011 Share Posted August 30, 2011 Try this code: local SWATgate1 = createObject(3115, 1286, -1651.69, 10, 180, 90) local SWATColSphere1 = createColSphere(1286.67, -1652.15, 13.54, 10) function SWATopen1 (player) if (player and isElement(player) and getElementType(player) == "player") then local t = getTeamFromName("SWAT Team") if (getPlayerTeam(player) == t) then moveObject(SWATgate1, 2500, 1286, -1635.2, 10) end end end addEventHandler("onColShapeHit", SWATColSphere1, SWATopen1) function SWATclose1 (player) if (player and isElement(player) and getElementType(player) == "player") then local t1 = getTeamFromName("SWAT Team") if (getPlayerTeam(player) == t1) then moveObject(SWATgate1, 2500, 1286, -1651.69, 10) end end end addEventHandler("onColShapeLeave", SWATColSphere1, SWATclose1) BTW, why do you need to check if the player is not in the colshape when he leaves? Link to comment
Hunter567T Posted August 30, 2011 Author Share Posted August 30, 2011 Jesseunit, your missing the whole point of why I am asking for help. Your code will open and close the gates just fine. But I'm trying to make the gates so, that they do not close if someone in the "SWAT Team" is inside the colsphere. But what I am trying to do here is make so, that if someone of the same team in in the colsphere it does not close. Link to comment
Castillo Posted August 31, 2011 Share Posted August 31, 2011 Copy my script code again, I've changed some things, seems to work here, try it with another player though. Link to comment
Hunter567T Posted September 1, 2011 Author Share Posted September 1, 2011 Tested it with one player. Then I tested it with another player. Both times it worked! Thanks for the help! 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