@name Minefield (Chat armed)
@inputs 
@outputs Detonate Arm
@persist Arm
@trigger 
@model models/Items/AR2_Grenade.mdl
interval(50)

runOnChat(1)
Chat=owner():lastSaid()
if(chatClk()){
    if(Chat=="lock and load"){Arm=1}
    if(Chat=="cease fire"){Arm=0}
}

if(first()|dupefinished()){
    print("say 'lock and load' to arm mines\nsay 'cease fire' to disarm")
    #ifdef entity:createWire(entity,string,string)
        entity():isConstrainedTo():createWire(entity(),"Detonate","Detonate")
    #endif
    entity():isConstrainedTo():setAlpha(100)
    entity():setAlpha(0)
}
if(Arm){
    Pl=players()
    Dist=array()
    for(C=1,Pl:count()){
        Dist[C,number]=Pl[C,entity]:pos():distance(entity():pos())
    }
    Min=Dist:min()
    MinEnt=Pl[Dist:minIndex(),entity]
    
    Detonate=(Min<50)&MinEnt!=owner()
}
