Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @inputs User:entity
- @persist [EGP]:wirelink
- @persist Counter Interval MaxHistoryAmount MaxAlarmAmount MaxHolos DrawHolo
- @persist [TriggerData Cmds QueueData TEGP Notification Curtime TimerDelay AlarmDuration]:table
- @persist [ScrRes]:vector2 [Whitelist]:array GTable:gtable
- if(first()){
- # Made by Preach
- # Version: 0.51
- #[---------------------------------------------------[ Settings ]--------------------------------------------------]#
- Interval = 500
- MaxHistoryAmount = 5
- MaxAlarmAmount = 5
- MaxHolos = 3
- Cmds["prefix", string] = "."
- Cmds["setTriggerBox", string] = "setbox"
- Cmds["setTriggerSphere", string] = "setsphere"
- Cmds["setTriggerMode", string] = "triggermode"
- Cmds["addPlyWhitelist", string] = "addply"
- Cmds["removePlyWhitelist", string] = "removeply"
- Cmds["printWhitelist", string] = "whitelist"
- Cmds["clearHistory", string] = "clear"
- Cmds["clearGTable", string] = "gclear"
- Cmds["drawHolos", string] = "holo"
- TimerDelay["updateHistory", number] = 2
- Whitelist = array( owner() )
- #[---------------------------------------------------[ Core ]--------------------------------------------------]#
- runOnChat(1)
- runOnLast(1)
- AlarmDuration = table()
- TEGP["frame", table] = table()
- TriggerData = table(
- "mode" = "box",
- "modes" = table(
- "box" = 1,
- "sphere" = 1
- ),
- "box" = table(
- ),
- "sphere" = table(
- )
- )
- Notification = table(
- "print" = table(
- "prefix" = "[Alarm] ",
- "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)
- )
- )
- #-----------------[ Auto Run ]------------------#
- findIncludePlayerProps(owner())
- findByClass("gmod_wire_egp_hud")
- local Ent = findClosest(entity():pos())
- if(Ent){
- EGP = Ent:wirelink()
- entity():createWire(Ent, "User", "User")
- #EGP:egpHudToggle()
- } else {
- print("Spawn an EGP Hud first!")
- error("No EGP Hud found")
- }
- findClearWhiteList()
- #-----------------[ E G P ]-----------------#
- #include "egplib"
- #-----------------[ Functions ]-----------------#
- function vector4 col(Ind:string){
- return Notification["col", table][Ind, vector4]
- }
- function chat(Print:array, Mode:string){
- local StrP = Notification["print", table]["prefix" , string]
- local ColP = Notification["col", table]["prefix" , vector4]
- local ColT = Notification["col", table]["text" , vector4]
- local Arr = array(ColP, StrP,ColT)
- if(Notification["print", table]:exists(Mode)){
- local S = Notification["print", table][Mode, string]
- local C = Notification["col", table][Mode, vector4]
- local C2 = Notification["col", table][Mode+"2", vector4]
- Arr = array(ColP, StrP, ColT, C, S, C2)
- }
- printColor(Arr:add(Print))
- }
- function number ind(){
- return EGP:egpNumObjects()+1
- }
- function number cmd(Chat:string, Cmd:string){
- return Chat:lower() == Cmds["prefix", string] + Cmds[Cmd, string]
- }
- function string timeDif(CurrentTime){
- local Dif = floor(curtime()-CurrentTime)
- local S = Dif%60
- local Min = floor(Dif/60)
- local H = floor(Dif/3600)
- local Num = Dif > 3600 ? H : (Dif > 60 ? Min : S)
- local Format = Dif > 3600 ? "h" : (Dif > 60 ? "Min" : "s")
- return format("%02dh %02dMin %02ds", H, Min, S)
- }
- function string getID(Ply:entity){
- return Ply:steamID64()
- }
- function number scale(Num){
- return Num/1920*ScrRes:x()
- }
- function number delay(Index:string){
- return curtime() > Curtime[Index, number] + TimerDelay[Index, number]
- }
- function updateHistory(){
- for(I=1, min(QueueData:count(), MaxHistoryAmount)){
- local Tab = QueueData[I, array]
- local Ply = Tab[1, entity]
- local Ind = TEGP["history", table]["text", array][I, number]
- EGP:egpSetText(Ind, Ply:name())
- EGP:egpSetText(Ind+1, timeDif(Tab[2, number]))
- }
- if(QueueData:count() > MaxHistoryAmount){
- QueueData:popArray()
- }
- }
- function array getFilteredPly(Mode:string, Data:array){
- switch(Mode){
- case "box",
- if(findCanQuery()){
- findInBox(Data[1, vector], Data[2, vector])
- findClipToClass("player")
- findExcludeEntities(Whitelist)
- return findToArray()
- }
- break
- case "sphere",
- if(findCanQuery()){
- findInSphere(Data[1, vector], Data[2, number])
- findClipToClass("player")
- findExcludeEntities(Whitelist)
- return findToArray()
- }
- break
- }
- return array()
- }
- function checkPlyExistsInQueue(Ply:entity){
- for(I=1, QueueData:count()){
- local P = QueueData[I, array][1, entity]
- if(P == Ply){
- QueueData:removeArray(I)
- break
- }
- }
- QueueData:unshiftArray(array(Ply, curtime()))
- }
- function updateAlarm(TrackedPly:array){
- local AlarmInd = TEGP["frame", table][2, array]
- EGP:egpPos(AlarmInd[1, number], AlarmInd[2, vector2])
- for(I=1, MaxAlarmAmount){
- local Ply = TrackedPly[I, entity]
- local Ind = TEGP["alarm", table]["text", array][I, number]
- if(Ply){
- if(!AlarmDuration:exists(Ply:steamID64())){ AlarmDuration[Ply:steamID64(), number] = curtime() }
- EGP:egpSetText(Ind, Ply:name())
- EGP:egpSetText(Ind+1, timeDif(AlarmDuration[Ply:steamID64(), number]))
- EGP:egpSetText(Ind+2, teamName(Ply:team()))
- checkPlyExistsInQueue(Ply)
- } else {
- EGP:egpSetText(Ind, "")
- EGP:egpSetText(Ind+1, "")
- EGP:egpSetText(Ind+2, "")
- }
- }
- updateHistory()
- }
- function update(){
- switch(TriggerData["mode", string]){
- case "box",
- local ArrBox = TriggerData["box", table]["pos", array]
- if(ArrBox:count() == 2){
- local TrackedPly = getFilteredPly("box", ArrBox)
- if(TrackedPly:count()){
- updateAlarm(TrackedPly)
- }
- else {
- AlarmDuration:clear()
- local AlarmInd = TEGP["frame", table][2, array]
- EGP:egpPos(AlarmInd[1, number], ScrRes + vec2(512))
- }
- DrawHolo = 1
- }
- break
- case "sphere",
- local Pos = TriggerData["sphere", table]["pos", vector]
- local R = TriggerData["sphere", table]["radius", number]
- if(Pos){
- local TrackedPly = getFilteredPly("sphere", array(Pos, R))
- if(TrackedPly:count()){
- updateAlarm(TrackedPly)
- } else {
- AlarmDuration:clear()
- local AlarmInd = TEGP["frame", table][2, array]
- EGP:egpPos(AlarmInd[1, number], ScrRes + vec2(512))
- }
- }
- break
- default,
- TriggerData["mode", string] = "box"
- break
- }
- if(changed(Whitelist:count())){
- findClearBlackList()
- }
- if(QueueData:count() & delay("updateHistory")){
- Curtime["updateHistory", number] = curtime()
- updateHistory()
- }
- }
- function string gID(){
- return "gAlarm"+owner():steamID64()
- }
- function checkPreviousData(){
- GTable = gTable(gID(), 0)
- if(GTable["triggerData", table]:count()){
- TriggerData = GTable["triggerData", table]
- chat(array("Previous Trigger information found, restoring previous data"), "info")
- }
- }
- function updateHolo(){
- local ArrBox = TriggerData["box", table]["pos", array]
- if(ArrBox:count() == 2){
- local P1 = ArrBox[1, vector]
- local P2 = ArrBox[2, vector]
- local Pos = P1 + (P2-P1)/2
- local Size = abs(P2-P1)
- holoPos(1, Pos)
- holoScaleUnits(1, Size)
- holoVisible(1, players(), 1)
- }
- }
- function setTrigger(Mode:string, Radius){
- switch(Mode){
- case "sphere",
- TriggerData["sphere", table]["pos", vector] = owner():aimPos()
- TriggerData["sphere", table]["radius", number] = Radius != 0 ? Radius : 150
- chat(array("Sphere-Trigger position was set"), "info")
- break
- case "box",
- local T = TriggerData["box", table]["pos", array]
- if(T:count() == 0 || T:count() == 2){
- TriggerData["box", table]["pos", array] = array( owner():aimPos() )
- } else {
- TriggerData["box", table]["pos", array]:pushVector( owner():aimPos() )
- }
- local Amount = TriggerData["box", table]["pos", array]:count()
- chat(array(format("Box-Trigger position #%d was set", Amount)), "info")
- break
- }
- GTable["triggerData", table] = TriggerData
- updateHolo()
- }
- function whitelist(Ply:entity, Mode:string){
- if(!Ply){ return void }
- switch(Mode){
- case "add",
- if(Whitelist:count()){
- for(I=1, Whitelist:count()){
- local P = Whitelist[I, entity]
- if(P == Ply){
- chat(array("Player \"", col("mark"), Ply:name(), col("error2"), "\" already exists"), "error")
- return void
- }
- }
- }
- Whitelist:pushEntity(Ply)
- chat(array("Player \"", col("mark"), Ply:name(), col("success2"), "\" was ADDED"), "success")
- break
- case "remove",
- if(!Whitelist:count()){
- chat(array("List is empty!"), "error")
- return void
- }
- for(I=1, Whitelist:count()){
- local P = Whitelist[I, entity]
- if(P == Ply){
- Whitelist:removeEntity(I)
- chat(array("Player \"", col("mark"), Ply:name(), col("success2"), "\" was REMOVED"), "success")
- return void
- }
- }
- chat(array("Player \"", col("mark"), Ply:name(), col("error2"), "\" is not the list"), "error")
- break
- }
- }
- function drawFrame(Title:string, Pos:vector2, Size:vector2, PosT:vector2, SizeT:vector2, Alpha){
- TEGP["frame", table]:pushArray(array(ind(), Pos, Size))
- TEGP[Title:lower(), table] = table()
- TEGP[Title:lower(), table]["text", array] = array()
- local MainInd = ind()
- local F = SizeT:y()/38*scale(40)
- EGP:box(ind(), Pos, Size, vec4(vec(30), Alpha))
- Pos = vec2()
- EGP:boxoutline(ind(), Pos, Size, vec4(vec(255),Alpha))
- EGP:box(ind(), PosT, SizeT, vec4(vec(50), Alpha))
- EGP:boxoutline(ind(), PosT, SizeT, vec4(vec(255), Alpha))
- EGP:text(ind(), Title, PosT, vec4(vec(255), Alpha), F)
- for(I=1, 4){
- EGP:egpParent(MainInd+I, MainInd)
- }
- }
- function drawContent(Index:string, Frame, Start, End, Max, Pos:vector2, Size:vector2, PosT:vector2, SizeT:vector2, Alpha){
- local MainInd = TEGP["frame", table][Frame, array][1, number]
- Pos = vec2()
- local Gap = 2
- local NewSize = Size + vec2(0, -SizeT:y())
- local FSize = scale(20)*Size:y()/192
- NewSize = vec2(NewSize:x(), NewSize:y()/Max) - vec2(2, Gap)
- for(I=Start, End){
- local NewPos = Pos + vec2(0, -Size:y()/2 + SizeT:y()) + vec2(0, NewSize:y()/2)
- NewPos += (I-1)*(vec2(0, NewSize:y() + Gap))
- local Col = I%2 == 0 ? vec4(vec(60), Alpha) : vec4(vec(30), Alpha)
- EGP:box(ind(), NewPos, NewSize, Col)
- EGP:egpParent(ind()-1, MainInd)
- TEGP[Index, table]["text", array]:pushNumber(ind())
- if(Frame == 1){
- EGP:text(ind(), "", NewPos+vec2(-Size:x()/2+5,0), vec4(vec(255), Alpha), FSize, "r")
- EGP:egpParent(ind()-1, MainInd)
- EGP:text(ind(), "", NewPos+vec2(Size:x()/2-5,0), vec4(vec(255), Alpha), FSize, "l")
- EGP:egpParent(ind()-1, MainInd)
- } else {
- EGP:text(ind(), "", NewPos+vec2(-Size:x()/2+5,0), vec4(vec(255), Alpha), FSize, "r")
- EGP:egpParent(ind()-1, MainInd)
- EGP:text(ind(), "", NewPos+vec2(Size:x()/2-5,0), vec4(vec(255), Alpha), FSize, "l")
- EGP:egpParent(ind()-1, MainInd)
- EGP:text(ind(), "", NewPos, vec4(vec(255), Alpha), FSize)
- EGP:egpParent(ind()-1, MainInd)
- }
- }
- }
- function holoInit(){
- for(I=1, MaxHolos){
- holoCreate(I, entity():pos(), vec(1), ang(), vec4(150))
- holoVisible(I, players(), 0)
- }
- }
- function initDraw(){
- Counter++
- ScrRes = egpScrSize(owner())
- local Alpha = 200
- local Gap = vec2(-6, 50)
- local Size = vec2(ScrRes:x()*0.2, ScrRes:x()*0.1)
- local Pos = vec2(ScrRes:x() - Size:x()/2, Size:y()/2 + 150) + Gap
- local SizeT = vec2(Size:x(), Size:y()*0.2)
- local PosT = vec2(0, -Size:y()/2 + SizeT:y()/2)
- local Size2 = vec2(Size:x(), Size:y())
- local Pos2 = Pos+vec2(0, Size2:y() + Gap:y()/2)
- local SizeT2 = vec2(Size2:x(), Size2:y()*0.2)
- local PosT2 = vec2(0, -Size2:y()/2 + SizeT2:y()/2)
- switch(Counter){
- case 1,
- EGP:egpClear()
- checkPreviousData()
- holoInit()
- break
- case 2,
- drawFrame("History", Pos, Size, PosT, SizeT, Alpha)
- break
- case 3,
- local Start = TEGP["history", table]["text", array]:count()+1
- if(Start <= MaxHistoryAmount){
- drawContent("history", 1, Start, min(Start+2, MaxHistoryAmount), MaxHistoryAmount, Pos, Size, PosT, SizeT, Alpha)
- Counter--
- }
- break
- case 4,
- drawFrame("Alarm", Pos2, Size2, PosT2, SizeT2, Alpha)
- break
- case 5,
- local Start = TEGP["alarm", table]["text", array]:count()+1
- if(Start <= MaxAlarmAmount){
- drawContent("alarm", 2, Start, min(Start+2, MaxAlarmAmount), MaxAlarmAmount, Pos2, Size2, PosT2, SizeT2, Alpha)
- Counter--
- }
- break
- default,
- Counter = 0
- return void
- }
- timer("drawEGP", 10)
- }
- function entity isPlayerValid(Chat:string){
- local Ply = noentity()
- if(Chat){
- Ply = findPlayerByName(Chat)
- } else {
- Ply = owner():aimEntity():isPlayer() ? owner():aimEntity() : noentity()
- }
- if(Ply){
- return Ply
- }
- chat(array("Player is not valid!"), "error")
- return noentity()
- }
- if(Whitelist:count()){
- findExcludeEntities(Whitelist)
- }
- initDraw()
- }
- elseif(clk("drawEGP")){
- initDraw()
- }
- elseif(chatClk(owner())){
- local O = owner():lastSaid():explode(" ")
- local T1 = O[1, string]
- local T2 = O[2, string]
- local T3 = O[3, string]
- if(cmd(T1, "setTriggerSphere")){
- setTrigger("sphere", T2:toNumber())
- }
- elseif(cmd(T1, "setTriggerBox")){
- setTrigger("box", 0)
- }
- elseif(cmd(T1, "setTriggerMode")){
- if(TriggerData["modes", table]:exists(T2)){
- TriggerData["mode", string] = T2
- chat(array("Trigger mode set to ", col("mark"), T2), "info")
- }
- }
- elseif(cmd(T1, "addPlyWhitelist")){
- local Ply = isPlayerValid(T2)
- whitelist(Ply, "add")
- }
- elseif(cmd(T1, "removePlyWhitelist")){
- local Ply = isPlayerValid(T2)
- whitelist(Ply, "remove")
- }
- elseif(cmd(T1, "printWhitelist")){
- printTable(Whitelist)
- }
- elseif(cmd(T1, "clearHistory")){
- if(QueueData:count()){
- QueueData:clear()
- chat(array("History cleared!"), "info")
- for(I=1, MaxHistoryAmount){
- local Tab = QueueData[I, array]
- local Ply = Tab[1, entity]
- local Ind = TEGP["history", table]["text", array][I, number]
- EGP:egpSetText(Ind, "")
- EGP:egpSetText(Ind+1, "")
- }
- } else {
- chat(array("History is already clear!"), "error")
- }
- }
- elseif(cmd(T1, "clearGTable")){
- if(GTable:count()){
- GTable:clear()
- chat(array("gTable cleared!"), "info")
- } else {
- chat(array("gTable is already clear!"), "error")
- }
- }
- elseif(cmd(T1, "drawHolos")){
- DrawHolo = !DrawHolo
- for(I=1, MaxHolos){
- holoVisible(I, players(), DrawHolo)
- }
- }
- }
- elseif(clk()){
- update()
- }
- interval(Interval)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement