Sign in to follow this  

Generators

This topic is 4090 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

Hi, I'm new to the forums at new to game development too. The case: I'm actually, creating my server for the game. Which is a mmorpg. Using python with twisted for network. The problem: I need to find a dynamic way to create monsters/items. I need it to be dynamic and independent, because I won't be like: item = Potion() #where Potion would be the item class or monster1 = Zombie() #where Zombie would be a class too I need to fill maps with them, so I need a dynamic way, a function like: spawn(mapname, monstertype, quantity) Any ideas? I'm not a master python programmer yet, so it can take a while until I grasp the explanations ^^. Thanks for your time, DarkSorrow.

Share this post


Link to post
Share on other sites
You might want to start looking at controlling how and where you spawn monsters using a series of probability distributations.

Monster type, location and treasure could all be controlled by a chance of occurance.

gen = LevelGenerator()
gen.AddMonster(type = Zombie, probability = 0.5)
gen.AddMonster(type = Skeleton, probability = 0.4)
gen.AddMonster(type = Dragon, probability = 0.1)
level = gen.SpawnLevel(meanMonsters = 15, varianceMonsters = 4)

Share this post


Link to post
Share on other sites
Quote:
Original post by XXX_Andrew_XXX
You might want to start looking at controlling how and where you spawn monsters using a series of probability distributations.

Monster type, location and treasure could all be controlled by a chance of occurance.

gen = LevelGenerator()
gen.AddMonster(type = Zombie, probability = 0.5)
gen.AddMonster(type = Skeleton, probability = 0.4)
gen.AddMonster(type = Dragon, probability = 0.1)
level = gen.SpawnLevel(meanMonsters = 15, varianceMonsters = 4)


The problem is the (using your example) gen.AddMonster function, I mean, each monster will be a different entity, so when the player attacks a monster it will only damage this monster, instead of all others. I mean, I don't know how I will create instances of them.

Thanks

Share this post


Link to post
Share on other sites
When you type "monster1 = Zombie()", that does create a separate instance. So essentially, that is all you need. The rest is just deciding how to store them all. Inside the spawn() function, you decide which class you want, create an instance as above, and then return it, to be stored in a list or something.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
When you type "monster1 = Zombie()", that does create a separate instance. So essentially, that is all you need. The rest is just deciding how to store them all. Inside the spawn() function, you decide which class you want, create an instance as above, and then return it, to be stored in a list or something.


Ahh, so basically what I need is something like this?

#CODE START
class Monster:
def __init__(self, name=None):
self.name = name

monsterlist = []
for x in range(10):
monster = Monster('Zombie')
monsterlist.append(monster)
#CODE END

Thanks for the info :) just one more question, when the monster is killed the instance need to be deleted, how would I do it?

Thanks once more,
Bye.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kylotan
You remove it from whatever contains it. '5.1 More on Lists'.

PS. Use the code tag for short code snippets and the source tag for longer ones, to make your code easier to read. This is especially important for Python where the indentation matters.


Hmm, thanks for the advice, but I still see a problem.

If I create 10 instances of the monster in a list(all will be called monster), and the third monster in the list dies(still, I'll have not control of which one dies), I need to delete the third list object, BUT, since all the monsters have the same name, using
mylist.index(monster)
since all the instances are called monster, I will get the first one. Sorry If I'm looking so dumb, that's my first attempt into a game, and I'm really confused ^^

Thanks for all,
DarkSorrow.

Share this post


Link to post
Share on other sites
Maybe your spawn function could have some sort of static ID generator/counter with a sister ID variable in your 'monster' class. This way all 'monsters' can be tracked and controlled by an ID instead of their general class name.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xyphyx
Maybe your spawn function could have some sort of static ID generator/counter with a sister ID variable in your 'monster' class. This way all 'monsters' can be tracked and controlled by an ID instead of their general class name.


Hmm, I'll look into this, thanks :)

DarkSorrow.

Share this post


Link to post
Share on other sites
Quote:
Original post by darksorrow
Quote:
Original post by Kylotan
You remove it from whatever contains it. '5.1 More on Lists'.

PS. Use the code tag for short code snippets and the source tag for longer ones, to make your code easier to read. This is especially important for Python where the indentation matters.


Hmm, thanks for the advice, but I still see a problem.

If I create 10 instances of the monster in a list(all will be called monster), and the third monster in the list dies(still, I'll have not control of which one dies), I need to delete the third list object, BUT, since all the monsters have the same name, using
mylist.index(monster)
since all the instances are called monster, I will get the first one. Sorry If I'm looking so dumb, that's my first attempt into a game, and I'm really confused ^^


Look at the method above index() in the link I sent you.

Incidentally, your instances are not called 'monster'. They have no name, as such. In your last code example, 'monster' is just a variable name that refers to an instance temporarily.



Share this post


Link to post
Share on other sites

This topic is 4090 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this