OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Aldo15 on 18 Oct 2011, 21:20:49
-
Hi,
Im trying to make a script who add the second weapon option, I don't know if you can understand me. Well I've tried severals way but no one work for me, I'd want to know if there's some script for that...
-
I believe this script works:
_guy = _this select 0
_pos = getpos _guy select 2
~1
_holder = "weaponholder" createvehicle getpos _guy
~1
;------------Edit Weapon Here-----------------
_holder addmagazinecargo ["HK",3]
_holder addweaponcargo ["HK",1]
;-------------------------------------------------
#loop
?vehicle _guy !=_guy: goto "loop2"
_holder setpos [(getpos _guy select 0),(getpos _guy select 1),(getpos _guy select 2)-0.5]
~0.1
goto "loop"
#loop2
?vehicle _guy ==_guy: goto "loop"
_holder setpos [(getpos _guy select 0),(getpos _guy select 1),(getpos _guy select 2)+500]
~0.1
goto "loop2"
exit
This basically creates a weapon holder (like a crate) directly below the player, allowing him to access another weapon. In this script the second weapon is an HK, but you replace it with any weapon of your choice.
I believe SBG made a script similar to this in his Kolgujev Contract mission, which I hear is more efficient (though I think the disadvantage with it is that the crate cannot be accessed when the player is in a guard tower)
-
Ok thanks I'll try it, but another question... we say: "if I want to shoot with a ak47 30/4 and then it has 14/4, well, now I change it by a m16, m16 has 30/4 magazine. Now my question is Can My unit or me have the ak47 with 14/4 magazines with the second option?
-
Do you mean that when you access the second weapon you want it to have 14/4? I'm not sure about that. If the AK was the main weapon then it might work.
-
You can list which primary weapon type (http://www.ofpec.com/COMREF/index.php?action=details&id=252&game=All) the player possesses, what magazine types (http://www.ofpec.com/COMREF/index.php?action=details&id=209&game=All) and then count (http://www.ofpec.com/COMREF/index.php?action=details&id=82&game=All) how many of the type you seeking, but there is no command in existence to count bullets or rounds per magazine that I am aware of.
-
I want tomake like some warfare games for example... Modern Warfare or medal of honor. You can use two weapons, we say aM14 and a ak47 or some onther weapon. As you can see we can use those two weapons, and you cahnge them they always appear wit the last magazines. I don't know if you guys are understanding but I don't know how to say you it.
-
The script Gruntage quoted is by Blip (http://www.ofpec.com/ed_depot/index.php?action=details&id=294&game=OFP). The problem you are having stems from the 'crate-like' behaviour of objects where magazines are automatically reloaded when weapons are taken. You can test it for yourself on crates, vehicles, or, as shown in the script, weaponholders. BUT IT DOES NOT APPLY TO DEAD BODIES!
Place a soldier far out of the way. Name him ColdDeadHands and set his health to zero. Remove all his weapons. IF YOU WANT, edit his Init line to load him with a weapon and magazines that the player can swap with straight away, for example:
removeAllWeapons this
removeAllWeapons this; this addMagazine "HK"; this addMagazine "HK"; this addMagazine "HK"; this addWeapon "HK"
In the init line of the player write:
player addAction ["Switch Weapons", "WEK_SwitchWeapons.sqs"]
if (primaryWeapon ColdDeadHands == "") then {goto "PutWeapon"}
; Swap Weapons
player action ["Take Weapon", ColdDeadHands, 0,0, (primaryWeapon ColdDeadHands)]
exit
; Put Weapon (because there was nothing to swap)
#PutWeapon
if (primaryWeapon player == "") then {hint "No weapons to swap between."; exit}
player action ["Drop Weapon", ColdDeadHands, 0,0, (primaryWeapon player)]
~1
ColdDeadHands action ["Take Weapon", player, 0,0, (primaryWeapon player)]
exit
Edit: updated the script for situations when the player has discarded one weapon and hence has nothing to swap with - in this circumstance the weapon is transferred to ColdDeadHands and the player is free to pick up something else. Although you can take weapons from dead bodies, you can't put them; they have to go via the empty crate.
Edit 2: But then again, dead bodies can take weapons directly from you. Spooky! This means an intervening crate is no longer required.
Edit 3: Realised that using a civilian with only 4 magazine slots might cause a problem - use a soldier instead.
Edit 4: Used primaryWeapon to select ColdDeadHands' weapon as well as the player's - now more consistent and hopefully a smidgen faster.