S
SLx
Guest
Hi guys, I'm finally taking the dive into game development and had some very limited experience with GML about a decade ago during the GML 5.1 era. I used to do some (pretty bad) sprite work for a friend back then so unfortunately I don't have a ton of experience with the GML side of things.
---
I'm working with GMS2 and am in the midst of trying to put together a straight forward turn-based combat game. I'm trying to figure out what the best way to handle a weapons system is, without having to rely on individual objects per weapon. Allow me to elaborate:
Say there are 5 weapons: Pistol, Shotgun, SMG, LMG, Sniper.
Each of these weapons will share properties but the values will differ. For example, the properties can be:
0 Name -> A string with the weapon's name.
1 Damage -> A number with the amount of damage the weapon does.
2 Ammo -> Another number; how much ammo the weapon can hold.
3 Accuracy -> How accurate the weapon is (All from 0-100%, we'll say the LMK might only be 60-70% given the spread)
What would be the best way to handle this without relying on individual objects storing these variables?
I presume a ds_grid would be the optimal way. So I'd be setting up a ds_grid in the Create event of a controller object, or alternatively a script?
wpns = ds_grid_create(5,4); // I presume that the width (5 weapons) will be the width in columns, so I then set the height (4 values/properties) to be the rows.
Would I be correct in setting up the rest of the values as follows:
ds_grid_add(wpns,0,0,"Pistol"); //Name of the first weapon, Pistol
ds_grid_add(wpns,0,1,4); //Damage the Pistol does
ds_grid_add(wpns,0,2,10); //Ammo the pistol can hold
ds_grid_add(wpns,0,3,90); // Accuracy of the pistol (truth be told I'll handle this value differently but I'll leave it for the sake of an example.
I'd then go on to add the next weapon, the Shotgun, using ds_grid_add(wpns,1,0,"Shotgun"); correct? (Iterating 0-3 through the Y).
---
Once set, would I be able to reference this list and the values with my player object with a variable called 'heldweapon'? As such it would be dynamic depending on what weapon is being used. How would I handle an attack (with the shotgun, for e.g)? I can't do something such as:
obj_enemy.HP -= heldweapon[1,1];
...as this would be a regular 2D array, and the value [1,1] is hardcoded. What would be the best way to pass the information from the ds_grid to the heldweapon variable?
Apologies for the long post, just wanted to be concise. Any help with this would be appreciated. Can speak in DMs or on Discord if necessary.
Thanks.
---
I'm working with GMS2 and am in the midst of trying to put together a straight forward turn-based combat game. I'm trying to figure out what the best way to handle a weapons system is, without having to rely on individual objects per weapon. Allow me to elaborate:
Say there are 5 weapons: Pistol, Shotgun, SMG, LMG, Sniper.
Each of these weapons will share properties but the values will differ. For example, the properties can be:
0 Name -> A string with the weapon's name.
1 Damage -> A number with the amount of damage the weapon does.
2 Ammo -> Another number; how much ammo the weapon can hold.
3 Accuracy -> How accurate the weapon is (All from 0-100%, we'll say the LMK might only be 60-70% given the spread)
What would be the best way to handle this without relying on individual objects storing these variables?
I presume a ds_grid would be the optimal way. So I'd be setting up a ds_grid in the Create event of a controller object, or alternatively a script?
wpns = ds_grid_create(5,4); // I presume that the width (5 weapons) will be the width in columns, so I then set the height (4 values/properties) to be the rows.
Would I be correct in setting up the rest of the values as follows:
ds_grid_add(wpns,0,0,"Pistol"); //Name of the first weapon, Pistol
ds_grid_add(wpns,0,1,4); //Damage the Pistol does
ds_grid_add(wpns,0,2,10); //Ammo the pistol can hold
ds_grid_add(wpns,0,3,90); // Accuracy of the pistol (truth be told I'll handle this value differently but I'll leave it for the sake of an example.
I'd then go on to add the next weapon, the Shotgun, using ds_grid_add(wpns,1,0,"Shotgun"); correct? (Iterating 0-3 through the Y).
---
Once set, would I be able to reference this list and the values with my player object with a variable called 'heldweapon'? As such it would be dynamic depending on what weapon is being used. How would I handle an attack (with the shotgun, for e.g)? I can't do something such as:
obj_enemy.HP -= heldweapon[1,1];
...as this would be a regular 2D array, and the value [1,1] is hardcoded. What would be the best way to pass the information from the ds_grid to the heldweapon variable?
Apologies for the long post, just wanted to be concise. Any help with this would be appreciated. Can speak in DMs or on Discord if necessary.
Thanks.