Jump to content

what is wrong?


Sparrow

Recommended Posts

I do a simple script that is allow army to block road with barriers, but when I'm testing this in my local server I found that all can use it, also I stuck inside the barrier, how to solve this?

here is the script:

local barrier = {} 
  
function createBarrier (thePlayer) 
    local getTeam = getTeamFromName ("Army")  
    if (getTeam) then 
        local x, y, z = getElementPosition (thePlayer) 
        barrier[thePlayer] = createObject (3578, x, y, z, 0, 0, 0) 
    end 
end 
addCommandHandler ("barrier", createBarrier) 
  
function removeBarrier (thePlayer) 
    if (isElement(barrier[thePlayer])) then 
        destroyElement(barrier[thePlayer]) 
        barrier[thePlayer] = nil 
    end 
end 
addCommandHandler ("rbarrier", removeBarrier) 

Link to comment

You mean it?

Server

local barrier = {} 
  
function isUser( source,name ) 
    if isElement( source ) and type( name ) == "string" then 
        local acc = getPlayerAccount( source ) 
        if acc then 
            if isObjectInACLGroup( "user."..getAccountName( acc ),aclGetGroup( name ) ) then   
                return true 
            end 
            return false 
        end 
        return false     
    end 
    return false     
end  
  
function createBarrier ( thePlayer ) 
    if isUser( thePlayer,"Admin" ) then -- check if player Admin for example 
        local getTeam = getTeamFromName ("Army")  
        if (getTeam) then 
            local x, y, z = getElementPosition (thePlayer) 
            barrier[thePlayer] = createObject (3578, x, y, z, 0, 0, 0) 
        end 
    end     
end 
addCommandHandler ("barrier", createBarrier) 
  
function removeBarrier ( thePlayer ) 
    if isUser( thePlayer,"Admin" ) then -- check if player Admin for example 
        if isElement( barrier[thePlayer ] ) then 
            destroyElement( barrier[thePlayer ] ) 
            barrier[ thePlayer ] = nil 
        end 
    end     
end 
addCommandHandler ("rbarrier", removeBarrier) 

Link to comment

with yours only admins can do it?

Edit: it's working only for "Army" team, and I solve the problem of bugged inside it by changing:

barrier[thePlayer] = createObject (3578, x + 6, y , z, 0, 0, 0) 

but if I create 2+ barriers I only remove 1 barrier, how to set it only create 1 barrier?

Link to comment
local barrier = {} 
  
function isUser( source,name ) 
    if isElement( source ) and type( name ) == "string" then 
        local acc = getPlayerAccount( source ) 
        if acc then 
            if isObjectInACLGroup( "user."..getAccountName( acc ),aclGetGroup( name ) ) then   
                return true 
            end 
            return false 
        end 
        return false     
    end 
    return false     
end 
  
function createBarrier ( thePlayer ) 
    if isUser( thePlayer,"Admin" ) then -- check if player Admin for example 
        local getTeam = getTeamFromName ("Army") 
        if (getTeam) then 
            local x, y, z = getElementPosition (thePlayer) 
            if (isElement(barrier[thePlayer])) then return end 
            barrier[thePlayer] = createObject (3578, x, y, z, 0, 0, 0) 
        end 
    end     
end 
addCommandHandler ("barrier", createBarrier) 
  
function removeBarrier ( thePlayer ) 
    if isUser( thePlayer,"Admin" ) then -- check if player Admin for example 
        if isElement( barrier[thePlayer ] ) then 
            destroyElement( barrier[thePlayer ] ) 
            barrier[ thePlayer ] = nil 
        end 
    end     
end 
addCommandHandler ("rbarrier", removeBarrier) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...