Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

tenchimusaki

rpg array

This topic is 6414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, i was wondering how i would go about making an array of weapons or items for an rpg. Then, I wanted to know how to make it appear in the users inventory after they find it or kill a monster for it.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by tenchimusaki

Hey, i was wondering how i would go about making an array of weapons or items for an rpg. Then, I wanted to know how to make it appear in the users inventory after they find it or kill a monster for it.


Wow you ask a huge question. . . and you''re prolly asking it in the wrong forum.

We need to know what language you are using . . . and there are many ways of doing this. . .

But honestly, it sounds more like you''re asking, "how do you program an RPG?" which is a huge question with no particular answer.

I''m sorry i''m being vague but i need more info on your programming knowledge, skillz, etc.

Hope that helps.

DmGoober

Share this post


Link to post
Share on other sites
You mean array as in:

int Weapons[666];

??? In that case, do something like the following:

//--------------------
#define WEAPON_1 0x1
... // Type them all in
#define WEAPON_5 0x16

const unsigned int Weapons[] = { 0x1, 0x2, 0x4, 0x8, 0x16 };
//--------------------

Or you could enum them instead of defining or whatever. Or just make a function:

//--------------------
unsigned int GetWeaponID(unsigned int weaponNum)
{
int ret = 2;

for (int i = 0; i < weaponNum-1; i++)
ret *= 2;

return ret;
}
//--------------------

In any case, it should be OBVIOUS.

THEN, for your player stuct or class:

//----------------------
struct Player
{
int life;
int strength;
... // etc.
unsigned int inventory;
}
//----------------------

And then you say, when he gets WEAPON_3 for example:

//----------------
Player player1;

player1.inventory |= GetWeaponID(5);
//----------------

You have to make the weapon ID''s in powers of two. That way they stay on different bits. If you have more than 16, make it an "unsigned long" instead of an "unsigned int". Then you can have 32. Etc...

That''s how to do this with arrays, if that''s what you meant

------------------------
CRAZY_DUSIK* pCrazyDuSiK;
pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!