@name FailCake Abduct Props
@persist Say:array [O E]:entity
@persist PropName:string Cookies:entity PropDataBase:table FindIt:string Find Props:array
@persist ClosestD Dis GOTO:entity Spin Ang:angle POS:vector Up Get Gm:string
@trigger all

if(first() | duped()){
runOnTick(1)  
runOnChat(1)  
propSpawnEffect(0)

E = entity()
O = owner()

PropDataBase["melon",string] = "models/props_junk/watermelon01.mdl"

holoCreate(54)
holoModel(54,"cube")
holoScale(54,vec(1,1,1)/2)
holoAlpha(54,0)
holoPos(54,E:toWorld(vec(0,0,29)))


holoCreate(1)
holoModel(1,"models/props_junk/sawblade001a.mdl")
holoScale(1,vec(1,1,1)/2)
holoPos(1,E:toWorld(vec(0,0,29)))

holoCreate(2)
holoModel(2,"models/props_interiors/pot01a.mdl")
holoScale(2,vec(1,1,1)/2)
holoPos(2,E:toWorld(vec(0,0,29)))
holoAng(2,ang(-180,0,0))
holoParent(2,1)

holoCreate(3)
holoModel(3,"models/props_junk/sawblade001a.mdl")
holoScale(3,vec(1,1,1)/2)
holoPos(3,E:toWorld(vec(0,0,30)))
holoAng(3,ang(-180,0,0))
holoParent(3,1)

holoCreate(4)
holoModel(4,"models/props_junk/MetalBucket01a.mdl")
holoScale(4,vec(1,1,1)/2)
holoPos(4,E:toWorld(vec(0,0.1,27.5)))
holoAng(4,ang(-180,0,0))
holoParent(4,1)

holoCreate(5)
holoModel(5,"models/Items/combine_rifle_ammo01.mdl")
holoScale(5,vec(1,1,1)/2)
holoPos(5,E:toWorld(vec(0,0,31)))
holoAng(5,ang(0,0,0))
holoParent(5,1)

holoCreate(6)
holoModel(6,"models/Items/combine_rifle_cartridge01.mdl")
holoScale(6,vec(1,1,1)/2)
holoPos(6,E:toWorld(vec(3,0,32)))
holoAng(6,ang(-90,0,0))
holoParent(6,1)

holoCreate(7)
holoModel(7,"models/Items/combine_rifle_cartridge01.mdl")
holoScale(7,vec(1,1,1)/2)
holoPos(7,E:toWorld(vec(0,3,32)))
holoAng(7,ang(-90,90,0))
holoParent(7,1)

holoCreate(8)
holoModel(8,"models/Items/combine_rifle_cartridge01.mdl")
holoScale(8,vec(1,1,1)/2)
holoPos(8,E:toWorld(vec(0,-3,32)))
holoAng(8,ang(-90,-90,0))
holoParent(8,1)

holoCreate(9)
holoModel(9,"models/Items/combine_rifle_cartridge01.mdl")
holoScale(9,vec(1,1,1)/2)
holoPos(9,E:toWorld(vec(-3,0,32)))
holoAng(9,ang(-90,180,0))
holoParent(9,1)

holoCreate(10)
holoModel(10,"models/Effects/combineball.mdl")
holoScale(10,vec(1,1,1)/4)
holoPos(10,E:toWorld(vec(0,0,35)))
holoAng(10,ang(-90,180,0))
holoParent(10,1)

holoCreate(11)
holoModel(11,"models/props_combine/stasisshield.mdl")
holoScaleUnits(11,vec(10,10,40))
holoPos(11,E:toWorld(vec(0,0,30)))
holoAng(11,ang(-180,0,0))
holoParent(11,1)
holoAlpha(11,0)

}

function entity finds(Ts:array){
ClosestD = 999

for(I = 1, Ts:count()){
Dis = holoEntity(1):pos():distance(Ts[I,entity]:pos())  

if(Dis < ClosestD){
ClosestD = Dis   
Cookies = Ts[I,entity] 
} 
   
}

print(Cookies)
return Cookies   
}


function void findProp(Prop:string){
    
if(PropDataBase[Prop,string] != ""){
FindIt = PropDataBase[Prop,string]    
Find = 1
}else{
Find = 0
FindIt = ""
printColor(vec(255,0,0),"[Error]",vec(255,255,255)," Prop Name Not Found!")
}    
       
}



if(chatClk(O)){
Say = O:lastSaid():explode(" ") 

if(Say[1,string]:lower() == "-abduct" & Find == 0){
PropName = Say[2,string]:lower() 
findProp(PropName)  
printColor(vec(0,255,0),"[Info]",vec(255,255,255)," Abducting " + PropName + " >:D!") 
}

}


if(Find == 1){
findByModel(FindIt)
findIncludePlayerProps(O) 
Props = findToArray()  

if(Props:count() >= 1){
Find = 2    
}else{
printColor(vec(255,0,0),"[Error]",vec(255,255,255)," Props not Found!")
Find = 0
}

}


if(Find == 2){
GOTO = finds(Props) 
Find = 3  
holoPos(54,vec(0,0,0)) 
}

if(Find == 3){
POS = (holoEntity(54):pos())
Ang = (holoEntity(1):pos() - POS):toAngle()
DIS = holoEntity(1):pos():distance(holoEntity(54):pos())

holoPos(54,GOTO:pos() + vec(0,0,25))    

if(DIS > 0.3 & Get == 0){
holoAng(1,Ang)
holoPos(1,holoEntity(1):pos() + -holoEntity(1):forward()/2)
}elseif(DIS < 0.3){
holoAng(1,ang(0,0,0))
Get = 1
Find = 4
}

}

if(Get == 1){
GOTO:propFreeze(1)
holoAlpha(11,255)  
 
if(Up < 0.4){
Up+=0.005
GOTO:setPos(GOTO:pos() + vec(0,0,Up))
}else{
Gm = GOTO:model()
GOTO:propDelete()
holoAlpha(11,0)
holoPos(54,E:pos() + vec(0,0,25))
Get = 2
}

}




if(Get == 2){
POS = (holoEntity(54):pos())
Ang = (holoEntity(1):pos() - POS):toAngle()
DIS = holoEntity(1):pos():distance(holoEntity(54):pos())

holoPos(54,E:pos() + vec(0,0,25))    

if(DIS > 0.3 & Get == 2){
holoAng(1,Ang)
holoPos(1,holoEntity(1):pos() + -holoEntity(1):forward()/2)
}elseif(DIS < 0.3){
holoAng(1,ang(0,0,0))
Get = 3
}    
}

if(Get == 3){
Melon = propSpawn(Gm,holoEntity(1):pos(),ang(0,0,0),0) 
Get = 0   
}
   

