Python Forum
Extremely Simple RPG Character File Maker - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Extremely Simple RPG Character File Maker (/thread-7426.html)



Extremely Simple RPG Character File Maker - ashtons - Jan-09-2018

Hello! I made a simple RPG character file creator.

It asks for a name and 6 attributes (Strength, Agility, Intelligence, Perception, Endurance, and Charisma). Then, it calculates some large-scale stats and puts them all into a basic text file with the extension .chr (First person to figure out where I got that extension from gets a cookie.)

It still needs some work, though. I feel like the total amount of attribute points should be 30 instead of 45, and it would probably be better to export the character to JSON instead of a text file with a rarely used file extension. Then again, what would you expect from a 17 year old with little experience? Oh well.

# Ask the user for their name.
name = input("What is your name? ")

# Here is an array of attributes. 0 is Strength, 1 is Agility, 2 is Intelligence, 3 is Perception, 4 is Endurance, and 5 is Charisma
attributes = [0,1,2,3,4,5]

# Here is a variable that an if statement will change to true if the items in the above array add up to 45.
goodSum = False

while goodSum == False:
  # Strength, a measurement of physical power.
  attributes[0] = int(input("How strong are you from 1 to 10? "))
  # Agility, a measurement of speed and reflexes.
  attributes[1] = int(input("How fast are you from 1 to 10? "))
  # Intelligence, a measurement of thinking and problem solving skills.
  attributes[2] = int(input("How smart are you from 1 to 10? "))
  # Perception, a measurement of how easily you can detect something.
  attributes[3] = int(input("How perceptive are you from 1 to 10? "))
  # Endurance, a measurement of physical tolerance.
  attributes[4] = int(input("How physically tolerant are you from 1 to 10? "))
  # Charisma, a measurement of persuasiveness.
  attributes[5] = int(input("How suave are you from 1 to 10? "))
  if attributes[0] + attributes[1] + attributes[2] + attributes[3] + attributes[4] + attributes[5] == 45:
    print("Those attributes seem good.")
    goodSum = True
  else:
    print("Your attributes don't add up to 45! Try again.\n")

# Maximum Health for this character.
maxHealth = attributes[0] * 75

# Maximum weight this character can carry, in kg
carryWeight = attributes[0] * 25

# Maximum Stamina for this character.
maxStamina = attributes[4] * 40

# How much damage is taken off any attack done to this character.
resistance = attributes[4] * 5

# How far away enemies and items are detected by this character, in meters.
senseDistance = attributes[3] * 5

# How fast the character walks, in meters per second.
walkSpeed = attributes[1] / 2

# How fast the character runs, in meters per second.
runSpeed = attributes[1] * 2

# A percentage that all experience this character gains is multiplied by.
xpGainMod = attributes[2] * 10 / 100

# A percentage that all prices for this character are reduced by.
discount = attributes[5] * 5 / 100

# List off all of the extra stats that were just calculated!

# First, the strength-based stuff.
print(name + " can have a maximum of " + str(maxHealth) + " health points.")
print(name + " can carry up to " + str(carryWeight) + " kilograms of stuff.")

# Second, the endurance-based stuff.
print(name + " can have a maximum of " + str(maxStamina) + " stamina points.")
print(name + " can resist " + str(resistance) + " HP of damage by default.")

# Third, the perception-based thing.
print(name + " can detect enemies and items up to " + str(senseDistance) + " meters away.")

# Fourth, the agility-based stuff.
print(name + " can walk at a rate of " + str(walkSpeed) + " meters per second.")
print(name + " can run at a rate of " + str(runSpeed) + " meters per second.")

# Fifth, the intelligence-based thing.
print(name + " gains Experience " + str(xpGainMod * 100) + "% faster than most.")

# Sixth, the charisma-based, thing.
print(name + " gets a " + str(discount * 100) + "% discount on all prices.")

print("We're now going to save your character to a file.")

# Opens (usually also creating) a file that is the character's name plus the .chr extension in write mode
f = open(name + '.chr', 'w')

# Dumps the attributes the player chose, each on a new line.
f.write('str:' + str(attributes[0]) + '\n')
f.write('agi:' + str(attributes[1]) + '\n')
f.write('int:' + str(attributes[2]) + '\n')
f.write('per:' + str(attributes[3]) + '\n')
f.write('end:' + str(attributes[4]) + '\n')
f.write('cha:' + str(attributes[5]) + '\n')

# mHP is Max HP. cHP is Current HP. The character was just made, so they're the same.
f.write('mHP:' + str(maxHealth) + '\n')
f.write('cHP:' + str(maxHealth) + '\n')

# mCW is Max Carry Weight. uCW is Used Carry Weight. The character doesn't have any items right now, so uCW is 0.
f.write('mCW:' + str(carryWeight) + '\n')
f.write('uCW:0\n')

# mSP is Max Stamina. cSP is Current Stamina. They're the same right now, just like with mHP and cHP
f.write('mSP:' + str(maxStamina) + '\n')
f.write('cSP:' + str(maxStamina) + '\n')
f.write('res:' + str(resistance) + '\n')
f.write('sDst:' + str(senseDistance) + '\n')
f.write('wSpd:' + str(walkSpeed) + '\n')
f.write('rSpd:' + str(runSpeed) + '\n')
f.write('xp%:' + str(xpGainMod) + '\n')

# pd% is the discount (think of it as "Price Drop %")
f.write('pd%:' + str(discount) + '\n')

# Starts the inventory section of the character file. You have nothing, so its empty.
f.write('inv:\n')

# Closes the file
f.close()

print("Character file saved!")

P.S. If you use my code, I'm holding you up to the MIT License.