Created
February 10, 2021 13:59
-
-
Save illixion/ac1f37488672558a304890605e4e38e8 to your computer and use it in GitHub Desktop.
Nuclear Throne: send GET request upon death (API integration)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This mod will send a web request when you die in-game. | |
// I've implemented an additional check for Chicken's passive ability, since there is seemingly no way to know when you /actually/ died. | |
// PLEASE NOTE: Nuclear Throne Together may be required, I have't checked. | |
// This mod is a derivative of https://github.com/Strangework/eott-ntt | |
#define init | |
// List of every mean motherfucker in this game | |
// Miscellaneous (aren't specific to an area) | |
global.MiscBaddies[0] = Bandit | |
global.MiscBaddies[1] = Gator | |
global.MiscBaddies[2] = EnemyHorror | |
global.MiscBaddies[3] = CrownGuardian | |
global.MiscBaddies[4] = Mimic | |
global.MiscBaddies[5] = SuperMimic | |
global.SewerBaddies[6] = MeleeBandit | |
// Desert | |
global.DesertBaddies[0] = RadMaggot | |
global.DesertBaddies[1] = GoldScorpion | |
global.DesertBaddies[2] = MaggotSpawn | |
global.DesertBaddies[3] = BigMaggot | |
global.DesertBaddies[4] = Maggot | |
global.DesertBaddies[5] = Scorpion | |
// Sewers | |
global.SewerBaddies[0] = SuperFrog | |
global.SewerBaddies[1] = BuffGator | |
global.SewerBaddies[2] = Ratking | |
global.SewerBaddies[3] = Rat | |
global.SewerBaddies[4] = FastRat | |
global.SewerBaddies[5] = Turtle | |
// Scrapyard | |
global.ScrapyardBaddies[0] = Sniper | |
global.ScrapyardBaddies[1] = Raven | |
global.ScrapyardBaddies[2] = Salamander | |
// Crystal caves | |
global.CrystalCavesBaddies[0] = Spider | |
global.CrystalCavesBaddies[1] = LaserCrystal | |
global.CrystalCavesBaddies[2] = LightningCrystal | |
// Frozen city | |
global.FrozenCityBaddies[0] = SnowTank | |
global.FrozenCityBaddies[1] = GoldSnowTank | |
global.FrozenCityBaddies[2] = SnowBot | |
global.FrozenCityBaddies[3] = Wolf | |
// Labs | |
global.LabsBaddies[0] = RhinoFreak | |
global.LabsBaddies[1] = Freak | |
global.LabsBaddies[2] = Turret | |
global.LabsBaddies[3] = ExploFreak | |
global.LabsBaddies[4] = Necromancer | |
// Palace | |
global.PalaceBaddies[0] = ExploGuardian | |
global.PalaceBaddies[1] = DogGuardian | |
global.PalaceBaddies[2] = GhostGuardian | |
global.PalaceBaddies[3] = Guardian | |
// Mansion | |
global.MansionBaddies[0] = Molefish | |
global.MansionBaddies[1] = FireBaller | |
global.MansionBaddies[2] = SuperFireBaller | |
global.MansionBaddies[3] = Jock | |
global.MansionBaddies[4] = Molesarge | |
// IDPD | |
global.PopoBaddies[0] = Van | |
global.PopoBaddies[1] = PopoFreak | |
global.PopoBaddies[2] = Grunt | |
global.PopoBaddies[3] = EliteGrunt | |
global.PopoBaddies[4] = Shielder | |
global.PopoBaddies[5] = EliteShielder | |
global.PopoBaddies[6] = Inspector | |
global.PopoBaddies[7] = EliteInspector | |
// Oasis | |
global.OasisBaddies[0] = Crab | |
global.OasisBaddies[1] = BoneFish | |
// Jungle | |
global.JungleBaddies[0] = JungleAssassin | |
global.JungleBaddies[1] = JungleFly | |
global.JungleBaddies[2] = JungleBandit | |
trace("NTS loaded") | |
with (Player) { | |
is_swapped = false | |
global.last_wep = wep | |
global.last_bwep = bwep | |
} | |
global.curr_area = 10 | |
global.curr_subarea = 0 | |
global.baddies = [] | |
global.player_muts = 0 | |
global.player_initialized = false // Player initialization is not possible until the player entity is (re)created. Initialization occurs within a conditional block in step() | |
global.kill_map = ds_map_create() | |
global.dead = false | |
#define step | |
// Perform any one-time player initializations | |
if (!global.player_initialized and instance_exists(Player)) { | |
Player.last_wep = Player.wep | |
Player.last_bwep = Player.bwep | |
global.player_initialized = true | |
} | |
// Check for enemy deaths | |
for (i=0; i<array_length_1d(global.baddies); i++) { | |
with(global.baddies[i]){ | |
var name = object_get_name(object_index) | |
if (my_health <= 0 and name == "Player") { | |
wait 10; | |
if (TopCont.dead > 0 and global.dead == false) { | |
trace("You're dead, not big surprise.") | |
global.dead = true | |
} | |
var url, headers, data; | |
url = "https://localhost:3000/player_died"; | |
headers = ds_map_create(); | |
data = ds_map_create(); | |
http_request(url, "GET", headers, json_encode(data)); | |
ds_map_destroy(headers); | |
ds_map_destroy(data); | |
global.kill_map[? name] = global.kill_map[? name] | |
return | |
} else if (global.dead == true and my_health > 0 and name == "Player") { | |
// trace("Not dead anymore!") | |
global.dead = false | |
} | |
} | |
} | |
// End of level logic | |
if GameCont.area != global.curr_area or GameCont.subarea != global.curr_subarea { | |
// trace("Here we go again!") | |
// Log level change | |
global.curr_area = GameCont.area | |
global.curr_subarea = GameCont.subarea | |
// Update enemy list | |
global.baddies = get_baddie_list(global.curr_area) | |
// Create new kill map | |
// TODO : Find a more reliable value to be used as a key! Instantiating the map before the level loads means that the objects are unavailable, so deriving their names from their object IDs doesn't work | |
ds_map_destroy(global.kill_map) | |
global.kill_map = ds_map_create() | |
for (i=0; i<array_length_1d(global.baddies); i++) { | |
with(global.baddies[i]) { | |
global.kill_map[? object_get_name(object_index)] = 0 | |
} | |
} | |
// Check for new mutations | |
new_muts = global.player_muts | |
for (i = 0; i < 29; i++) { | |
if (skill_get(i+1)) { | |
new_muts = new_muts | 1 << i | |
} | |
} | |
// If there are new mutations, log the change | |
if (global.player_muts != new_muts) { | |
global.player_muts = new_muts | |
} | |
} | |
#define get_baddie_list(area) | |
// TODO : Add looping logic | |
switch (area) { | |
case 1: | |
return concatenate_1d_arrays(global.DesertBaddies, global.MiscBaddies) | |
break | |
case 2: | |
return concatenate_1d_arrays(global.SewerBaddies, global.MiscBaddies) | |
break | |
case 3: | |
return concatenate_1d_arrays(global.ScrapyardBaddies, global.MiscBaddies) | |
break | |
case 4: | |
return concatenate_1d_arrays(global.CrystalCavesBaddies, global.MiscBaddies) | |
break | |
case 5: | |
return concatenate_1d_arrays(global.FrozenCityBaddies, global.MiscBaddies) | |
break | |
case 6: | |
return concatenate_1d_arrays(global.LabsBaddies, global.MiscBaddies) | |
break | |
case 7: | |
return concatenate_1d_arrays(global.PalaceBaddies, global.MiscBaddies) | |
break | |
} | |
#define concatenate_1d_arrays(x, y) | |
z = x | |
for (i=0; i < array_length_1d(y); i++) { | |
z[i+array_length_1d(x)+1] = y[i] | |
} | |
return z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment