My game is a 3rd person RPG. Currently, whenever a player kills an enemy, an item drops. The item looks like a small Point Defense Drone unit (brought down to ground level). When the player approaches the unit, a window pops up that shows an image corresponding to the type of item that dropped, and its stats. Even if the player is within range of multiple items, only one item window will show at a time. If you still want more clarity on how my game works, here's a picture:
Now, I know how to calculate chances for all of the different varying aspects, like the item type, its stats, etc. What I need your help with is figuring out how to SAVE these stats to the point defense drone "unit" so that every time I leave the radius of the item drop and come back later, the same stats will show. I'll probably also utilize this same method, whatever it turns out to be, to save these item stats for items that players equip and/or place in their inventory.
If this were a standard programming language, I'd just make an item class, but as far as I'm aware, we can't do anything like new variable types, objects, etc without going directly into the sc2 code itself, which I don't want to attempt.
Thanks for any and all help! I do appreciate it :) And if you need any more context, just let me know
You can use a "record" (in trigger editor right click on left trigger bar and new>record) or press ctrl+U.
A record is basically like a struct, or a class without functions, in which you can store multiple types within the same variable. So for example a record can contain a unit for the item and several stat values for the item.
Then you can create an array of variables of type "item record".
The only downside is that you will have to specify a MAX number of items, since array lengths cannot be changed in-game in SC2.
If you didn't want to have to specify a max number of items, another way you could do it is using custom values. Every unit in the game can be assigned custom values (reals) and you could put all the stats values in there. But if you did this you would have to encode the string values of the items into reals. So it's probably just best to use records and make the array size higher than you think the number of items will ever reach.
Use data tables. You can store seemingly any reasonable amount of info in them, though they are much slower than variables, so yea, dynamic storage space.
Spawn unit (item), assign item an ID, save that ID in units custom value, save all items data in data table. Data tables are both simple and awesome :D
I imagine you wouldn't want to use them in any instant arthritics such as AI. Didn't have the need to test it myself since heard several people who should know what they're talking about say that they're slow.
I'm using them to save/recall item data/stuff. If you want to know more I imagine you would have better luck asking in IRC, people like G0A and Ahli were using them way back when I didn't even know they existed.
Thanks for the help guys! I just spent a good 3 hours detailing all the item stats, generating them properly, name banks, blah blah blah.. However theres still a couple things I need help with.
Right now, every time an item "unit" (the Point Defense drone in the pic in OP) is created, an item is now generated as follows:
-I have a Record for Armor type items, with all the related stats they might have, as well as a record for Weapons, and "Other" items (but just the armor one is done for now)
-I have a Variable referring to that record, in the form of an array of size 1000 (simply because I don't think we can do ArrayLists in sc2mapmaker, and I doubt they'll have 1,000 not-picked-up armor items on the ground at once)
-When a new item is generated, it is set to the Record Variable (the array), at the index of CurrNumArmorPiecesOnGround, and CurrNumArmorPiecesOnGround is incremented.
-So when all of the stats in the record are filled, the first stat filled is a variable of type Unit, that is set to the item "unit" (point defense drone) that is created when the player kills an enemy and the item first drops.
MY PROBLEM: My trigger to show the item pickup window is when the player enters within a distance of a unit of type itemUnit, and I need to update the info in that window for the triggering unit's item stats. However I don't know how to do this, because afaik, I can't get the index in the array that this item belongs to.
I could also assign a value to the unit itself equal to the index number when it is first assigned, but as far as I know, I can't just assign an int value to a specific unit in the map.
So how can I do get the item stats from the triggering unit?
My game is a 3rd person RPG. Currently, whenever a player kills an enemy, an item drops. The item looks like a small Point Defense Drone unit (brought down to ground level). When the player approaches the unit, a window pops up that shows an image corresponding to the type of item that dropped, and its stats. Even if the player is within range of multiple items, only one item window will show at a time. If you still want more clarity on how my game works, here's a picture:
Now, I know how to calculate chances for all of the different varying aspects, like the item type, its stats, etc. What I need your help with is figuring out how to SAVE these stats to the point defense drone "unit" so that every time I leave the radius of the item drop and come back later, the same stats will show. I'll probably also utilize this same method, whatever it turns out to be, to save these item stats for items that players equip and/or place in their inventory.
If this were a standard programming language, I'd just make an item class, but as far as I'm aware, we can't do anything like new variable types, objects, etc without going directly into the sc2 code itself, which I don't want to attempt.
Thanks for any and all help! I do appreciate it :) And if you need any more context, just let me know
@PerAnimus: Go
You can use a "record" (in trigger editor right click on left trigger bar and new>record) or press ctrl+U.
A record is basically like a struct, or a class without functions, in which you can store multiple types within the same variable. So for example a record can contain a unit for the item and several stat values for the item.
Then you can create an array of variables of type "item record".
The only downside is that you will have to specify a MAX number of items, since array lengths cannot be changed in-game in SC2.
If you didn't want to have to specify a max number of items, another way you could do it is using custom values. Every unit in the game can be assigned custom values (reals) and you could put all the stats values in there. But if you did this you would have to encode the string values of the items into reals. So it's probably just best to use records and make the array size higher than you think the number of items will ever reach.
@PerAnimus: Go
Use data tables. You can store seemingly any reasonable amount of info in them, though they are much slower than variables, so yea, dynamic storage space.
Have a link to relevant thread
Spawn unit (item), assign item an ID, save that ID in units custom value, save all items data in data table. Data tables are both simple and awesome :D
@DuckyTheDuck: Go
That's cool, I haven't used them before :)
How much slower is much slower?
@DeltaV: Go
I imagine you wouldn't want to use them in any instant arthritics such as AI. Didn't have the need to test it myself since heard several people who should know what they're talking about say that they're slow.
I'm using them to save/recall item data/stuff. If you want to know more I imagine you would have better luck asking in IRC, people like G0A and Ahli were using them way back when I didn't even know they existed.
Thanks for the help guys! I just spent a good 3 hours detailing all the item stats, generating them properly, name banks, blah blah blah.. However theres still a couple things I need help with.
Right now, every time an item "unit" (the Point Defense drone in the pic in OP) is created, an item is now generated as follows: -I have a Record for Armor type items, with all the related stats they might have, as well as a record for Weapons, and "Other" items (but just the armor one is done for now) -I have a Variable referring to that record, in the form of an array of size 1000 (simply because I don't think we can do ArrayLists in sc2mapmaker, and I doubt they'll have 1,000 not-picked-up armor items on the ground at once) -When a new item is generated, it is set to the Record Variable (the array), at the index of CurrNumArmorPiecesOnGround, and CurrNumArmorPiecesOnGround is incremented. -So when all of the stats in the record are filled, the first stat filled is a variable of type Unit, that is set to the item "unit" (point defense drone) that is created when the player kills an enemy and the item first drops.
MY PROBLEM: My trigger to show the item pickup window is when the player enters within a distance of a unit of type itemUnit, and I need to update the info in that window for the triggering unit's item stats. However I don't know how to do this, because afaik, I can't get the index in the array that this item belongs to. I could also assign a value to the unit itself equal to the index number when it is first assigned, but as far as I know, I can't just assign an int value to a specific unit in the map.
So how can I do get the item stats from the triggering unit?
Try Set Unit Custom Value. Through this you can assign any unit up to 64 (slots 0-63) real variables.
@PerAnimus: Go
are you building medieval rpg or sci-fi?
In addition, you can use data tables to assign any type to a unit and getting it with O(1) complexity, by using unit tags as identifiers.