; 
; Vehicle loading script for AGS-17 Addon by Kegetys <Kegetys@raketti.net> 
; http://www.ofp.kege.cjb.net
;

agsScript_gun = _this

agsScript_dummyobj = "B45_SF14dummy" createVehicle [-10000,-10000,10000]

agsScript_dummyobj addAction["Load Sf14 in vehicle","load.sqs"]

agsScript_gun_addAction = 0
agsScript_gun_remAction = 0


#loop1
~1
?(agsScript_gun_addAction == 1) : goto "gun_addAction"
?(agsScript_gun_remAction == 1) : goto "gun_remAction"

?((agsScript_gun distance (nearestObject [agsScript_gun, "B45HETZER_P000"])) < 5) : goto "proximity"
?((agsScript_gun distance (nearestObject [agsScript_gun, "B45HETZER_B000"])) < 5) : goto "proximity"
?((agsScript_gun distance (nearestObject [agsScript_gun, "StM_Hetzer"])) < 5) : goto "proximity"
?((agsScript_gun distance (nearestObject [agsScript_gun, "GST_Stug"])) < 5) : goto "proximity"
?((agsScript_gun distance (nearestObject [agsScript_gun, "GST_Stugnoarm"])) < 5) : goto "proximity"

agsScript_dummyobj setpos[-10000,-10000,10000]
goto "loop1"

#gun_addAction
agsScript_rekka_action = agsScript_rekka addAction["Unload Sf14","unload.sqs"]
agsScript_gun_addAction = 0
goto "loop1"

#gun_remAction
agsScript_rekka removeAction agsScript_rekka_action
agsScript_gun_remAction = 0
goto "loop1"

#proximity
?((agsScript_gun distance (nearestObject [agsScript_gun, "B45HETZER_P000"])) < 5) : agsScript_rekka = nearestObject [agsScript_gun, "B45HETZER_P000"]
?((agsScript_gun distance (nearestObject [agsScript_gun, "B45HETZER_B000"])) < 5) : agsScript_rekka = nearestObject [agsScript_gun, "B45HETZER_B000"]
?((agsScript_gun distance (nearestObject [agsScript_gun, "StM_Hetzer"])) < 5) : agsScript_rekka = nearestObject [agsScript_gun, "StM_Hetzer"]
?((agsScript_gun distance (nearestObject [agsScript_gun, "GST_Stug"])) < 5) : agsScript_rekka = nearestObject [agsScript_gun, "GST_Stug"]
?((agsScript_gun distance (nearestObject [agsScript_gun, "GST_Stugnoarm"])) < 5) : agsScript_rekka = nearestObject [agsScript_gun, "GST_Stugnoarm"]

agsScript_dummyobj setpos [getpos agsScript_gun select 0,getpos agsScript_gun select 1,-3]
goto "loop1"