Jump to content

Table Problem...


PaulDK

Recommended Posts

my problem is, if the maximum creating object is only 4. how to deduct those in the table. create it again to have a new object then remove the other object that you put first .THANKS in ADVANCE :wink:

local barrier = {}

function consoleCreateObject ( thePlayer, commandName )

local SAPD = getTeamFromName("SAPD")

if (SAPD) then

local ArmedForces = getTeamFromName("Armed Forces")

if (ArmedForces) then

local SWAT = getTeamFromName("SWAT")

if (SWAT) then

if ( thePlayer ) then

local rx, ry = 0, 0

local rz = getElementRotation ( thePlayer )

local x, y, z = getElementPosition ( thePlayer )

table.concat(barrier, 1, 4)

table.insert(barrier, createObject ( 3091, x , y, z - 0.5, 0, 0,rz) )

setElementPosition ( thePlayer, x, y, z + 1)

end

end

end

end

end

addCommandHandler ( "barrier", consoleCreateObject )

Edited by Guest
Link to comment

Server:

local barrier = {} 
  
function consoleCreateObject(thePlayer,commandName) 
    if (commandName == barrier) then 
        local SAPD = getTeamFromName("SAPD") 
        if (SAPD) then 
            local ArmedForces = getTeamFromName("Armed Forces") 
            if (ArmedForces) then 
                local SWAT = getTeamFromName("SWAT") 
                if (SWAT) then 
                    if (getPlayerTeam(thePlayer) == SAPD) or (getPlayerTeam(thePlayer) == ArmedForces) or (getPlayerTeam(thePlayer) == SWAT) then 
                        local x,y,z = getElementPosition(thePlayer) 
                        local _,_,rz = getElementRotation(thePlayer) 
                        local Object = createObject(3091,x,y,z - 0.5,0,0,rz) 
                        setElementPosition(thePlayer,x,y,z + 1) 
                        local PBar = barrier[thePlayer] 
                        if not (PBar) then 
                            barrier[thePlayer] = {} 
                            PBar = {} 
                        end 
                        if not (PBar[1]) then 
                            PBar[1] = Object 
                        elseif not (PBar[2]) then 
                            PBar[2] = Object 
                        elseif not (PBar[3]) then 
                            PBar[3] = Object 
                        elseif not (PBar[4]) then 
                            PBar[4] = Object 
                        else 
                            destroyElement(PBar[1]) 
                            PBar[1] = PBar[2] 
                            PBar[2] = PBar[3] 
                            PBar[3] = PBar[4] 
                            PBar[4] = Object 
                        end 
                        barrier[thePlayer] = PBar 
                    end 
            end 
        end 
    end 
end 
addCommandHandler("barrier", consoleCreateObject) 
  
function fncPlayerQuit() 
    local PBar = barrier[source] 
    barrier[source] = nil 
    if (PBar[1]) then 
        destroyElement(PBar[1]) 
    end 
    if (PBar[2]) then 
        destroyElement(PBar[2]) 
    end 
    if (PBar[3]) then 
        destroyElement(PBar[3]) 
    end 
    if (PBar[4]) then 
        destroyElement(PBar[4]) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),fncPlayerQuit) 

Your English is poor, but I understood what you meant (barely). Add this to your server-side. Also I formatted your code to be more understandable and fixed some other stuff.

Link to comment
Server:
local barrier = {} 
  
function consoleCreateObject(thePlayer,commandName) 
    if (commandName == barrier) then 
        local SAPD = getTeamFromName("SAPD") 
        if (SAPD) then 
            local ArmedForces = getTeamFromName("Armed Forces") 
            if (ArmedForces) then 
                local SWAT = getTeamFromName("SWAT") 
                if (SWAT) then 
                    if (getPlayerTeam(thePlayer) == SAPD) or (getPlayerTeam(thePlayer) == ArmedForces) or (getPlayerTeam(thePlayer) == SWAT) then 
                        local x,y,z = getElementPosition(thePlayer) 
                        local _,_,rz = getElementRotation(thePlayer) 
                        local Object = createObject(3091,x,y,z - 0.5,0,0,rz) 
                        setElementPosition(thePlayer,x,y,z + 1) 
                        local PBar = barrier[thePlayer] 
                        if not (PBar) then 
                            barrier[thePlayer] = {} 
                            PBar = {} 
                        end 
                        if not (PBar[1]) then 
                            PBar[1] = Object 
                        elseif not (PBar[2]) then 
                            PBar[2] = Object 
                        elseif not (PBar[3]) then 
                            PBar[3] = Object 
                        elseif not (PBar[4]) then 
                            PBar[4] = Object 
                        else 
                            destroyElement(PBar[1]) 
                            PBar[1] = PBar[2] 
                            PBar[2] = PBar[3] 
                            PBar[3] = PBar[4] 
                            PBar[4] = Object 
                        end 
                        barrier[thePlayer] = PBar 
                    end 
            end 
        end 
    end 
end 
addCommandHandler("barrier", consoleCreateObject) 
  
function fncPlayerQuit() 
    local PBar = barrier[source] 
    barrier[source] = nil 
    if (PBar[1]) then 
        destroyElement(PBar[1]) 
    end 
    if (PBar[2]) then 
        destroyElement(PBar[2]) 
    end 
    if (PBar[3]) then 
        destroyElement(PBar[3]) 
    end 
    if (PBar[4]) then 
        destroyElement(PBar[4]) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),fncPlayerQuit) 

Your English is poor, but I understood what you meant (barely). Add this to your server-side. Also I formatted your code to be more understandable and fixed some other stuff.

Thanks For Helping me im sorry for my English :D Wrong Translate :D After this Topic i will go Read English Dictionary to Learn more. Thanks a lot brother :mrgreen: ... i will test it

Link to comment
Server:
local barrier = {} 
  
function consoleCreateObject(thePlayer,commandName) 
    if (commandName == barrier) then 
        local SAPD = getTeamFromName("SAPD") 
        if (SAPD) then 
            local ArmedForces = getTeamFromName("Armed Forces") 
            if (ArmedForces) then 
                local SWAT = getTeamFromName("SWAT") 
                if (SWAT) then 
                    if (getPlayerTeam(thePlayer) == SAPD) or (getPlayerTeam(thePlayer) == ArmedForces) or (getPlayerTeam(thePlayer) == SWAT) then 
                        local x,y,z = getElementPosition(thePlayer) 
                        local _,_,rz = getElementRotation(thePlayer) 
                        local Object = createObject(3091,x,y,z - 0.5,0,0,rz) 
                        setElementPosition(thePlayer,x,y,z + 1) 
                        local PBar = barrier[thePlayer] 
                        if not (PBar) then 
                            barrier[thePlayer] = {} 
                            PBar = {} 
                        end 
                        if not (PBar[1]) then 
                            PBar[1] = Object 
                        elseif not (PBar[2]) then 
                            PBar[2] = Object 
                        elseif not (PBar[3]) then 
                            PBar[3] = Object 
                        elseif not (PBar[4]) then 
                            PBar[4] = Object 
                        else 
                            destroyElement(PBar[1]) 
                            PBar[1] = PBar[2] 
                            PBar[2] = PBar[3] 
                            PBar[3] = PBar[4] 
                            PBar[4] = Object 
                        end 
                        barrier[thePlayer] = PBar 
                    end 
            end 
        end 
    end 
end 
addCommandHandler("barrier", consoleCreateObject) 
  
function fncPlayerQuit() 
    local PBar = barrier[source] 
    barrier[source] = nil 
    if (PBar[1]) then 
        destroyElement(PBar[1]) 
    end 
    if (PBar[2]) then 
        destroyElement(PBar[2]) 
    end 
    if (PBar[3]) then 
        destroyElement(PBar[3]) 
    end 
    if (PBar[4]) then 
        destroyElement(PBar[4]) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),fncPlayerQuit) 

Your English is poor, but I understood what you meant (barely). Add this to your server-side. Also I formatted your code to be more understandable and fixed some other stuff.

not functioning :roll: i set my team to swat but the object not created :?:

Link to comment
local barrier = {} 
  
function consoleCreateObject(thePlayer,commandName) 
    if (commandName == "barrier") then 
        local SAPD = getTeamFromName("SAPD") 
        if (SAPD) then 
            local ArmedForces = getTeamFromName("Armed Forces") 
            if (ArmedForces) then 
                local SWAT = getTeamFromName("SWAT") 
                if (SWAT) then 
                    if (getPlayerTeam(thePlayer) == SAPD) or (getPlayerTeam(thePlayer) == ArmedForces) or (getPlayerTeam(thePlayer) == SWAT) then 
                        local x,y,z = getElementPosition(thePlayer) 
                        local _,_,rz = getElementRotation(thePlayer) 
                        local Object = createObject(3091,x,y,z - 0.5,0,0,rz) 
                        setElementPosition(thePlayer,x,y,z + 1) 
                        local PBar = barrier[thePlayer] 
                        if not (PBar) then 
                            barrier[thePlayer] = {} 
                            PBar = {} 
                        end 
                        if not (PBar[1]) then 
                            PBar[1] = Object 
                        elseif not (PBar[2]) then 
                            PBar[2] = Object 
                        elseif not (PBar[3]) then 
                            PBar[3] = Object 
                        elseif not (PBar[4]) then 
                            PBar[4] = Object 
                        else 
                            destroyElement(PBar[1]) 
                            PBar[1] = PBar[2] 
                            PBar[2] = PBar[3] 
                            PBar[3] = PBar[4] 
                            PBar[4] = Object 
                        end 
                        barrier[thePlayer] = PBar 
                    end 
            end 
        end 
    end 
end 
addCommandHandler("barrier", consoleCreateObject) 
  
function fncPlayerQuit() 
    local PBar = barrier[source] 
    barrier[source] = nil 
    if (PBar[1]) then 
        destroyElement(PBar[1]) 
    end 
    if (PBar[2]) then 
        destroyElement(PBar[2]) 
    end 
    if (PBar[3]) then 
        destroyElement(PBar[3]) 
    end 
    if (PBar[4]) then 
        destroyElement(PBar[4]) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),fncPlayerQuit) 

I forgot to put 'barrier' in double quotes. It should work now.

Link to comment
local barrier = {} 
  
function consoleCreateObject(thePlayer,commandName) 
    if (commandName == "barrier") then 
        local SAPD = getTeamFromName("SAPD") 
        if (SAPD) then 
            local ArmedForces = getTeamFromName("Armed Forces") 
            if (ArmedForces) then 
                local SWAT = getTeamFromName("SWAT") 
                if (SWAT) then 
                    if (getPlayerTeam(thePlayer) == SAPD) or (getPlayerTeam(thePlayer) == ArmedForces) or (getPlayerTeam(thePlayer) == SWAT) then 
                        local x,y,z = getElementPosition(thePlayer) 
                        local _,_,rz = getElementRotation(thePlayer) 
                        local Object = createObject(3091,x,y,z - 0.5,0,0,rz) 
                        setElementPosition(thePlayer,x,y,z + 1) 
                        local PBar = barrier[thePlayer] 
                        if not (PBar) then 
                            barrier[thePlayer] = {} 
                            PBar = {} 
                        end 
                        if not (PBar[1]) then 
                            PBar[1] = Object 
                        elseif not (PBar[2]) then 
                            PBar[2] = Object 
                        elseif not (PBar[3]) then 
                            PBar[3] = Object 
                        elseif not (PBar[4]) then 
                            PBar[4] = Object 
                        else 
                            destroyElement(PBar[1]) 
                            PBar[1] = PBar[2] 
                            PBar[2] = PBar[3] 
                            PBar[3] = PBar[4] 
                            PBar[4] = Object 
                        end 
                        barrier[thePlayer] = PBar 
                    end 
            end 
        end 
    end 
end 
addCommandHandler("barrier", consoleCreateObject) 
  
function fncPlayerQuit() 
    local PBar = barrier[source] 
    barrier[source] = nil 
    if (PBar[1]) then 
        destroyElement(PBar[1]) 
    end 
    if (PBar[2]) then 
        destroyElement(PBar[2]) 
    end 
    if (PBar[3]) then 
        destroyElement(PBar[3]) 
    end 
    if (PBar[4]) then 
        destroyElement(PBar[4]) 
    end 
end 
addEventHandler("onPlayerQuit",getRootElement(),fncPlayerQuit) 

I forgot to put 'barrier' in double quotes. It should work now.

no debugscript. but creating object not functions and SetElementPosition ... HELP PLEASE :?::?::?:

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...