Jump to content

Sign in to follow this  
mk82

how to add players weapons and magazines to an object

Recommended Posts

Hello,

I'm working on a multiplayer mission where dead players get replaced by an object.

I would like to add the players weapons and magazines to that object but don't know the syntax.

Something like:

"_object addMagazine[u]cargo[/u] _x" forEach magazines _player
"_object addWeapon[u]cargo[/u] _x" forEach weapons _player

Share this post


Link to post
Share on other sites
  mk82 said:
Hello,

I'm working on a multiplayer mission where dead players get replaced by an object.

I would like to add the players weapons and magazines to that object but don't know the syntax.

Something like:

"_object addMagazine[u]cargo[/u] _x" forEach magazines _player
"_object addWeapon[u]cargo[/u] _x" forEach weapons _player

I think that might be a beginning towards a functional script:

_wp = [weapons player select 0] ;; would be primary weapon
_object addWeaponCargo [_wp,1]
_mag = [magazines player select 0] ;; would be the first magazine in the menu list
_magCount = count (magazines player) ;; counts them all, not a specific type. For countType command, they'd have to be defined first
_object addMagazineCargo [_mag,_magCount] 

Share this post


Link to post
Share on other sites

Thanks Lenyoga,

but isn't there a way to add the exact amouth of weapons and ammo, handguns, rocketlaunchers and rockets included?

Share this post


Link to post
Share on other sites

There is, but you'll have to find out each weapon and magazine slot individually. I can't give you a full script, but the pieces which are essential, I hope:

;; this checks what contents each weapon slot has, you can store those directly to the object, then, but you'd have to add a check to make sure, it's not empty, otherwise an error message will show up every time the script runs
;; 0 is the primary weapon (M16 and so on) 1 is a launcher weapon, 2 is a pistol, - they give you <null> if they're empty

_wp1= (weapons _player select 0)
_wp1 = (weapons _player select 1) 

;; this checks what contents each magazine slot has, same as above

_mag1 = (magazines _player select 0)
_mag2 = (magazines _player select 1) 

-- in the end, all you need to do is to run the check blocks which give you the contents, then run a segment which adds each weapon and magazine to the object (with a check before, if it's empty.) - The problem here is that empty magazine or weapon slots sometimes give you error messages, which are of course looking bad in the game.

---------- Post added at 21:44 ---------- Previous post was at 21:07 ----------

Update: Alright, I tested it with adding a non-existing magazine to a crate, no error messages visible, so you don't need to add any sort of check which determines if there are actually magazines or weapons in the slots. I did it like this, with a test soldier (once with an M16 and all magazines, once with no weapon at all, and no magazines)

_player = player
_container = crate1
_mag1 = magazines _player select 0
Hint format["Magazine slot 1 contains a %1 magazine", _mag1]
~2
Hint format["%1 magazine added to Ammo Crate", _mag1]
_container addMagazineCargo [_mag1,1]
exit

Share this post


Link to post
Share on other sites

Can the corpses of players perform actions?

If so, then Action "Drop Weapon" could be used to move across a weapon and its magazines (including any that are half empty). Along the lines of:

_player action ["DROP WEAPON",_playertombstone,1,1,(primaryWeapon _player)]

However, I think Lenyoga is correct in suggesting the way to proceed is to generate arrays: firstly, of weapons - loop through them checking they are not <null> and move them across. Then of any magazines that have been missed.

Share this post


Link to post
Share on other sites

Hello,

unfortunately "drop weapon/magazine" doesn't work on dead bodys. The other approach only works if the objcts has cargo slots like an ammo box or a vehicle, but I would like to add the loadout on a "grave".

Share this post


Link to post
Share on other sites

You could fake it by putting an ammo crate on the grave and setpos with a -Z to burry it in the ground to hide it.

  mk82 said:
Hello,

unfortunately "drop weapon/magazine" doesn't work on dead bodys. The other approach only works if the objcts has cargo slots like an ammo box or a vehicle, but I would like to add the loadout on a "grave".

Share this post


Link to post
Share on other sites

I think I'll try it.

First I was uncertain beacause on hilly areas the ammo case might be seen but on second though, seeing a coffin unter the grave is not that bad.

Share this post


Link to post
Share on other sites

_player = dummy
_container = crate1

_weap0 = weapons _player select 0
_weap1 = weapons _player select 1
_weap2 = weapons _player select 2
_weap3 = weapons _player select 3
_weap4 = weapons _player select 4

_mag0 = (magazines _player select 0)
_mag1 = (magazines _player select 1)
_mag2 = (magazines _player select 2)
_mag3 = (magazines _player select 3)
_mag4 = (magazines _player select 4)
_mag5 = (magazines _player select 5)
_mag6 = (magazines _player select 6)
_mag7 = (magazines _player select 7)
_mag8 = (magazines _player select 8)
_mag9 = (magazines _player select 9)


_mag10 = (magazines _player select 10)
_mag11 = (magazines _player select 11)
_mag12 = (magazines _player select 12)
_mag13 = (magazines _player select 13)

~1


_container addweaponCargo [_weap0,1]
_container addweaponCargo [_weap1,1]
_container addweaponCargo [_weap2,1]
_container addweaponCargo [_weap3,1]
_container addweaponCargo [_weap4,1]


_container addmagazinecargo [_mag0,1]
_container addmagazinecargo [_mag1,1]
_container addmagazinecargo [_mag2,1]
_container addmagazinecargo [_mag3,1]
_container addmagazinecargo [_mag4,1]
_container addmagazinecargo [_mag5,1]
_container addmagazinecargo [_mag6,1]
_container addmagazinecargo [_mag7,1]
_container addmagazinecargo [_mag8,1]
_container addmagazinecargo [_mag9,1]

_container addmagazinecargo [_mag10,1]
_container addmagazinecargo [_mag11,1]
_container addmagazinecargo [_mag12,1]
_container addmagazinecargo [_mag13,1]

Causes error message for example in some cases when there are empty slots or pieces of ammo carried who take two or more slots (such as lawlauncher). On the other hand it adds all weapons and magazines to the box but the error message indeed isn't nice...

'_mag13 =(magazines _player select 13)|#|': Error Zero divisor

Edited by mk82

Share this post


Link to post
Share on other sites

Stupid error messages, they complain all the time, but never help with any of the actual work.

If you have a restricted amount of weapon and magazine types in your mission, you can add check lines like those:


#Nr8
?((magazines _player select 8) != "M16") and ((magazines _player select 8) != "WeaponMagazineName"): goto "Nr9"
_mag8 = (magazines _player select 8)
[/Code]

I hope then it doesn't even feel the need to display that the magazines command is unhappy about the absence of anything.

Share this post


Link to post
Share on other sites
  mk82 said:
but I would like to add the loadout on a "grave".

How about a grave, with the weapons on top of it or laying alongside (like in some missions in which you take weapons from a table)? If that's what you meant you should use weaponholder's.

These need care as they're createVehicle'd and you don't want multiple instances to be spawned.

There is a ten-year old script for this here on the forums, but I'm afraid the change in forum formatting has not left it very legible.

Update: this should be cleared up (just needed pasting in here, and the formatting cured itself)

  Quote

;

; ammosprinkler.sqs

;

; Usage

;

; [unit] exec "ammosprinkler.sqs"

;

; Or, to prevent the deletion of the dead corpse (possibly due to having some

; other nifty script do it

;

; [unit, false] exec "ammosprinkler.sqs"

;

; Some constants. Edit them to your liking

; Name of this script. If you choose to rename it, change _THISSCRIPT

; to the same name. Default: "ammosprinkler.sqs"

_THISSCRIPT = "ammosprinkler.sqs"

; How long before the corpse is removed and the ammo is created where it was

_REMOVEDELAY = 100

; The "wait until unit is dead"-loop delay

_DEADDELAY = 1

; The "search for a WeaponHolder" loop delay and search timeout

_SEARCHDELAY = 1

_SEARCHTIMEOUT = 20

;-----------------------------------------------------------------------------------

; No need to edit below this

;-----------------------------------------------------------------------------------

?(count _this == 0 && local player): hint "Error: "+ _THISSCRIPT + " called with no parameters! Exiting."; exit

?(count _this == 0): exit

_dude = _this select 0

_bDelete = true

; Someone is possibly overriding the default value for deleting the dead body

?count _this > 1: _bDelete = _this select 1

; Script is called with all three parameters. Jump to the label indicated by

; the third parameter.

?count _this > 2: goto (_this select 2)

#init

?local _dude: [_dude, _bDelete, "local"] exec _THISSCRIPT; exit

[_dude, _bDelete, "nonlocal"] exec _THISSCRIPT

exit

#local

#localwait

~_DEADDELAY

?alive _dude: goto "localwait"

_wpns = weapons _dude

_mags = magazines _dude

_magcount = count _mags

_wpncount = count _wpns

~_REMOVEDELAY

?(getDammage _dude < 0.95): exit

_pos = getPos _dude

_wpnh = "WeaponHolder" createVehicle _pos

_c = 0

while "_c < _magcount" do {_wpnh addMagazineCargo [format ["%1",(_mags select _c)],1]; _c = _c + 1}

_c = 0

while "_c < _wpncount" do {_wpnh addWeaponCargo [format ["%1",(_wpns select _c)],1]; _c = _c + 1}

~(2+_SEARCHTIMEOUT)

?(!isNull _dude && _bDelete): deleteVehicle _dude

; all done locally

exit

#nonlocal

#nonlocalwait

~_DEADDELAY

?alive _dude: goto "nonlocalwait"

_wpns = weapons _dude

_mags = magazines _dude

_magcount = count _mags

_wpncount = count _wpns

~_REMOVEDELAY

?(getDammage _dude < 0.95): exit

; On the machine where the unit was local, a WeaponHolder is created. Here, we

; just wait for it to appear and snag it.

_tstamp = _time

_timeout = _tstamp + _SEARCHTIMEOUT

#nlloop

~_SEARCHDELAY

_wpnh = nearestObject [_dude, "WeaponHolder"]

?((_time < _timeout) && isNull _wpnh): goto "nlloop"

; Just a failsafe: Did we get it? If not, just give up, exit and hope some other dead soldier

; will generate a proper ammo pile for players to loot.

?isNull _wpnh: exit

; Ok, we have a WeaponHolder created on some other machine where _dude was local.

; If its empty, fill it to spec. If it isn't empty, it probably means

; that some other guy died nearby and we got hold of that one instead.

; If so, TS - just give that holder even more ammo.

_c = 0

while "_c <= (_magcount - 1)" do {_wpnh addmagazineCargo [format ["%1",(_mags select _c)],1]; _c = _c + 1}

_c = 0

while "_c <= (_wpncount - 1)" do {_wpnh addweaponCargo [format ["%1",(_wpns select _c)],1]; _c = _c + 1}

; all done non-locally

exit

Edited by -rageQuit-

Share this post


Link to post
Share on other sites

Seems to work this way. Thanks @ all.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×