Call of Duty: Black Ops III

Call of Duty: Black Ops III

Not enough ratings
[Scripting] Buyable Powerups
By Mysti and 1 collaborators
   
Award
Favorite
Favorited
Unfavorite
Introduction
Hello everyone, this is hopefully one of many scripting tutorials I'll contribute to the community, first off, for this stimple one we're going to do the age old classic of buyable powerups, I may write a more specific one for specific perks such as buying a "Max Ammo" but for now we're going to keep it randomized and simple!
Map Requirements
So, not surpsingly you're going to need a tiny bit of map preperation for this. All you're going to need is a Trigger Use and a Script Struct.

First, you're going to want to place the Trigger Use around a button of some sort, make it flashy I guess?

Once you have it where you want it, give it this KVP:
Key
Value
targetname
Buyable_Powerup_Trigger

Now you're going to place the Script Struct where you want the perk to drop, once you have it where you want it give it the following KVP:
Key
Value
targetname
Buyable_Powerup_Location

Now double check you got it right as this is all for the map side of things in your map. Now we move onto the scripting.
Scripting Requirements
Finally we're up to the scripting side of things. Copy the code below into your own gsc file and reference it in your zone file.

#using scripts\codescripts\struct; #using scripts\zm\_zm_powerups; #using scripts\zm\_zm_score; #namespace buy_powerup; //Hint String For Trigger #define TRIGGER_HINT_STRING "Press and hold ^3[{+activate}] ^7to Spawn Powerup." //Icon For Trigger #define TRIGGER_HINT_ICON "HINT_NOICON" //How Many Seconds Until You Can Rebuy #define TRIGGER_COOLDOWN 120 //Cooldown Hint String For Triiger #define TRIGGER_COOLDOWN_HINT_STRING "Please Wait " + TRIGGER_COOLDOWN + " Seconds Before Buying Another Perk" //How Much Should Powerups Cost? #define POWERUP_COST 500 function autoexec init() { Poweup_Spawn_Location = struct::get( "Buyable_Powerup_Location", "targetname" ); Trigger = GetEnt( "Buyable_Powerup_Trigger", "targetname" ); Trigger SetCursorHint( TRIGGER_HINT_ICON ); while( 1 ) { Trigger SetHintString( TRIGGER_HINT_STRING ); Trigger waittill("trigger", Player); if( Player.score >= POWERUP_COST ) { Player zm_score::minus_to_player_score( POWERUP_COST ); zm_powerups::special_powerup_drop( Poweup_Spawn_Location.origin - .40 ); Trigger SetHintString( TRIGGER_COOLDOWN_HINT_STRING ); wait TRIGGER_COOLDOWN; } else { Player IPrintLnBold( "Not Enough Money" ); } } }


I have called my file buyable_powrups.gsc, DO NOT paste it into your normal mapname.gsc as it won't work. Once you have it in your own gsc file called whatever make a #usings directive in your mapname gsc like so

//Using Buyable Powerup Code by Johnathon #using scripts\zm\buyable_powerup;

The code will autorun thanks to the autoexc keyword used in the function header meaning you won't have to call any thread functions for it to work. Now to reference it in your zone file add the following line into your zone file

scriptparsetree,scripts/zm/buyable_powerup.gsc

This will give Linker the ability to see your file. Just make sure you save the buyable_powerup.gsc local to your map, ergo not in the share/scripts directory.
Final words
Thanks for reading another one of my tutorials, if you need any help getting this to work or have some scripting questions you can't seem to find answeres for feel free to either post them here or add me and I'll do my best to help you.


Thanks, Johnathon.
1 Comments
MrTomWaffles 31 Dec, 2016 @ 9:31am 
Nice one Man!:3arc: