April 06, 2020, 05:49 am

Author Topic: NinjaPhenix's E2 Door  (Read 795 times)

Offline NinjaPhenix

  • ByB Newbie
  • *
  • Posts: 31
    • View Profile
NinjaPhenix's E2 Door
« on: July 21, 2018, 07:20 pm »
Made this a while back on another server however it still performs well and works on ByB, however due to setAlpha being blocked now there will be no indication if the door is open or not.

Code: [Select]
@name NinjaPhenix's E2 Core
@persist Tables:table
if(first())
{
    #[
   
        Tables
            doors
            doors_open
            players
            blacklist_id
            whitelist_id
   
    ]#
    Tables = table()
    Tables["doors", table] = table()
    Tables["players", table] = table()
    Tables["doors_open", table] = table()
    function number entity:canUseDoor(Level:number)
    {
        return This["level", number] >= Level
    }
    function number entity:canUseDoor(Door:entity)
    {
        local Blacklist = Tables["blacklist_"+Door:creationID(), table]
        local Whitelist = Tables["whitelist_"+Door:creationID(), table]
        if(Blacklist[This:steamID(), number])
        {
            return 0
        }
        elseif(This["level", number] >= Door["level", number])
        {
            return 1
        }
        else
        {
            if(Whitelist[This:steamID(), number])
            {
                return 1
            }
        }
        return 0
    }
    function void entity:whitelistPlayer(Player:entity)
    {
        Tables["whitelist_"+This:creationID(), table][Player:steamID(), number] = 1
    }
    function void entity:dewhitelistPlayer(Player:entity)
    {
        Tables["whitelist_"+This:creationID(), table]:remove(Player:steamID())
    }
    function void entity:blacklistPlayer(Player:entity)
    {
        Tables["blacklist_"+This:creationID(), table][Player:steamID(), number] = 1
    }
    function void entity:deblacklistPlayer(Player:entity)
    {
        Tables["blacklist_"+This:creationID(), table]:remove(Player:steamID())
    }
    function number entity:isDoor()
    {
        return This == Tables["doors", table][This:creationID()+"", entity]
    }
    function number entity:isPlayer_()
    {
        return This == Tables["players", table][This:steamID(), entity]
    }
    function void addDoor(Door:entity, Level:number)
    {
        local CID = Door:creationID()+""
        Door["level", number] = Level
        Tables["doors", table][CID, entity] = Door
        Tables["blacklist_"+CID, table] = table()
        Tables["whitelist_"+CID, table] = table()
        if(Tables["doors", table]:count() == 1)
        {
            timer("checkdoors", 100)
        }
    }
    function void removeDoor(Door:entity)
    {
        local CID = Door:creationID()+""
        Door["level", number] = 0
        Tables["doors", table]:remove(CID)
        Tables["doors_open", table]:remove(CID)
        Door:propNotSolid(0)
        Door:setAlpha(255)
        Tables:remove("blacklist_"+CID)
        Tables:remove("whitelist_"+CID)
        if(Tables["doors", table]:count() == 0)
        {
            stoptimer("checkdoors")
        }
    }
    function void addPlayer(Player:entity, Level:number)
    {
        runOnKeys(Player, 1)
        Player["level", number] = Level
        Tables["players", table][Player:steamID(), entity] = Player
        if(Tables["players", table]:count() == 1)
        {
            timer("checkplayers", 100)
        }
    }
    function void removePlayer(Player:entity)
    {
        runOnKeys(Player, 0)
        Player["level", number] = 0
        Tables["players", table]:remove(Player:steamID())
        if(Tables["players", table]:count() == 0)
        {
            stoptimer("checkplayers")
        }
    }
    addPlayer(owner(), 5)
    runOnChat(1)
    #propSpawnUndo(0)
}
# -- Timer Clk( Door Removal )
if(clk("checkdoors"))
{
    foreach(K, V:entity=Tables["doors", table])
    {
        if(!V:isValid())
        {
            Tables["doors", table]:remove(K)
            Tables["doors_open", table]:remove(K)
        }
    }
    if(Tables["doors", table]:count() != 0)
    {
        timer("checkdoors", 10000)
    }
}
# -- Timer Clk( Player Disconnect )
if(clk("checkplayers"))
{
    foreach(K, V:entity=Tables["players", table])
    {
        if(!V:isPlayer())
        {
            Tables["players", table]:remove(K)
        }
    }
    if(Tables["players", table]:count() != 0)
    {
        timer("checkplayers", 10000)
    }
}
# -- Timer Clk( Door closing )
if(clk("checkdoors_open"))
{
    foreach(K, V:number=Tables["doors_open", table])
    {
        if(curtime()-V >= 1)
        {
            local Door = Tables["doors", table][K, entity]
            Door:propNotSolid(0)
            Door:setAlpha(255)
            Tables["doors_open", table]:remove(K)
        }
    }
    if(Tables["doors_open", table]:count() != 0)
    {
        timer("checkdoors_open", 100)
    }
}
# -- Key Clk( Door Opening )
local R = keyClk()
if(R)
{
    if(R:keyUse())
    {
        local E = R:aimEntity()
        if(E:isDoor())
        {
            if(R:canUseDoor(E))
            {
                Tables["doors_open", table][E:creationID()+"", number] = curtime()
                E:propNotSolid(1)
                E:setAlpha(130)
                if(Tables["doors_open", table]:count() == 1)
                {
                    timer("checkdoors_open", 100)
                }
            }
        }
    }
}
# -- Chat Clk( Chat Commands )
if(chatClk(owner()))
{
    local LS = lastSaid():explode(" ")
    if(LS[1, string] == "-core")
    {
        hideChat(1)
        print("Hidden: "+owner():name()+": "+lastSaid())
        if(LS[2, string] == "doors")
        {
            local Door = owner():aimEntity()
            if(LS[3, string] == "add")
            {
                local Level = LS[4, string]:toNumber()
                if(Level > 0)
                {
                    if(!Door:isDoor())
                    {
                        if(Door:owner() == owner())
                        {
                            addDoor(Door, Level)
                        }
                    }
                }
            }
            elseif(LS[3, string] == "rem")
            {
                if(Door:isDoor())
                {
                    removeDoor(Door)
                }
            }
            elseif(LS[3, string] == "whitelist")
            {
                if(LS[4, string] == "add")
                {
                    if(Door:isDoor())
                    {
                        local Player = findPlayerByName(LS:concat(" ", 5))
                        Door:whitelistPlayer(Player)
                    }
                }
                elseif(LS[4, string] == "rem")
                {
                    if(Door:isDoor())
                    {
                        local Player = findPlayerByName(LS:concat(" ", 5))
                        Door:dewhitelistPlayer(Player)
                    }
                }
            }
            elseif(LS[3, string] == "blacklist")
            {
                if(LS[4, string] == "add")
                {
                    if(Door:isDoor())
                    {
                        local Player = findPlayerByName(LS:concat(" ", 5))
                        Door:blacklistPlayer(Player)
                    }
                }
                elseif(LS[4, string] == "rem")
                {
                    if(Door:isDoor())
                    {
                        local Player = findPlayerByName(LS:concat(" ", 5))
                        Door:deblacklistPlayer(Player)
                    }
                }
            }
        }
        elseif(LS[2, string] == "players")
        {
            if(LS[3, string] == "add")
            {
                local Player = findPlayerByName(LS:concat(" ", 4, LS:count()-1))
                local Level = LS[LS:count(), string]:toNumber()
                if(Level > 0)
                {
                    if(!Player:isPlayer_())
                    {
                        if(Player:isPlayer())
                        {
                            addPlayer(Player, Level)
                        }
                    }
                }
            }
            elseif(LS[3, string] == "rem")
            {
                local Player = findPlayerByName(LS:concat(" ", 4))
                if(Player:isPlayer_())
                {
                    removePlayer(Player)
                }
            }
        }
    }
}
Hastebin link: https://hastebin.com/qizufotude.py
So Theres quite an extensive command list
Every command is a subcommand of -core, from there it splits into two, players and doors, from there are commands for adding doors/players removing doors/players and more. They are fully explained below however if you still have issues, just pm me ingame or on the forums.
  • -core doors add level # Adds the aimentity as a door with the specified level meaning only players with that level or higher will be able to open it unless the player is whitelisted to that door.
  • -core doors rem # Removes the door being looked at.
  • -core doors whitelist add name # Allows the specified player to open the door even if they dont have the clearence for it.
  • -core doors whitelist rem name # Removes the player from the doors whitelist
  • -core doors blacklist add name # Disallows the usage of the door even if they have the clearence for it.
  • -core doors blacklist rem name # Removes the specified player from the blacklist
  • -core players add name level # Adds the player with the specified name with the clearence level specified.
  • -core players rem name # Removes the players access to opening doors unless they are whitelisted to specific doors.