HDSnekTechDiscountPartyPack/zscript/snektech.zs

120 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

2023-09-03 16:33:10 -07:00
// ----------------------------------------------------------------------
// Snektech
// ----------------------------------------------------------------------
//
// Spawn flags for SnekTech items handled here.
//
2023-09-02 18:36:48 -07:00
enum SnekTechSpawnFlags
{
2023-09-02 20:48:24 -07:00
SNEKTECH_GRETCHENCOUNTER = 0,
SNEKTECH_JUMPERCABLES = 1,
2023-09-09 13:00:20 -07:00
SNEKTECH_CACOPLUSHIE = 2,
SNEKTECH_SPRAYCAN = 3
2023-09-02 18:36:48 -07:00
}
class SnekTechEventHandler : EventHandler
{
bool GetItemEnabled(int item)
{
int spawnFlags = CVar.GetCVar("snektech_spawnflags").GetInt();
if(spawnFlags & (1 << item)) {
return true;
}
return false;
}
void DoSnekTechBackpackSpawnCheck(
Actor maybePack,
int itemFlagIndex,
String itemClass)
{
HDBackpack pack = HDBackpack(maybePack);
if(pack && !pack.owner) {
if(!GetItemEnabled(itemFlagIndex)) {
pack.storage.DestroyItem(itemClass);
}
}
}
void DoSnekTechReplacement(
int itemFlagIndex,
class<Actor> Replacee,
class<Actor> Replacement,
int chance,
ReplaceEvent e)
{
if(GetItemEnabled(itemFlagIndex)) {
if(e.Replacee == Replacee) {
if(random() < chance) {
e.Replacement = Replacement;
}
}
}
}
override void WorldThingSpawned(WorldEvent e)
{
if(!e.Thing) {
return;
}
// Disable drop useless ammo for batteries.
HDBattery bat = HDBattery(e.Thing);
if(bat) {
bat.ItemsThatUseThis.Push("GretchenCounter");
2023-09-03 15:04:00 -07:00
bat.ItemsThatUseThis.Push("JumperCablesUsable");
2023-09-02 18:36:48 -07:00
}
// Delete disabled items from backpacks that just spawned.
2023-09-02 20:48:24 -07:00
DoSnekTechBackpackSpawnCheck(
e.Thing,
SNEKTECH_GRETCHENCOUNTER,
"GretchenCounter");
DoSnekTechBackpackSpawnCheck(
e.Thing,
SNEKTECH_JUMPERCABLES,
"JumperCablesUsable");
DoSnekTechBackpackSpawnCheck(
e.Thing,
SNEKTECH_CACOPLUSHIE,
"KiriCacodemonPlushie");
2023-09-09 14:34:54 -07:00
DoSnekTechBackpackSpawnCheck(
e.Thing,
SNEKTECH_SPRAYCAN,
"SnekTechSprayer");
2023-09-02 18:36:48 -07:00
}
override void CheckReplacement(ReplaceEvent e)
{
if(!e.Replacement) {
return;
}
if(e.isFinal) {
return;
}
2023-09-02 20:48:24 -07:00
DoSnekTechReplacement(
SNEKTECH_GRETCHENCOUNTER,
2023-09-09 21:10:00 -07:00
"PortableStimpack", "GretchenCounter",
2, e);
2023-09-02 20:48:24 -07:00
DoSnekTechReplacement(
SNEKTECH_JUMPERCABLES,
"Allmap", "JumperCablesUsable",
12, e);
DoSnekTechReplacement(
SNEKTECH_CACOPLUSHIE,
"BlurSphere", "KiriCacodemonPlushie",
2023-09-03 16:33:10 -07:00
6, e);
2023-09-09 14:34:54 -07:00
// Note: No replacements for spray cans.
2023-09-02 18:36:48 -07:00
}
}