exp script discussion

Hey guys, I’m currently working on an exp script for a game to count exp and to add levels to the characters. Here is what I have so far and it works, but with a slight few issues for future reference.

import GameLogic as gl

cont = gl.getCurrentController()
me = cont.owner

expk = cont.sensors[“expcon”]
mes = cont.actuators[“lvlup.mes”]
lvl = cont.actuators[“lvladd.act”]

if expk.isTriggered():
if me[‘exp’]>=10 and me[‘level’]<=1:
gl.addActiveActuator(mes, 1)
gl.addActiveActuator(lvl, 1)

expk is an Always sensor put on true pulse so it’s constantly scanning. When the character is given 10 exp (from 0) and is currently equal to or lower then lvl 1, then he lvl’s up, very simple script, but now here’s the issue

What about lvls 2-99. Theoretically I could just an ‘if statement’ for every level… but that would be to much work for one code. Then I thought, just make a dictionary array, but then when ‘level’ is checked it’s going to be less then 99, so it’ll just go up all the way to that level, and thats not good.

My brain is on overload right now inbetween working at my job and working on this script. Just wondering if someone had a good idea on how to resolve this and I bet I’m going to end up hitting my head in the end. Thanks guys

(I’m also still learning python with Blender GE)

Use an equation. For ConceptRPG I awarded experience based on the player’s and monster’s level. It was similar to this:

exp = (monsterLevel/playerLevel)*expFromMonster

We released the source for ConceptRPG here if you want to dig through it:
http://blenderartists.org/forum/showthread.php?t=158549

and i would implement a list, as you said

for example:

lvlexp = 10,20,30,50,80,100,200,300,500 and so on.

of course you will have to write the 99 lvls by hand,
so if you can come up with a formula, you should use it instead.

a simple and incomplete example:


def lvlexp(currlvl):
#the int is unneeded, but to be sure
  lvlexp = int((currlvl+1)*(20+currlvl))

def lvlup():
   char_lvl += 1
   attribute_points += 1
   skill_points += 5
   lvlexp(currlvl)

#whenever the player lvls you can recalculate the lvlexp for the next lvl.

if exp == lvlexp:
   lvlup()

Thanks guys, I’ve been hard at work on other things such as the attack system and how you receive damage, so it’s great that I got a few post here to take a load off. As far as the formula goes, that’s great and all and I’ll definitely take it into consideration.

As far as ranging the exp like that, it’s a good idea and I thought about that myself as well, but I like knowing how much exp to set, I could probably use a sample code to get the exp sets out and I could just use them. But what I was thinking of doing instead now, is to just have the game send a message at the end of the battle so it will activate the script.

hmm I have an idea, maybe something like this when activated by the script

If monster.exp > 0

for i in moster.exp(0, +1)
  me.exp += 1
  if me.exp == lvlexp[:] #I need to study on arrays again, I completely forgot how to do them
    me.level += 1

moster.exp is all the exp from killed monsters added into one variable so when you add it to me.exp.
The for statement will loop and add 1 exp to me.exp per loop of the monster.exp and if it equals the amounted exp for level up, it’ll add the level.

i put together a small levelling example, since i will need it soon anyways.

its pretty selfexplanatory, so i just uploaded the blend and there you go :smiley:

have fun, if you have any questions just ask :slight_smile:

greetings
manarius

Attachments

levelling.blend (312 KB)

Alright, I see what you did and I guess I have to concur with you for that being a better way going about it. This code I wrote is basically the same, so I hope you don’t mind that I use the same method. But I did change up the way the lvlexp function calculates the next level.

import GameLogic as gl

cont = gl.getCurrentController()
me   = cont.owner

def lvlexp(currlvl):
    me["lvlexp"] = int((me["lvlexp"] * 1.5) + (currlvl * 8))
    
    
def lvlup():
    me["level"] += 1
    lvlexp(me["level"])

    
if me["exp"] &gt;= me["lvlexp"]:
    lvlup()

I made the lvlexp definition the way it is, because I found that it will make the gaps between levels wider, making it seem to take longer to gain lvls.

I’m going to use a message sensor instead of detecting when exp changes, mainly because I’m making a turned based rpg and don’t want them to lvl until the end of the battle.

I’ll keep some updates flowing and a possible .blend as soon as I’m finished linking everything.