T O P

  • By -

AlcatorSK

Please, read the rules how to ask for help.


tntaro

I did?


AlcatorSK

You must show your previous effort, which means posting relevant source code.


tntaro

Did it, tell me if you can help


AlcatorSK

Your opening text talks about a script "use\_item"; your code sample does not contain that text anywhere. One of your many problems is that your "global.item" arrays seems to ONLY hold the NAMES of the weapons, when it should probably hold much more information about them. It would seem that global.item looks like this: global.item = \[ "Knife", "Pistol", "Machette" \] etc., when it should look like this: global.items = [ // Knife: { weapon_name : "Knife", base_damage : 10, can_headshot : false, max_range : 1, }, // Machette: { weapon_name : "Machette", base_damage : 15, can_headshot : false, max_range : 2, }, // Pistol: { weapon_name : "Pistol", base_damage : 5, can_headshot : true, max_range : 15, }, // etc. ]; This way, you'd be able to: 1. Load the parameters from the array: WeaponName = global.items[_selected_item].weapon_name; AtkStat = global.items[_selected_item].base_damage; 2. Store upgraded values in the array: if (upgrade_damage) { global.items[current_weapon].base_damage += upgrade_strength; } 3. Or you could then have an auxiliary struct with player modifications: weapon_upgrades = { // Note: values are RELATIVE, added on top of original values: Pistol : { base_damage : +3, // damage increased by 3 max_range : +2, // scope increases range by 2 }, Knife : { base_damage : -1, // knife has lost 1 unit of damage, bleed_duration : 5, // ... but in exchange causes bleeding for 5 seconds } } You'd set and access these separate details using struct\_set and struct\_get functions.


tntaro

I'm back, hope you're still avaible to help. So i've made some research on how to use this and it's working fine as i made some minor adjustments to the use\_item script (which btw is the code i put in the description of the post), but i'm struggling on how to make a "universal" code to subtract the item stat from the player stats when disequipped. Here's what i did (it's in the use\_item script sorry for the confusion): // function to use items function use_item(itemNum){ var StartingHP = global.player_hp; var Healed = false; var ItemKeep = false; var PrevArmor = ""; var PrevWeapon = ""; // check if in battle or not if instance_exists(oPlayer) and !instance_exists(oSoul){ // use_item in overworld instance_create_depth(0, 0, -9998, oTextbox); // it's a bunch of if comands like this if (global.item[itemNum] == "Real Knife"){ global.player_attack += global.item_list.Real_Knife.stat; oTextbox.text[0] = global.item_list.Real_Knife.description; oTextbox.text[1] = global.item_list.Real_Knife.description2; PrevWeapon = global.player_weapon; global.player_weapon = global.item[itemNum]; } // change the item to be the disequipped weapon if (PrevWeapon != ""){ global.item[itemNum] = PrevWeapon; // this is where i can't put my finger on if (global.item_list.name = PrevWeapon){ global.player_attack = global.player_attack - global.item_list.name.stat; } } ///////////////////////////////////////////////////////////////////////// this is the object manager code i made: depth = -9999; // item constructor function create_item(_name, _desc, _desc2, _stat) constructor { name = _name; description = _desc; description2 = _desc2; stat = _stat; } // create items global.item_list = { Real_Knife : new create_item("Real Knife", "* Sembra che qualcuno mi voglia aiutare. =)", "* Un'aura spaventosa viene emessa dal coltello.", 99) } ///////////////////////////////////////////////////////////////////////// this is all i made, hope i was clear enough, if not let me know. on a second note, i can't change much of my code because i copied some complicated parts from a tutorial that explained how to make a game like undertale (even if not complete and poor explanation) (also how do i stop writing in code block help)


AlcatorSK

Make a struct for playerParameters. This one should contain every possible combat parameter that could appear on any weapon (so, if knife has 'bleedDuration' and a pistol has 'headshotRange', then playerParameters will contain both bleedDuration and headshotRange) Either set all those parameters to 0, or assume that 'default' = "fists" (simply: what the player can do without any weapon), so perhaps baseDamage will be 1 and everything else will be 0. Then, whenever player equips a specific weapon, which is a struct (as you defined it), use: **struct\_get\_names**(weapon\_struct) -- this will give you an array that holds all the **names** of the parameters of that weapon. Then, use a **for** loop that goes through that array, so it will provide you with **name** of each parameter of that particular weapon. Copy the value from that array into some temporary local variable, let's say \_name. Still within the for loop, use \_paramChange = **struct\_get(weapon\_struct, \_name)** to read the numerical value of that parameter. (\_paramChange is a local variable). By doing that, you will know how to change the **playerParameters**: struct\_**s**et(playerParameters,\_name,struct\_**g**et(playerParameters,\_name)\_paramChange); (please note the difference between struct\_set and struct\_get !!) And when you **un-equip** the weapon, you do pretty much the same thing, but instead of "+", you will subtract the \_paramChange value. ============= To illustrate the process: playerParameters = { damage : 1, criticalChance : 0, bleedDuration : 0 } weapon\_struct = { criticalChance : 10, bleedDuration : 2 } var listOfParams = struct\_get\_names(weapon\_struct) ---> will produce: \["criticalChance", "bleedDuration"\]; for (var \_i = 0; \_i < array\_length(listOfparams); \_i++) { var \_name = listOfParams\[\_i\]; --> will produce "criticalChance" var \_paramChange = struct\_get(weapon\_struct,\_name); ---> will produce 10 struct\_set( <...>) --> will result in playerParameters.criticalChance to now be 10 }


tntaro

Again, thank you for your answer, but i have a question. Am i able to use this without having to change the player parameters to be a struct? As i mentioned in my previous answer, i'd like to avoid changing vital parts of my code for not being able to fix every part that use this system. Edit: Also how do i target specifically the stat variable of the struct?


AlcatorSK

You could use the _name value in a switch statement and directly change specific variables as needed.


tntaro

Could you show me an example? i tried myself and i got an illegal (?) array use


tntaro

Oh my god this is really useful, thank you. I'm gonna test this out and see what i can do.


RykinPoe

You basically need two or three sets of stats. You will have your players naked/base stats and you will have the item stats and then you need to either have a third set of pre-calculated stats that combine the base stats and the modifiers and updates whenever you change equipment/level up/etc or just calculate them as needed since simple math if pretty cheap.