• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Race types

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
Why my scripts of races don't work?
When I advance level...

Code:
function onAdvance(cid, skill, oldLevel, newLevel)
    if(skill == SKILL__EXPERIENCE) then
      return true
    end

    if getPlayerSex(cid) == 5 then
        if ((skill == SKILL__LEVEL) and (newLevel <= 150) and (newLevel > oldLevel)) then
            if getPlayerStorageValue(cid, 96609765040) == newLevel then
            else
              setPlayerStorageValue(cid, 96609765040, newLevel)
              setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+2)
            end
        end
    end
  return true
end

If I'm a human or I'm a dwarf my hp on level 4 is 168. It should not!

Dwarf:
Code:
setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+2)
Human:
Code:
setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+1)

...and the HP is equal :eek: WTF?

Human script:
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
    if(skill == SKILL__EXPERIENCE) then
      return true
    end

    if getPlayerSex(cid) == 0 or getPlayerSex(cid) == 1 then
        if ((skill == SKILL__LEVEL) and (newLevel <= 150) and (newLevel > oldLevel)) then
            if getPlayerStorageValue(cid, 96609765040) == newLevel then
            else
              setPlayerStorageValue(cid, 96609765040, newLevel)
              setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+1)
                if getCreatureMaxMana(cid) > 0 then
                  setCreatureMaxMana(cid, getCreatureMaxMana(cid)+2)
                end
            end
        end
    end
  return true
end

Login.lua:
Code:
    registerCreatureEvent(cid, "Human")
    registerCreatureEvent(cid, "Dwarf")

creaturescripts.xml:
Code:
    <event type="advance" name="Human" event="script" value="human adv.lua"/>
    <event type="advance" name="Dwarf" event="script" value="dwarf adv.lua"/>


The dwarf should have more hitpoints than human!
 
Edit: Now the script work for Human and Dwarf, but for the Elf don't work the function "speed":
Code:
doChangeSpeed(cid, getCreatureBaseSpeed(cid)+3)
Code:
function onAdvance(cid, skill, oldLevel, newLevel)
    if(skill == SKILL__EXPERIENCE) then
      return true
    end

    if ((skill == SKILL__LEVEL) and (newLevel <= 150) and (newLevel > oldLevel)) then
        if getPlayerStorageValue(cid, 96609765040) == newLevel then
        else
          setPlayerStorageValue(cid, 96609765040, newLevel)
            if getPlayerStorageValue(cid, RACE) == HUMAN then -- race human
              setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+1)
                if getCreatureMaxMana(cid) > 0 then -- mages
                  setCreatureMaxMana(cid, getCreatureMaxMana(cid)+2)
                end
            elseif getPlayerStorageValue(cid, RACE) == ELF then -- race elf
              doChangeSpeed(cid, getCreatureBaseSpeed(cid)+3)
            elseif getPlayerStorageValue(cid, RACE) == DWARF then -- race dwarf
              setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+2)
            end
        end
    end
  return true
end
 
Your setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+2) looks good, there is no bug in the code.
You have to check your data/XML/vocations.xml, maybe there is sth like +5 hp per level. Your script adds additional 1 hp per level.
So, level 4 have 150 base + (5 + 1) * 3 extra levels after 1. It's 168 at level 4. Exactly like you said.

Next, doChangeSpeed(cid, getCreatureBaseSpeed(cid)+3) will not work! It's like a CONDITION. Base speed will return to previous value everytime you logout. To avoid that bug, you have to add it in data/creaturescripts/scripts/login.lua to make it executing everytime someone login.
The onLogin script have to check player's level and baseSpeed. Then it should adds extra baseSpeed. Remember, oryginal Tibia's speed is calculated exactly like this:
Code:
baseSpeed = 220 + 2 * (level - 1)

Hmm, players with sex 0 and 1 are elves right? Sex 5 are dwarves? Do you have in sources playerSex 5? Could you try debugging that first code with:
Code:
doCreatureSay(cid, getPlayerSex(cid), 1)
Maybe all players with sex over 2 are downgraded to 0. That's why your script isn't working. As I said, use my debugger to see is that player a correct sex.
 
Last edited:
Back
Top