Author Topic: Possible to create a level up system?  (Read 5536 times)

0 Members and 1 Guest are viewing this topic.

Starlock

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Possible to create a level up system?
« on: January 05, 2016, 05:18:37 AM »
For my game, I want to create a leveling system that is a mix of ideas between Zelda 2 and Skyrim. Every time you reach a new level you can choose to raise either health, magic, or stamina with a max level of 10 for each, making a maximum total level of 30.

First off, is such a system possible with the engine. Second, if it is how would I get started creating it?

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Possible to create a level up system?
« Reply #1 on: January 05, 2016, 06:53:24 AM »
Of course it's possible :D. But not an easy task. Some things that you will need:

-Script and draw the associated menu.
-Maybe add an experience bar to the HUD.
-You need to know how the player gets the experience an how much (for instance, killing different enemies could give different experience, or you could give the experience after finishing the missions instead...)
-A script to manage the variables and experience. After leveling you need to apply the changes to the life, stamina and magic, so some changes are needed for the HUD and changing value of some variables.

It's a huge amoung of work and there are lots of details that you should choose, but you can do it for sure!
« Last Edit: January 05, 2016, 06:55:45 AM by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Renkineko
  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Re: Possible to create a level up system?
« Reply #2 on: January 05, 2016, 07:50:13 AM »
I don't think it's that much work.

If you want to give xp to each kill of enemy, you can modify the enemy metatable to add the xp value of enemy to the xp counter of your hero (it can be a formula if easy enemy give you less and less xp to avoid the "easy farm" ^^).

The xp points are attached to the hero (in my opinion), but basically you just replace the heart container by a menu giving you more life/magic/stamina so...

I think the more difficult in here is to determine the experience formula giving you the number of xp point you have to get to reach each level, and maybe indeed the modification of the hud to give the state of the xp, but the code should be a formality :p

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Possible to create a level up system?
« Reply #3 on: January 05, 2016, 08:08:52 AM »
You are right, Renkineko, it's easier than I thought. I was thinking of using a menu to choose the ability you want to increase, but maybe with the dialog box is enough (and quicker since you avoid drawing the menu).

It would be cool to display a coloured number above the hero (or above the killed enemy) showing the experience you got (like "+1" if you get 1 of experience). I would do this to make this system cooler :P.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Possible to create a level up system?
« Reply #4 on: January 05, 2016, 05:20:46 PM »
Yeah it is very possible, the only "hard" thing is indeed the menu and level ups (except if you just want a damage/consuption ration), the rest is fairly doable.
« Last Edit: January 05, 2016, 05:23:27 PM by MetalZelda »

froggy77

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Possible to create a level up system?
« Reply #5 on: January 10, 2016, 12:01:44 PM »
Very interesting subject , at least for me, because I started a little scripting experience points .
(...)
If you want to give xp to each kill of enemy, you can modify the enemy metatable to add the xp value of enemy to the xp counter of your hero (it can be a formula if easy enemy give you less and less xp to avoid the "easy farm" ^^).
(...)
I modified the enemy metatable to add the xp value, but the problem is that the value is common to every enemy. It could be ok for a bonus. I have probably misunderstood.

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Possible to create a level up system?
« Reply #6 on: January 10, 2016, 12:17:09 PM »
I suggest you to make that function to use some variable that is defined on each enemy script, so you can get different experience from each enemy. And instead of decreasing the experience you get, I think that it would be easier to increase the experience bar after each level, so you need more experience each time. The enemies that you find in the new levels/places should be stronger, but they should also give more experience, which would give balance to the system. You will need to test a lot to know how much experience you need to choose for the bar at each level, so that the game leveling does not get too easy or too hard.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

froggy77

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Possible to create a level up system?
« Reply #7 on: January 10, 2016, 03:04:16 PM »
Thank you for answering. If I understand you, I should not use my enemy metatable for this, but only enemy scripts.

I also used the metatable for the hero: I created "hero:get_xp()" and "hero:set_xp(xp, boolean)" functions .(Maybe I will also create "hero:add_xp(xp)" ). It works fine, but I had then added a value in the backup file, otherwise I lost the xp value when I backed up and left the game. It would be easier without metatables for backups and to avoid having a value that is outdated.
I have another question:
Is it better to often read a value inside a metatable or a value from a backup file?


I put this code in the quest_manager.lua, maybe it is not the best file.

Code: (Lua) [Select]
-- Initializes some behavior of our hero.
local function initialize_hero()

  local hero_meta = sol.main.get_metatable("hero")
  -- ZL --  Functions for experience points of our hero
  hero_meta.t_xp = {k_xp = nil}
  function hero_meta:set_xp(v_xp, bool)
local game = self:get_game()
v_xp = v_xp or nil
bool = bool or false -- false means "do not save" with a set_value.
if type(v_xp) == "number" and type(bool) == "boolean" or bool == nil then
hero_meta.t_xp.k_xp = v_xp
if bool == true then
game:set_value("xp", v_xp)
end
else
print("error in set_xp(v_xp, bool)")
end
  end
  function hero_meta:get_xp()
local game = self:get_game()
local xp = game:get_value("xp")
if hero_meta.t_xp.k_xp == nil then
local hero = self:get_map():get_hero()
-- print("xp from file = ", xp)
hero:set_xp(xp) -- xp value is now in the metatable
return xp
else
-- print("xp from metatable = ", hero_meta.t_xp.k_xp)
return hero_meta.t_xp.k_xp
end
  end

end


function quest_manager:initialize_quest()

  -- blablabla
  initialize_hero()
  -- blablabla

end

EDIT: I said "backup file" (for save1.dat, save2.dat or save3.dat), but I should have said "buffer";  e.g "xp = 100" is first read in a "backup file" and then the value is in the buffer of the engine. But with my method, I have xp value in the buffer (with other values found in the saveX.dat) + in the metatable which also used memory: I think my method is stupid, and I should avoid to insert data in the metatable.
« Last Edit: January 10, 2016, 03:36:39 PM by froggy77 »

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Possible to create a level up system?
« Reply #8 on: January 10, 2016, 03:34:29 PM »
@froggy77: What I meant is that you can define a function on the enemy metatable that gets particular info depending on the enemy, or in other words, you can define some variable with different values on each enemy script and the function defined on the metatable uses that info.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Possible to create a level up system?
« Reply #9 on: January 10, 2016, 04:24:10 PM »
You should try to add your local game = self:get_game() in the condition (if bool == true then), before the game:set_value()
I had trouble with this when adding hero voices (value not read or written).

froggy77

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Possible to create a level up system?
« Reply #10 on: January 28, 2016, 10:08:28 PM »
Quote
But with my method, I have xp value in the buffer (with other values found in the saveX.dat) + in the metatable which also used memory: I think my method is stupid, and I should avoid to insert data in the metatable.
For people who will read my previous post in several months, know that I have improved the functions.

See in this topic: HUD: ZL - level (LVL) & experience (XP). The xp system is more complete.