Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # you made a couple of different choices to select stats. but how to work from them?
- # So your NPC had a stat choice like "Bad (10,10,10,10,10,8)" or random
- # first of all lets make it a bit more readable/handy
- # choices are:
- CHOICES = ['Bad', "Medium", "Random"]
- # lets make a second dictionary with what that means
- STAT_CHOICES = {
- "Bad": [10, 10, 10, 10, 10, 8],
- "Medium": [14, 12, 12, 10, 10, 8],
- "Random": True,
- }
- # as you can see stats for not random is pretty straight forward, it list 6 stats in order
- # now how to assign them? Lets work from an npc thats been created
- import json
- with open("NPC/location/name.json", 'r') as f:
- npc = json.loads(f.read())
- stats = STAT_CHOICES[npc['ARRAY']]
- # what this does is load the stats from STAT_CHOICES from the value! of npc['ARRAY']
- # meaning npc['ARRAY'] returns 'Bad'
- # so the actual lookup is STAT_CHOICES['Bad']
- # so returns: [10, 10, 10, 10, 10, 8]
- # now you can come up with a way to assign the stats to an npc (hint you can also look at class
- # remember lists and index? lets put stats to a npc
- npc['STATS'] = {
- "strength": stats[0],
- "dexterity": stats[3],
- "constitution": stats[4],
- }
- # however this leaves us with Random. Those dont have stats, so how do we do this?
- # conditions come in handy here
- # before you start 'assigning' stats, it might be a good idea to check what you are dealing with
- # so lets go back to stats
- def get_random_stats():
- import random
- # come up with a way to get 6 random stats.
- # random.randint(number, higher_number) returns a value between number and higher number
- if npc['ARRAY'] == "Random":
- stats = get_random_stats()
- else:
- stats = STAT_CHOICES[npc['ARRAY']]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement