Topic:   Simple New Inventory   (Read 10386 times)


0 Members and 1 Guest are viewing this topic.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Simple New Inventory
« on: June 11, 2008, 05:31:36 PM »
I posted this in another topic, but I'm posting here so that everyone can find it easier. This is a simple inventory I came up with that stores item properties in arrays.

This is how to set the properties of weapons and armors. The first parameter in the array is the item's name, the second parameter is the Attack plus it gives in combat, and the third parameter is the Defence plus it gives in combat.
Code: [Select]
Weapon1Stats$ = "RustyDagger 10 0"
Weapon2Stats$ = "BattleAxe 14 0"
Weapon3Stats$ = "LongSword 20 0"

Armor1Stats$ = "LeatherVest 0 8"
Armor2Stats$ = "ChainMail 0 12"
Armor3Stats$ = "SpikedCuiras 3 17"

How to set the player's weapon/armor properties to those of another item: (in other words, how to equip an item ;) )
Code: [Select]
PlayerWeaponStats$ = Weapon1Stats$
PlayerArmorStats$ = Armor1Stats$

How to reference the properties of an item:
Code: [Select]
PlayerWeaponName$ = WORD$ PlayerWeaponStats$ 1
PlayerArmorName$ = WORD$ PlayerArmorStats$ 1

WeaponAttackPlus$ = WORD$ PlayerWeaponStats$ 2
ArmorAttackPlus$ = WORD$ PlayerArmorStats$ 2
WeaponAttackPlus = VAL WeaponAttackPlus$
ArmorAttackPlus = VAL ArmorAttackPlus$
WeaponDefencePlus$ = WORD$ PlayerWeaponStats$ 3
ArmorDefencePlus$ = WORD$ PlayerArmorStats$ 3
WeaponDefencePlus = VAL WeaponDefencePlus$
ArmorDefencePlus = VAL ArmorDefencePlus$

Attack = Attack + WeaponAttackPlus
Attack = Attack + ArmorAttackPlus
Defence = Defence + WeaponDefencePlus
Defence = Defence + ArmorDefencePlus

It's fairly straight forward. You shouldn't have to edit any of the code to use it, so you don't even have to understand it. All you have to do is set the values of "Weapon1Stats" "Weapon2Stats" and so on. If you do understand it however, you could add extra parameters to the arrays such as attribute bonuses or durability. Or even the item's sell price. :) It's easy to mod.
I survived the spammage of 2007

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Simple New Inventory
« Reply #1 on: June 11, 2008, 05:58:00 PM »
How will you make it so that you can have weapons with more than one word in their name like "Dragon's Blade" instead of Dragon'sBlade.
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Simple New Inventory
« Reply #2 on: June 12, 2008, 06:53:19 AM »
It's kinda tricky. I may just use another variable, but I'll have a think about it. Perhaps a parameter could govern the amount of words in the item's name, then you could add more parameters afterwards equal to the first parameter's value. Somewhat like this:

Code: [Select]
blankspace$ = ""

Weapon1Stats$ = "10 0 2 Rusty Dagger"

PlayerWeaponStats$ = Weapon1Stats$

WeaponName$ = WORD$ PlayerWeaponStats$ 4
ItemNameWords$ = WORD$ PlayerWeaponStats$ 3
ItemNameWords = VAL ItemNameWords$
ExtraWordNumber = 4

REPEAT ItemNameWords
 Â IF ItemNameWords > 1 THEN
 Â   ExtraWordNumber = ExtraWordNumber + 1
 Â   ExtraWord$ = WORD$ PlayerWeaponStats$ ExtraWordNumber
 Â   WeaponName$ = WeaponName$ + BlankSpace$
 Â   WeaponName$ = WeaponName$ + ExtraWord$
 Â END IF
END REPEAT
I think that should do it, though it hasn't been tested.
« Last Edit: June 12, 2008, 07:39:55 AM by Silverwind »
I survived the spammage of 2007

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Simple New Inventory
« Reply #3 on: June 12, 2008, 07:56:09 AM »
Did you try making all the words the same length then use the MID command? Thats how I did it.
P.S. It won't work because you are starting on word 5, you would need to make it start on word 4 by making the variable equal to three. It seems like an awful lot of work to go to just to get the name.
« Last Edit: June 12, 2008, 09:01:48 AM by Tireas_Dragon »
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: Simple New Inventory
« Reply #4 on: June 12, 2008, 12:51:57 PM »
Someone mentioned before about making a NTHFIELD command or something like that. I think REALbasic has that. I'll look into that more.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Simple New Inventory
« Reply #5 on: June 12, 2008, 02:04:53 PM »
Quote
P.S. It won't work because you are starting on word 5
No I'm not. ;)

Quote
Someone mentioned before about making a NTHFIELD command or something like that. I think REALbasic has that. I'll look into that more.
That would be cool. WORD$ is a very powerful command, but NTHFIELD is even better. :)
I survived the spammage of 2007

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Simple New Inventory
« Reply #6 on: June 12, 2008, 02:28:04 PM »
What does NTHFIELD do?
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Simple New Inventory
« Reply #7 on: June 12, 2008, 03:04:34 PM »
Quote
NTHFIELD$(string, separator, fieldnum) - Returns the field value from the source that precedes the fieldNumber occurrence of the separator in the source.

Two more great SC commands 4.0 could use are

Quote
REPLACE$(sourcestring, oldstring, newstring) - Replaces the first occurrence of oldString in sourceString with newString.

REPLACEALL$(sourcestring, oldstring, newstring) - Replaces all occurrences of oldString in sourceString with newString.
I survived the spammage of 2007

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Simple New Inventory
« Reply #8 on: June 12, 2008, 03:29:18 PM »
So its like the VAL MID command in a long string?
« Last Edit: June 12, 2008, 05:15:15 PM by Tireas_Dragon »
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Simple New Inventory
« Reply #9 on: June 13, 2008, 10:27:44 AM »
NTHFIELD$ retreives a field in a string

let inventory$="sword, gun, knife"

the fields are seperated by the comma, you can use anything as a seperator

this will let x$= the third field which is a knife, the comma in the quotes is how  it determines the seperator

let x$=NTHFIELD$(inventory$, ",", 3)

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Simple New Inventory
« Reply #10 on: June 13, 2008, 11:14:06 AM »
so instead of being forced to use spaces we can use anything NICE
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.