Call of Duty: Black Ops III

Call of Duty: Black Ops III

Not enough ratings
[Scripting] Weapon Swap Cabinet
By Mysti and 1 collaborators
   
Award
Favorite
Favorited
Unfavorite
Introduction
Hey everyone, this is going to be a tutorial on how you can make a weapon swap place for your map, so people can trade guns. So without messing about, as Keemstar says. Let's get riiiiight into the news!
Map Requirements
This section is going to be pretty tiny, since all you need is a trigger, you don't really need a model, but to make it "pretty" you might as well, yeah. First off, drag a Trigger Use
Give it the following KVP
Key
Value
targetname
Swap_Weapon


That's all we need in the map, so now on to the scripting!
Script Side
So, this is where the real magic happens, first I'll start off by saying remember to put the scriptparsetree in your zone if you're going to place this in an external file, which I'd recommend as it's what I am going to do and the code below is going to assume the same thing.

Put the following code in it's own gsc file
#using scripts\zm\_zm_utility; //Hint String For Trigger #define SWAP_WEAPON_HINT "Press and hold ^3[{+activate}] ^7to store weapon" //Hint Icon For Trigger #define SWAP_WEAPON_ICON "HINT_NOICON" //Can They Store Only Weapon? #define CAN_STORE_SINGLE_WEAPON true //Stored Weapon Hint (Weapon name at end) #define GET_STORED_HINT "Press and hold ^3[{+activate}] ^7to take stored weapon" function autoexec init() { Trigger = GetEnt("Swap_Weapon", "targetname"); Trigger SetHintString(SWAP_WEAPON_HINT); Trigger SetCursorHint(SWAP_WEAPON_ICON); Stored = false; do { Trigger waittill("trigger", Who); if(CAN_STORE_SINGLE_WEAPON == false && Who GetWeaponsListPrimaries().size == 1) { IPrintLnBold("You can't store your only weapon!"); } if (Stored == false && zm_utility::is_player_valid(Who) && isValid(Who GetCurrentWeapon())) { Stored = true; StoredWeapon = Who GetCurrentWeapon(); Who TakeWeapon(Who GetCurrentWeapon()); Trigger SetHintString(GET_STORED_HINT); } else { Stored = false; Who GiveWeapon(StoredWeapon); Who SwitchToWeapon(StoredWeapon); Trigger SetHintString(SWAP_WEAPON_HINT); Trigger SetCursorHint(SWAP_WEAPON_ICON); } wait .1; }while(true); } function isValid(Weapon) { if (Weapon == "frag_grenade" || Weapon == "minigun") { return false; } else { return true; } }

So, that's all the code you should need, you can change it around how you like and see fit, mostly you'll probably be editing the defines, but you could also beadding custom catches if you've ported weapons or the like. Anyway that's it! Like I said, I've plopped this into it's own gsc file, then just add a #using directive for it then you're good to go thanks to the nice autoexec :).
Final Words
Now this script isn't exactally fool proof, but I couldn't get it to break with Chris, so if you somehow get it to break let me know what you did to break it and I'll get on updating the code.

I try to make most scripts as modular as possible for everyone, if you want less or more of certain feautes in the code let me know and I'll try implement it. For now hope this was easy to follow.

Thanks, Johnathon.
1 Comments
Snoberts 6 Jan, 2017 @ 12:47pm 
Great tut!