Home   Help Search Login Register  

Author Topic: arming the unarmed from the dead. weaponholder contents.  (Read 878 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
What I would like to do is have a script to make unarmed soldier pickup the nearest weapon from a dead soldier.  I do not believe this can be done simply since the contents of weaponholders can not be queried, and the take weapon action requires the weapon type. Can someone pls confirm this fact? Also, if the take weapon action specifies a weapon type that is not in the weaponholder, the soldier gets stuck in the crouching phase of the animation.

When a soldier is killed, is the weaponholder object created before or after a killed eventhandler attached to the soldier fires? i.e. do user defined eventhandlers fire before or after OFP's default eventhandlers?

Thanks.
urp!

StonedSoldier

  • Guest
Re: arming the unarmed from the dead. weaponholder contents.
« Reply #1 on: 10 Jun 2006, 01:01:19 »
you raise a good question,

my solution was a quick script i wrote earlier today, whereby you make an array containing all the enemy troops that you want to consider taking weapons later when theyre dead,

by passing the name of that array along with the name of the unarmed soldier, the script will first generate a second array containing all those soldiers who have died and still have weapons on their corpses it will then find the closest dead body to the unarmed man then the unarmed man will move to the nearest corpse and take his weapon,

[array of enemies,name of unarmed man] exec "takeweapon.sqs"

Code: [Select]
_men = _this select 0
_unarmedman = _this select 1
_deadmen = []

_num = 0
#check
_man = _men select _num
?not alive _man && ((count weapons _man)>0):_deadmen = _deadmen + [_man]
_num = _num + 1
?_num!=(count _men):goto "check"

###########################
#find nearest deadbody

_nearesdis = 10000
_num = 0

#check2
?((_deadmen select _num) distance _unarmedman)<_nearesdis:_nearesdis = ((_deadmen select _num) distance _unarmedman); _nearestman = _num
_num = _num + 1
?_num!=(count _deadmen):goto "check2"

_nearestman = _deadmen select _nearestman
_unarmedman domove getpos _nearestman

@(_unarmedman distance _nearestman)<1

_unarmedman action ["take weapon",_nearestman,0,0,(primaryweapon _nearestman)]

apoligies for any typos and any areas of the script which could be done better i knocked it together really quickly
« Last Edit: 10 Jun 2006, 03:33:54 by StonedSoldier »