Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(3 edits) (+1)

1) Currently in playerweapon_randomly_pick_some_random_upgrades (used to pick valid choices for levelups, chests etc) we check if a weapon hasn't reached max upgrade level with the line:

global.weapon_upgrades_obtained[c] < global.weapon_data[c][pstat_UPGRADESMAX]

To give each individual upgrade a separate counter you'd need to update both of these accordingly:

  • Make global.weapon_upgrades_obtained a 2D array where the second member has PWD_LOCALDATA_MAX elements that all are initialized to 0 at the start of a run, this is done in playerweapon_initialize_run.
  • In obj_player's Alarm 0 event, the UPGRADETYPE_UPGRADEWEAPON block, now you'd change the ++ line to instead increment global.weapon_upgrades_obtained[global.confirmed_upgrades[c][upgd_WEAPONINDEX]][global.confirmed_upgrades[c][upgd_INDEX]]
  • In the playerweapons script macro section (just before playerweapon_initialize_run) add a new constant dbupgd_MAXUPGRADES, for readability I recommend putting this as 0 and incrementing all other dbupgd_ stats by 1. Then at the start of every upgrade in the database, add the desired max level there. For instance the sword's upgradedata should now start off with [[5,[pstat_ATKPOWER,1],NONE,"Whetstone"...
  • In playerweapon_randomly_pick_some_random_upgrades now finally change the second term to global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]

2) Yeah, currently triggerscripts are only used for things like the healing and money bag. I think the easiest way to implement this would be to make the actual update have no stat changes and no trigger script, and a max cap of 1 upgrades (see the answer to question 1) but the weapon's Player Shoot Script (e.g. pss_sword for the Hero Sword) checks if you have the upgrade, and if so alters the bullet's properties. The weapon script can check the variable currently_fired_weapon for the index in the player's active weapon list, and thus would check if global.weapon_upgrades_obtained[currently_fired_weapon][index_of_the_upgrade_in_the_list] > 0, for your convenience you'd probably want this upgrade to be first in the list so you don't need to count the already-confusing nested array slots.

I think for weapons using triggerscripts, you'd use them if the script does some one-off change that needs to work outside the weapon counter / PSS / stat system entirely, e.g. if the weapon creates a separate turret object rather than giving the player a weapon directly.

(1 edit)

Thank you for all your responces. I THINK I am following along so far, but the last element of Section 1 is throwing me off. What are you refering to be 'second term' in that function? Its not the argument I assume, so I'm not sure where to place that code. I've tried placing it as the second argument and setting 'include_weapons_we_have' to `global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]`, but this does not work.


Edit: If by second term you meant of the initially referenced line, I changed it to the following:

`if((global.weapon_upgrades_obtained[c] < global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]) || allow_surpassing_max_level){ //Can we upgrade it further?`

and got the following error, just in case

___________________________________________

############################################################################################

ERROR in

action number 1

of  Step Eventobj_player

for object parent_collectibleitem:

Push :: Execution Error - Variable Index [14] out of range [2] - -5.weapon_upgrades_obtained(100135,14)

 at gml_Script_playerweapon_randomly_pick_some_random_upgrades (line 97) -                             if((global.weapon_upgrades_obtained[c] < global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]) || allow_surpassing_max_level){ //Can we upgrade it further?

############################################################################################

gml_Script_playerweapon_randomly_pick_some_random_upgrades (line 97)

gml_Script_ics_exp (line 23) -               playerweapon_randomly_pick_some_random_upgrades(3,true,true,global.player_level >= 3,global.player_level >= 3,true,false)

gml_Object_parent_collectibleitem_Collision_obj_player (line 3) -               collection_script()

Second term as in "global.weapon_data[c][pstat_UPGRADESMAX]".

Hmm, judging by the message everything wasn't set up as expected (the upgrades_obtained array is too short), it should be a two-dimensional array that's got as many slots on the first axis as the number of weapons the player can obtain, and the second axis should have PWD_LOCALDATA_MAX elements (now I'm realizing that's not actually correct, you want this number to be the max number of different upgrade choices any weapon can have - we're addressing by upgrade index and not by stat - but so far none of them has 12 upgrade paths so it should be fine).

But either way, global.weapon_upgrades_obtained should be at least a 6-by-12 element array, but it's only 2 elements along one axis, so something's weird there. The first step would be to print its contents with show_debug_message(global.weapon_upgrades_obtained) at the start of the function and see what's actually in it when the game crashes. (Note that it's not enough to just set array[5][11] to 0 when initializing it, that'll give you a 6 element array which contains a 12-element array in the 6th slot and the number 0 in the prior five slots - 2D arrays are just arrays of 1D arrays so if you want the inner arrays to have the same length you need to manually put one in every slot of the outer array)

Oh yeah, and another issue, you're checking global.weapon_upgrades_obtained[c], but you should check global.weapon_upgrades_obtained[c][d] because upgrade level is per-upgrade now instead of shared for the entire weapon. (You'll need to move this check into the loop over array_length(ups) as well)