JunkDealer Posted May 5, 2015 Share Posted May 5, 2015 Hi. I tried to make freeze alive players when admin/supermoderator/moderator press F5 but it is working sometimes. I mean, 1 map starting and pressing F5 and freezing all. Another map, pressing F5 and nothing happening. Or when press F5, writing in chat but not freezing. Can anyone help me to fix it? server.lua: local aclTable = {"Admin", "SuperModerator", "Moderator"} acik = 1 alivePlayers = getAlivePlayers () function isAdmin(thePlayer) local pAcc = getPlayerAccount(thePlayer) if isGuestAccount(pAcc) then return false end for _, anACL in ipairs(aclTable) do if isObjectInACLGroup('user.'..getAccountName(pAcc), aclGetGroup(anACL)) then return true end end return false end function toggleFreezeStatus ( thePlayer ) for i, thePlayer in ipairs(alivePlayers) do if getPedOccupiedVehicle ( thePlayer ) then local playerVehicle = getPlayerOccupiedVehicle ( thePlayer ) local currentFreezeStatus = isElementFrozen ( playerVehicle ) local newFreezeStatus = not currentFreezeStatus setElementFrozen ( playerVehicle, newFreezeStatus ) end end end function freez ( thePlayer ) local pName = getPlayerNametagText(thePlayer) if acik == 1 then outputChatBox("* All players has been freezed by " .. pName .. ".",root,255,0,0,true) acik = 0 elseif acik == 0 then outputChatBox("* All players has been unfreezed by " .. pName .. ".",root,0,255,0,true) acik = 1 end end for i, thePlayer in ipairs(alivePlayers) do if isAdmin(thePlayer) then bindKey (thePlayer, "F5", "down", toggleFreezeStatus ) bindKey(thePlayer, "F5", "down", freez) end end Link to comment
WhoAmI Posted May 5, 2015 Share Posted May 5, 2015 I'd do it that way local aclTable = {"Admin", "SuperModerator", "Moderator"} frozen = false function isAdmin(thePlayer) local pAcc = getPlayerAccount(thePlayer) if isGuestAccount(pAcc) then return false end for _, anACL in ipairs(aclTable) do if isObjectInACLGroup('user.'..getAccountName(pAcc), aclGetGroup(anACL)) then return true end end return false end function freezeEm ( player ) if ( isAdmin ( player ) ) then local alivePlayers = getAlivePlayers (); frozen = not frozen for _, p in pairs ( alivePlayers ) do if ( isPedInVehicle ( p ) ) then local veh = getPedOccupiedVehicle ( p ) setElementFrozen ( veh, frozen ) end end local text = frozen and "freezed" or "unfreezed" local color = frozen and { 255, 0, 0 } or { 0, 255, 0 } outputChatBox ( "* All players has been " .. text .. " by " .. getPlayerName ( player ) .. ".", root, unpack ( color ), true ); end end function bind ( player ) return bindKey ( player, "F5", "down", freezeEm ); end addEventHandler ( "onResourceStart", resourceRoot, function ( ) for _, player in pairs ( getElementsByType ( "player" ) ) do bind ( player ) end end ); addEventHandler ( "onPlayerJoin", root, function ( ) bind ( player ) end ); Link to comment
JunkDealer Posted May 5, 2015 Author Share Posted May 5, 2015 I get some bugs. No error in debug but color is not working and sometimes when press F5 1 time, it is happening like press 2 or 3 times. Link to comment
Walid Posted May 5, 2015 Share Posted May 5, 2015 I get some bugs. No error in debug but color is not working and sometimes when press F5 1 time, it is happening like press 2 or 3 times. Try this : local aclTable = {"Admin", "SuperModerator", "Moderator"} local frozen = false function isAdmin(thePlayer) local pAcc = getPlayerAccount(thePlayer) if isGuestAccount(pAcc) then return false end for _, anACL in ipairs(aclTable) do if isObjectInACLGroup('user.'..getAccountName(pAcc), aclGetGroup(anACL)) then return true end end return false end function freezeEm ( player ) if not( isAdmin ( player ) ) then return end for _, p in pairs (getAlivePlayers ()) do if ( isPedInVehicle ( p ) ) then local veh = getPedOccupiedVehicle ( p ) if frozen then setElementFrozen ( veh, false ) frozen = false text = "unfreezed" color = { 0, 255, 0 } else setElementFrozen ( veh, true ) frozen = true text = "freezed" color = { 255, 0, 0 } end end end outputChatBox ( "* All players has been " .. text .. " by " .. getPlayerName ( player ) .. ".", root, unpack ( color ), true ); end function binFreezKey( thePlayer ) bindKey( thePlayer, "F5", "down", freezeEm) end function startBind () binFreezKey(source) end function BindForAll () for index, player in pairs(getElementsByType("player")) do binFreezKey(player) end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), BindForAll ) addEventHandler("onPlayerJoin",getRootElement(), startBind) Link to comment
JunkDealer Posted May 5, 2015 Author Share Posted May 5, 2015 thx but color still not working and when press F5, just freezing some players. Not all Link to comment
Walid Posted May 5, 2015 Share Posted May 5, 2015 thx but color still not working and when press F5, just freezing some players. Not all In this code you are just freezing vehicles try this function freezeEm ( player ) if not( isAdmin ( player ) ) then return end for _, p in pairs (getAlivePlayers ()) do if frozen then setElementFrozen ( p, false ) frozen = false text = "unfreezed" r, g, b = 0, 255, 0 else setElementFrozen ( p, true ) frozen = true text = "freezed" r, g, b = 255, 0, 0 end end outputChatBox ( "* All players has been " .. text .. " by " .. getPlayerName ( player ) .. ".", root,r,g,b, true ); end Link to comment
JunkDealer Posted May 5, 2015 Author Share Posted May 5, 2015 color done but now just unfreezing all. I mean, when press F5, unfreezing only. Players already unfreezed Edit: Fixed. Ty for 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