@name C4
@inputs 
@outputs  
@persist [Time Defuse Detonate Explode Off DefT Index Brute PIndex Follow I2 II3 Radius Maxprops II2 Saving] 
@persist [Password Password2 Model Password3 Data Name LoadName]:string 
@persist [H FF Prop P E Ent Stick Attach]:entity [PPOS]:vector 
@persist [PropIndex Brute1 LoadData Bind]:array
@trigger 
interval(100)
runOnChat(1)
#variables + first
P = owner()
E = entity()
Chat = chatClk(P)
Chat2 = chatClk()
LAS = lastSaid():lower()
LASS = LAS:explode(" ")
LAS2 = LAS:explode(":")
LS = P:lastSaid():lower()
LSS = LS:explode(" ")
LS2 = LS:explode(":")
if (first()){
    Bind[1,string] = "p"
    Bind[2,string] = "o"
    Bind[3,string] = "i"
    Bind[4,string] = "l"
    Bind[5,string] = "k"
    Off = 1
    Radius = 1000
    Maxprops = 75
    Model = "models/props_phx/torpedo.mdl"
    Time = 15000
    PIndex = (Time/255)
    DefT = (Time/1000)
    DefT = (PIndex/DefT)
    DefT = DefT-0.5
    Password = "123"
    Password2 = "1234"
    Password3 = "12345"
    function hide(){
            hideChat(1)
            printColor(vec(0,0,255),"[Hidden]",vec(random(0,255),random(0,255),random(0,255)),+P:name(),vec(255,255,255),": "+LS)
    }
}
#/help
if(Chat&LS == "/help"){
    hide()
    print(_HUD_PRINTCENTER,"Help Printed In console.")
    print("/model [model] - changes model of prop used to explode.")
    print("/radius [number] - changes explosion radius.")
    print("/maxprops [number] - changes max props used for explosion.")
    print("/time [number] - changes time for bomb to explode.")
    print("/help 2 - more help")
}
#/help 2
if(Chat&LS == "/help 2"){
    hide()
    print(_HUD_PRINTCENTER,"Help Printed In console.")
    print("/password:[password] - changes password to detonate c4.")
    print("/password 2:[password] - changes password to defuse c4.")
    print("/password 3:[password] - changes password to disarm c4.")
    print("/help 3 for more help.")
}
#/help 3
if(Chat&LS == "/help 3"){
    hide()
    print(_HUD_PRINTCENTER,"Help Printed In console.")
    print("/bind:plant [key] - changes bind to plant bomb.")
    print("/bind:disarm [key] - changes bind to disarm bomb.")
    print("/bind:detonate [key] - changes bind to detonate bomb.")
    print("/bind:defuse [key] - changes bind to defuse bomb.")
    print("/bind:attach [key] - changes bind to attach bomb.")
    print("/help 4 for more help.")
}
#/help 4
if(Chat&LS == "/help 4"){
    hide()
    print(_HUD_PRINTCENTER,"Help Printed In console.")
    print("/detonate:[password] - detonates c4, requires user to be near c4")
    print("/disarm:[password] - disarm c4, requires user to be near c4")
    print("/defuse:[password] - defuses c4, requires user to be near c4")
    print("/attach - attaches c4 to what you're looking at.")
    print("/help 5 for more help.")
}
#/help 5
if(Chat&LS == "/help 5"){
    hide()
    print(_HUD_PRINTCENTER,"Help Printed In console.")
    print("/force [detonate] - forces bomb to detonate, requires user to be near c4 and defuse time based on password length")
    print("/force [disarm] - forces bomb to disarm, requires user to be near c4 and defuse time based on password length")
    print("/force [defuse] - forces bomb to defuse, requires user to be near c4 and defuse time based on password length")
    print("/help 6 for more help.")
}
#/help 6
if(Chat&LS == "/help 6"){
    hide()
    print(_HUD_PRINTCENTER,"Help Printed In console.")
    print("/remote detonate - remotely detonates c4, no password required.")
    print("/remote disarm - remotely disarm c4, no password required.")
    print("/remote defuse - remotely defuses c4, no password required.")
    print("/settings - display settings.")
    print("/save [name] - saves settings to a txt file.")
    print("/load [name] - loads settings.")
}
#/model
if(Chat&LSS:string(1) == "/model"){
    hide()
    Model = LSS:string(2)
    print("Changed explosives to: "+Model)
}
#/radius
if(Chat&LSS:string(1) == "/radius"){
    hide()
    Radius = LSS:string(2):toNumber()
    print("Changed Explosion Radius to: "+Radius)
}
#/maxprops
if(Chat&LSS:string(1) == "/maxprops"){
    hide()
    Maxprops = LSS:string(2):toNumber()
    print("Changed max props spawned to: "+Maxprops)
}
#/password
if(Chat&LS2:string(1) == "/password"){
    hide()
    Password = LS2:string(2)
    print("Detonating Password Is Now: "+Password)
}
#/password2
if(Chat&LS2:string(1) == "/password 2"){
    hide()
    Password2 = LS2:string(2)
    print("Defusing Password Is Now: "+Password2)
}
#/password3
if(Chat&LS2:string(1) == "/password 3"){
    hide()
    Password3 = LS2:string(2)
    print("Disarming Password Is Now: "+Password3)
}
#/bind plant
if(Chat&LSS:string(1) == "/bind:plant"){
    hide()
    if(LSS:string(2):length()==1){
    Bind[1,string] = LSS:string(2)
    print("Changed planting bind to: "+Bind[1,string])
    }else{
    hint("Invalid Key!",10)
}
}
#/attach
if(Chat&LS == "/attach"){
    hide()
    if(P:aimEntity():isValid()){
        Attach = P:aimEntity()
        holoCreate(1)
        holoPos(1,P:pos())
        holoColor(1,vec(0,255,0))
        holoAng(1,ang(0,0,0))
        if(holoModelAny()){
            holoModel(1,"models/weapons/w_c4_planted.mdl")
    }
    H = holoEntity(1)
    }else{
    hint("Invalid Entity!",10)
}
}
if(changed(P:keyPressed(Bind[5,string]))&P:keyPressed(Bind[5,string])){
    if(P:aimEntity():isValid()){
        Attach = P:aimEntity()
        holoCreate(1)
        holoPos(1,P:pos())
        holoColor(1,vec(0,255,0))
        holoAng(1,ang(0,0,0))
        if(holoModelAny()){
            holoModel(1,"models/weapons/w_c4_planted.mdl")
    }
    H = holoEntity(1)
    }else{
    hint("Invalid Entity!",10)
}
}
#/bind disarm
if(Chat&LSS:string(1) == "/bind:disarm"){
    hide()
    if(LSS:string(2):length()==1){
        Bind[2,string] = LSS:string(2)
        print("Changed Disarm bind to: "+Bind[2,string])
    }else{
    hint("Invalid Key!",10)
}
}
#/suicide
if(Chat&LS == "/suicide"){
    hide()
    Follow = 1
    holoCreate(1)
    holoColor(1,vec(0,255,0))
    holoModel(1,"models/weapons/w_c4_planted.mdl")
    H = holoEntity(1)
}
if(Follow){
    holoPos(1,P:pos())
    holoAng(1,P:angles())
}
#/bind detonate
if(Chat&LSS:string(1) == "/bind:detonate"){
    hide()
    if(LSS:string(2):length()==1){
    Bind[3,string] = LSS:string(2)
    print("Changed Detonate bind to: "+Bind[3,string])
    }else{
    hint("Invalid Key!",10)
}
}

#/bind defuse
if(Chat&LSS:string(1) == "/bind:defuse"){
    hide()
    if(LSS:string(2):length()==1){
    Bind[4,string] = LSS:string(2)
    print("Changed Defuse bind to: "+Bind[4,string])
    }else{
    hint("Invalid Key!",10)
}
}

#/bind attach
if(Chat&LSS:string(1) == "/bind:attach"){
    hide()
    if(LSS:string(2):length()==1){
    Bind[5,string] = LSS:string(2)
    print("Changed Attach bind to: "+Bind[5,string])
    }else{
    hint("Invalid Key!",10)
}
}
#find players
if(!Off){
    findByClass("player")
    findSortByDistance(H:pos())
    FF = find()
}
#/settings
if(Chat&LS == "/settings"){
    hide()
    print("Model: "+Model)
    print("Radius: "+Radius)
    print("Maxprops: "+Maxprops)
    print("Explosion Time: "+Time)
    print("Detonate Password: "+Password)
    print("Defuse Password: "+Password2)
    print("Disarm Password: "+Password3)
    print("Plant Bind: " + Bind[1,string])
    print("Detonate Bind: " +Bind[3,string])
    print("Disarm Bind: " +Bind[2,string])
    print("Defuse Bind: " +Bind[4,string])
    print("Attach Bind: " +Bind[5,string])
}
#/save
if(Chat&LSS:string(1) == "/save"){
    hide()
    if(fileCanWrite()){
        Name = LSS:string(2)+".txt"
        Data = Model + " " + Radius:toString() + " " + Maxprops:toString() + " " + Password + " " + Password2 + " " + Password3 + " " + Bind[1,string] + " " + Bind[2,string] + " " + Bind[3,string] + " " + Bind[4,string] + " " + Time + " " + Bind[5,string]
        Saving = 1
    }else{
    hint("Cannot Write Files!",10)
}
}
if(Saving){
    fileWrite(">e2shared/C4-"+Name,Data)
    timer("Saved",1000)
}
if(clk("Saved")){
    Saving = 0
    hint("Saved "+Name+"!",10)
}
#/load
if(Chat&LSS:string()) {
}
