@name Grenadier
@inputs 
@outputs 
@persist Grenade:entity GrenadeMass O:entity 
@trigger 
if(duped()){ reset() print("Say Setm 1 or more to set the weight of the grenade!") }

runOnTick(1)
runOnChat(1)
O=owner()

S=O:lastSaid():explode(" ")


if(S:string(1)=="Setm"&chatClk(O)){
    GrenadeMass = S:string(2):toNumber()
  
  hideChat(1)
  print(O:lastSaid() + " " + "[HIDDEN]")
}
Grenade:setMass(GrenadeMass)

findExcludePlayerProps("*")
findSortByDistance(O:pos())
findIncludePlayerProps(O)
findByClass("npc_grenade_frag")
 P=players()
#[for(I=1, P:count()){
    if(find():pos():distance(P[I,entity]:pos()) < 500){ A= find() }
 A:applyForce(P[I,entity]:pos() - A:pos())    
}]#




if(find():pos():distance(O:pos()) < 200){ Grenade = find() }
       Grenade:applyForce(O:aimPos() - Grenade:pos())



if(changed(Grenade)){ 
    holoCreate(1, Grenade:pos())
    holoModel(1, "icosphere3")
    holoParent(1, Grenade)
    holoMaterial(1, "models/wireframe")
    holoColor(1, vec(random(255),random(255),random(255)))  
    holoScale(1, vec(1,1,1))
    O:soundPlay(10,10,"weapons/airstrike_fire_02.wav")
    Grenade:setTrails(100,102,52,"trails/physbeam",vec(random(255),random(255),random(255)),255)
  
}
P=players()
for(I=1,P:count()){
    if(Grenade:pos():distance(P[I,entity]:pos()) < 200 &P[I,entity]!=O&P[I,entity]:isAlive() ){
        holoPos(1, Grenade:pos())
        Grenade:setPos(P[I,entity]:pos()+vec(0,0,40))
        Attached = 1
      
        
}else{}
    
    }
