ID:160273
 
After much trouble, I have finaly got it working, but it still seems more tedious than it should be. The code is hand typed from my project that is on a pc not connected to the net, and will not be perfect.

mob/player
Talk(mob/NPC/M)
set src = oview(1)

mob/NPC
Thor
Talk()
..()
if(!usr.LEVEL)//LEVEL holds however many levels the player has earned, or can use in exchange for stat points
usr << "[src] : Come back when you have earned a level"
else
usr.str+=5
usr.LEVEL--
usr.level++ //this hold the players actual level, ex. level == 33 and LEVEL could be 2, when they speak to the NPC their level becomes 35 and their LEVEL = 0

Longbow
//exact same as Thor but gives dex not str
Merlin
//same but with int


There has to be an easier way to implement this, especially with the number of NPCs in a game and the possibility of start combinations (ex usr.dex += 3 usr.str +=2)
Morpholic wrote:
After much trouble, I have finaly got it working, but it still seems more tedious than it should be. The code is hand typed from my project that is on a pc not connected to the net, and will not be perfect.

> 
> mob/player
> Talk(mob/NPC/M)
> set src = oview(1)
>
> mob/NPC
> Thor
> Talk()
> ..()
> if(!usr.LEVEL)//LEVEL holds however many levels the player has earned, or can use in exchange for stat points
> usr << "[src] : Come back when you have earned a level"
> else
> usr.str+=5
> usr.LEVEL--
> usr.level++ //this hold the players actual level, ex. level == 33 and LEVEL could be 2, when they speak to the NPC their level becomes 35 and their LEVEL = 0
>
> Longbow
> //exact same as Thor but gives dex not str
> Merlin
> //same but with int
>

There has to be an easier way to implement this, especially with the number of NPCs in a game and the possibility of start combinations (ex usr.dex += 3 usr.str +=2)

You could store your general code in the parent Talk and leave the stat addition to the individual mob types.

mob/NPC
Talk()
if(!usr.LEVEL)
usr << "[src] : Come back when you have earned a level"
return 0
else
usr.LEVEL--
usr.level++
return 1
Thor
Talk()
if(!..()) return
usr.str+=5

Longbow
//exact same as Thor but gives dex not str
Merlin
//same but with int


Hope this helps.
In response to Green Lime
You could store your general code in the parent Talk and leave the stat addition to the individual mob types.

> mob/NPC
> Talk()
> if(!usr.LEVEL)
> usr << "[src] : Come back when you have earned a level"
> return 0
> else
> usr.LEVEL--
> usr.level++
> return 1
> Thor
> Talk()
> if(!..()) return
> usr.str+=5
>
> Longbow
> //exact same as Thor but gives dex not str
> Merlin
> //same but with int
>

Hope this helps.


I tried working with it, but it still isn't as flexible as it should be. Think of there being 20 TALKable NPCs in a town, and 6 of them are for levels. Thor/Merlin/Longbow/Combo1/Combo2/Combo3. You talk to the level ones(I added Leveler to the NPCs paths who give stats and defined an empty string var called stat) and if you do have a level, then your stats will be incremented by a mixture of stats equal to 5 -- dex + 2 str + 3, str + 5, str + 2 dex + 2 int + 1 etc.
I threw a
if(istype(src,/mob/NPC/Leveler) && !usr.LEVEL)
usr << "[src] : Come back when you have earned a level"

in the Talk() which worked fine, but thought that adding a proc to give the stats would be good, so I scrapped that and tried

mob/NPC
var/stat
Thor
stat = "str"
Talk()
..()
GiveStat(usr,src)

proc/GiveStat(mob/player/P, mob/NPC/N)
if(!usr.LEVEL)
P << "[src] : Come back when you have earned a level"
else
P.[N.stat] += 5//this doesn't work, also is bad implementation if I want +2 dex + 3 str or something
P.LEVEL--
P.level++


So I'm trying to make this flexiable, Talk() is used on every NPC except merchants and monsters and the like, but if the NPC gives stats(defining their type as mob/NPC/Leveler?) increment players stats by whatever stat the NPC gives and deincrement their earned level, increment players level.
In response to Morpholic
mob/NPC
Thor
Talk()
..()
src.GiveStat(usr,str,5)

mob/proc/GiveStat(mob/player/P,mob/var/L,var/amount)
if(!P || !L || !amount) return
if(!P.LEVEL)
P << "[src] : Come back when you have earned a level"
else
P.L += amount
P.LEVEL--
P.level++


Just a few improvements to make it more flexible. If it doesn't work sorry, I'm in the middle of something important but I thought I'd throw in my "5 cents".
In response to Andre-g1
Thanks but gives errors, I'm trying to fix it. P.L - var undefined. Not sure how to get it to target Ps stats but I'll try.
In response to Andre-g1
Hm, I don't think stuff like that works in BYOND that easily. Let me try a work-around.

mob/NPC
Thor
Talk()
..()
src.GiveStat(usr,str,5)

mob/proc/GiveStat(mob/player/P,L as text,var/amount) // note how L became text
if(!P || !L || !amount) return
if(!P.LEVEL)
P << "[src] : Come back when you have earned a level"
else
P.vars[L] = P.vars[L]+amount // look up vars under datum for further information
P.LEVEL--
P.level++
In response to CIB
Thank you! All it needed was quotes around "str" since it was a text string, but it works! Thanks again