Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @inputs Trigger:array
- @persist [Whitelist Cmds ChatNotification FadingDoors WLPly]:table [GTable]:gtable
- @persist FadingDuration MaxListEntries WhitelistPersistent Interval AddOwnerToWhitelist
- @persist HideChat Version MaxDoorDist
- if(first()){
- # MADE BY PREACH
- #[---------------------------------------------------[ Settings ]--------------------------------------------------]#
- Interval = 100
- WhitelistPersistent = 1
- AddOwnerToWhitelist = 1
- MaxDoorDist = 60
- FadingDuration = 5
- MaxListEntries = 5
- HideChat = 0
- Cmds["prefix", string] = "."
- Cmds["addFadingDoor", string] = "adddoor"
- Cmds["removeFadingDoor", string] = "removedoor"
- Cmds["addPly", string] = "addply"
- Cmds["removePly", string] = "removeply"
- Cmds["listWhitelist", string] = "list"
- Cmds["listFadingDoors", string] = "listfd"
- Cmds["clear", string] = "clear"
- Cmds["fadingDuration", string] = "duration"
- Cmds["maxDoorDist", string] = "doordist"
- #[---------------------------------------------------[ Core ]--------------------------------------------------]#
- runOnChat(1)
- runOnLast(1)
- Version = 1
- ChatNotification = table(
- "print" = table(
- "prefix" = "[pSmartOpener] ",
- "error" = "[ ERROR ] ",
- "success" = "[ SUCCESSFUL ] ",
- "info" = "[ INFORMATION ] ",
- "warn" = "[ WARNING ] "
- ),
- "col" = table(
- "prefix" = vec4(174, 255, 0, 255),
- "text" = vec4(255, 187, 51, 255),
- "mark" = vec4(145, 122, 255, 230),
- "error" = vec4(150, 30, 30, 255),
- "error2" = vec4(200, 60, 60, 255),
- "success" = vec4(30 , 150, 30, 255),
- "success2" = vec4(60 , 200, 60, 255),
- "info" = vec4(255, 94, 0, 255),
- "info2" = vec4(255, 139, 66, 255),
- "warn" = vec4(255, 37, 0, 255),
- "warn2" = vec4(255, 80, 0, 255)
- )
- )
- WLPly = table("76561197961325701" = 1, "76561199142783160" = 1)
- GTable = gTable(owner():steamID64()+"pSmartOpener", 1)
- #-----------------[ Functions ]-----------------#
- function void chat(Print:array, Mode:string){
- local StrP = ChatNotification["print", table]["prefix" , string]
- local ColP = ChatNotification["col", table]["prefix" , vector4]
- local ColT = ChatNotification["col", table]["text" , vector4]
- local Arr = array(ColP, StrP,ColT)
- if(ChatNotification["print", table]:exists(Mode)){
- local S = ChatNotification["print", table][Mode, string]
- local C = ChatNotification["col", table][Mode, vector4]
- local C2 = ChatNotification["col", table][Mode+"2", vector4]
- Arr = array(ColP, StrP, ColT, C, S, C2)
- }
- printColor(Arr:add(Print))
- }
- function number entity:isWhitelisted(){
- return Whitelist:exists(This:steamID64())
- }
- function number maxPage(){
- return ceil(Whitelist:count() / MaxListEntries)
- }
- function number difTime(Time){
- return Time - curtime()
- }
- function vector4 col(Col:string){
- return ChatNotification["col", table][Col, vector4]
- }
- function string entity:plyID(){
- return This:steamID64()
- }
- function string cmd(Cmd:string){
- local Alt = Cmds[Cmd, string] ? Cmds[Cmd, string]:lower() : curtime()+""
- return Cmds["prefix", string] + Alt
- }
- function entity getPly(PlyName:string){
- if(!PlyName:length()){
- local Ply = owner():aimEntity()
- if(Ply:isPlayer()){ return Ply }
- chat(array("invalid entity / player"), "error")
- return noentity()
- }
- local LowerPlyName = PlyName:lower()
- foreach(K,V:entity=players()){
- local TmpPlyName = V:name():lower()
- if(TmpPlyName:find(LowerPlyName)){
- return V
- }
- }
- chat(array("Player \"", col("mark"), PlyName, col("error2"),
- "\" not found"), "error")
- return noentity()
- }
- function void whitelistPly(Ply:entity, Mode){
- if(!Ply){
- #chat(array(col("error2"), "Player is not valid"), "error")
- return
- }
- local ID = Ply:plyID()
- local PlyName = Ply:name()
- if(Mode){
- if(!Whitelist:exists(ID)){
- Whitelist[ID, entity] = Ply
- GTable[ID, entity] = Ply
- chat(array("Player \"", col("mark"), PlyName, col("success2"),
- "\" has been added") , "success")
- } else {
- chat(array(col("error2"), "Player \"",col("mark"), PlyName, col("error2"), "\"
- already exists in whitelist"), "error")
- }
- } else {
- if(Whitelist:exists(ID)){
- Whitelist:remove(ID)
- GTable:removeEntity(ID)
- chat(array("Player \"", col("mark"), PlyName, col("success2"),
- "\" has been removed"), "success")
- } else {
- chat(array("Player \"", col("mark"), PlyName, col("error2"),
- "\" does not exists in whitelist"), "error")
- }
- }
- }
- function void showWhitelist(Page){
- if(!Whitelist:count()){
- chat(array("Whistlist is empty"), "info")
- return void
- }
- Page = clamp(Page, 1, maxPage())
- local Hyphen = "-":repeat(30)
- local MinIt = min(Whitelist:count(), MaxListEntries)
- local H2 = Hyphen:sub(1, Hyphen:length()-2)
- chat(array(Hyphen, "[", col("mark"), "Whitelist", col("info2"), "]", Hyphen), "info")
- for(I=1, MinIt){
- local Key = Whitelist:keys()[I + (Page-1)*MaxListEntries, string]
- local Ply = Whitelist[Key, entity]
- if(!Key){ continue }
- local KeyTxt = array("Index: ", col("mark"), Key, " ")
- local ValTxt = array("Name: ", col("mark"), Ply:name())
- chat(KeyTxt:add(ValTxt), "info")
- }
- chat(array(Hyphen, "[Page: ", col("mark"), Page, " / ", maxPage(),col("info2"), "]", H2), "info")
- }
- function void cmdData(S2:string, Cmd:string){
- local Num = S2:toNumber()
- local Old = -1
- local New = -1
- switch(Cmd){
- case "Max Door Distance", Old = MaxDoorDist break
- case "FadingDoor Duration", Old = FadingDuration break
- }
- if(S2:length()){
- local Num = S2:toNumber()
- if(Num > 0){
- switch(Cmd){
- case "Max Door Distance",
- MaxDoorDist = Num
- New = MaxDoorDist
- break
- case "FadingDoor Duration",
- FadingDuration = Num
- New = FadingDuration
- break
- }
- chat(array("Changed ", Cmd," from ", col("mark"), Old, col("success2"),
- " to ", col("mark"), New, col("success2")), "success")
- } else {
- chat(array("\"", col("mark"), S2, col("error2"), "\" is not a number ",
- " or less than one"), "error")
- }
- } else {
- chat(array(Cmd, " is ", col("mark"),
- Old, col("info2")), "info")
- }
- }
- function void manageFadingDoors(Ent:entity, Mode){
- if(!Ent){
- chat(array("Entity is not valid"), "error")
- return
- }
- if(Ent:owner() != owner()){
- chat(array("You do not own that prop"), "error")
- return
- }
- local ID = Ent:id() + ""
- if(Mode){
- if(!FadingDoors:exists(ID)){
- FadingDoors[ID, array] = array(Ent, 0, 0)
- chat(array("Prop (ID: ", col("mark"), ID, col("success2"),
- ") has been marked as FadingDoor") , "success")
- if(!Ent:wirelink():hasInput("Fade")){
- chat(array("Prop (ID: ", col("mark"), ID, col("warn2"),
- ") has no Fade input!") , "warn")
- }
- } else {
- chat(array("Prop (ID: ", col("mark"), ID, col("error2"),
- ") is already marked"), "error")
- }
- } else {
- if(FadingDoors:exists(ID)){
- FadingDoors:remove(ID)
- chat(array("Prop (ID: ", col("mark"), ID, col("success2"),
- ") has been unmarked"), "success")
- } else {
- chat(array(col("error2"), "Prop (ID: ", col("mark"), ID, col("error2"),
- ") is already unmarked"), "error")
- }
- }
- }
- function void checkChatCmds(Chat:string){
- local LS = Chat:lower()
- local Arr = LS:explode(" ")
- local S1 = Arr[1, string]
- local S2 = Arr[2, string]
- local S3 = Arr[3, string]
- local RE = format("^[%s]", Cmds["prefix", string])
- if(!LS:findRE(RE)){ return void }
- hideChat(HideChat)
- switch(S1){
- case cmd("addPly"),
- local Ply = getPly(S2)
- Ply = Ply ? Ply : noentity()
- whitelistPly(Ply, 1)
- break
- case cmd("addFadingDoor"),
- local Ent = owner():aimEntity() ? owner():aimEntity() : noentity()
- manageFadingDoors(Ent, 1)
- break
- case cmd("removeFadingDoor"),
- local Ent = owner():aimEntity() ? owner():aimEntity() : noentity()
- manageFadingDoors(Ent, 0)
- break
- case cmd("removePly"),
- local Ply = getPly(S2)
- whitelistPly(Ply, 0)
- break
- case cmd("listWhitelist"),
- showWhitelist(S2:toNumber())
- break
- case cmd("listFadingDoors"),
- if(FadingDoors:count()){
- printTable(FadingDoors)
- } else {
- chat(array("FadingDoor-List is empty!"), "info")
- }
- break
- case cmd("maxDoorDist"),
- cmdData(S2, "Max Door Distance")
- break
- case cmd("fadingDuration"),
- cmdData(S2, "FadingDoor Duration")
- break
- case cmd("clear"),
- Whitelist:clear()
- GTable:clear()
- chat(array("Whitelist cleared"), "success")
- break
- default,
- hideChat(0)
- chat(array("Command \"", col("mark"), S1, col("error2"),
- "\" not found"), "error")
- break
- }
- }
- function void update(){
- foreach(DoorID, ArrDoor:array=FadingDoors){
- local EntDoor = ArrDoor[1, entity]
- local Time = ArrDoor[2, number]
- local IsOpen = ArrDoor[3, number]
- local WLDoor = EntDoor:wirelink()
- local TimeDif = difTime(Time)
- if(IsOpen && TimeDif < 0){
- WLDoor["Fade", number] = 0
- ArrDoor[3, number] = 0
- }
- if(!Trigger:count()){ continue }
- if(EntDoor){
- foreach(PlyID, Ply:entity = Trigger){
- if(!Ply:isWhitelisted()){ continue }
- local Dist = EntDoor:pos():distance2(Ply:pos())
- if(Dist < MaxDoorDist ^ 2){
- ArrDoor[2, number] = curtime() + FadingDuration
- ArrDoor[3, number] = 1
- WLDoor["Fade", number] = 1
- }
- }
- } else {
- FadingDoors:remove(DoorID)
- chat(array("removed invalid door (ID: ", col("mark"), DoorID, col("info2"),
- ") from list"), "info")
- }
- }
- }
- function array string:rainbowTxt(){
- local ResultArr = array()
- local Txt = This
- local CharLength = Txt:length()
- for(I=1, CharLength){
- local Col = hsv2rgb(360 / CharLength * I, 1, 1)
- local Char = Txt[I]
- ResultArr:pushVector(Col)
- ResultArr:pushString(Char)
- }
- return ResultArr
- }
- function void init(){
- if(!WLPly:exists(owner():steamID64())){
- error("A file is missing")
- }
- if(WhitelistPersistent){
- if(GTable:count()){
- local Counter = 0
- foreach(K, V:entity=GTable){
- if(V){
- Counter++
- Whitelist[V:plyID(), entity] = V
- }
- }
- chat(array("Added ", col("mark"), Counter, col("info2"),
- " player(s) to the whitelist"), "info")
- } else {
- chat(array("No data found in gTable"), "info")
- }
- }
- if(AddOwnerToWhitelist){
- Whitelist[owner():plyID(), entity] = owner()
- }
- local Credits = "[pSmartOpener] Made by Preach (Version " + Version + ")"
- printColor(Credits:rainbowTxt())
- hint(Credits, 5)
- }
- init()
- }
- elseif(chatClk(owner())){
- checkChatCmds(lastSaid())
- }
- elseif(clk()){
- update()
- }
- interval(Interval)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement