ID:1847582
 
(See the best response by Turboskill.)
I did it once in past but i cant find it but how do I code it so where say different skills have their own levels and exp to level

EX: fireball is lv1 with 20/100 to next level and lighting bolt is lv 5 with 1324/2800 to lv 6

Best response
Well i'd assume as a really basic example (should be different depending on how you're currently doing it, but distinguishing such a difference is as easy as providing vars for them) you could do:

Skills
var
mob/user
Level = 0
// Tier
// ExpNeeded = Tier*100 + (Level * (Tier*100 + 75))
ExpNeeded
Experience = 0

proc/Give(var/mob/M)
user = M

proc/LevelUp()
Level++

proc/Use()
//other stuff

Experience += rand(7, 15) // i dunno, just an example


Fireball
// Tier = 1
ExpNeeded = 100 + (Level * 300)

LightningBolt
// Tier = 2
ExpNeeded = 200 + (Level * 300)
//Just showing that you can distinguish different behaviour easily


Initially i was going to go all gong ho and maybe map out a general skill system as i started doing this, but alas i'll be cutting things short here. Basically i wouldn't advise to take this code as any kind of slot in, but hopefully you can get the general idea.
ah ok for some reason it thought it was going to have to do with temp vars or local vars or something
ok im baffled here but something is wrong im trying to get it to update the info on xp per the next lv but yet it doesn't for some reason it's staying the same

var
rank=30
mod=1
level=1
reduction=0//don't put at 100 or it will be 0
requirement=c // this is exp needed
experience=0 //current exp


var/a = rank + 25 * level / mod
var/b = a * (reduction / 100)
var/c = a - b

proc
levelup()
if(experience>=a)
experience=0
level++
world<<"YOU LEVELED UP!"
else
return

mob
verb

expgiver()
levelup()
experience+=20
levelup()

leveltest2()
world<<"You need [round(requirement)] to level"
world<<"You have [experience] xp"
world<<"the level is [level]"

leveltest()
world<<"your reduction is [round(b)]"
world<<"before[round(rank+25*level/mod)]"
world<<"Strength requirement: [round(requirement)]"


it will keep reporting the xp needed is 55 even though the level is changing whcih is weird how do i fix it?
Why are you making
var
rank=30
mod=1
level=1
reduction=0//don't put at 100 or it will be 0
requirement=c // this is exp needed
experience=0 //current exp


and

proc
levelup()
if(experience>=a)
experience=0
level++
world<<"YOU LEVELED UP!"
else
return

world variables and proc?

Stick with the Skills datum Turbo has shown.
why are you commenting if your not here to help?
In response to Mastergamerx
I did. I helped. Don't use world /var and /proc's for things that should be handled per the /datum or the skill /obj itself.

"b" will always equal 0.
b = a * (reduction / 100)

b = (rank + 25 * level / mod) * (0 / 100)

So, let's take an example.
a = rank + 25 * level / mod
b = a * (reduction / 100)
c = a - b

a = 30 + 25 * 1 / 1
a = 55

b = 55 * (0 / 100)
b = 0

c = 55 - 0
c = 55


But like I said, you should be handling it like Turboskill has shown.
yes but the problem is the experience needed is not increasing aka the requirement var it just keeps saying 55 even though the level has increased
Ok so i've been kinda busy, but yeah the issue would be that rather than look to get the value of the requirement from the var directly, you'll want to instead use a 'get' proc. You see, variable a will continue to hold the value that was the result of the formula that you assigned to it, at the time that you assigned it; It won't automatically update because the value of a variable used within the formula changes**.

So what you'd want to do for your above code would be something like:
proc/getRequirement()
return <formula here> // you make this decision and figure it out, this isn't a spoon feeding

//and also
proc/checkExp()
if(experience >= getRequirement())
//do level up stuff
//do experience reset/whatever stuff
world << "Levelled Up!"

verb/test()
world << "You need [getRequirement()]" exp to level up"


An Alternative way to do this btw, is via the use of defines:
#define a  (rank + 25 * level / mod)
#define b a * (reduction / 100)
#define requirement a - b

Defining those as macros rather than variables would give the desired results (without need for other changes), because of the way macros work, being that in all places where the aliases/identifiers (i.e. 'a', 'b', or 'requirement'*) occur, at run time the names are treated to mean what you defined it as on the right side of the macro. Again this is done at run time, as such it gives the same effect as fetching a value by using a proc to return the result of a formula.
//     | name/alias | meaning
#define MacroExample world << "this is an example of a macro"

proc/MacroTest()
MacroExample // result is the "this is an example of a macro" output to the world

sigh this is just confusing me more and more i look at it so ill try to explain this best i can. I want the experience required per level to be based on "rank + 25 * level / mod" and to apply any reductions to the overall xp if there is any.
so EX:if the exp was 500 to level with 0% reductions vs say 400 xp to level with 5% reductions or w/e. so im making this quirky lil verb test to make sure everything is working accordingly
so the problem im having atm is the getxp proc will only return the base formula and not the reduction included which i need it to do
It's pretty simple:

You need to set the requirement every time you level up. You're currently not doing that. All you're doing is setting a variable to a formula, which is evaluated at run-time. Variables are evaluated once, unless you set them to something else.
so how do i set the req everytime
Well, it seems like you're just using code without having any idea what it actually does.

Your issue stems from id:1843282. You took a piece of code Goober gave you, and just added onto it. Don't just shove it into the editor.

You want a/b/c to be part of a bigger piece of code (probably part of a mob, obj, or datum) - not variables defined globally, the same with rank, level, reduction, etc. Use them in conjunction with procs and stuff.

mob
proc
levelUp()
if(reqForNextLevel>exp)
level++
exp = reqforNextLevel-exp
reqForNextLevel += 1000


I'd suggest reading the guide:

http://www.byond.com/docs/guide/

Here's also a really simple, but ancient, demo you can look at:

http://www.byond.com/developer/Rcet/LevelDemo