• 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!

Solved TFS 1.0 creaturescript to set a minimum level

Michael Orsino

Premium User
Premium User
Support Team
Joined
Nov 15, 2007
Messages
864
Solutions
10
Reaction score
451
Location
Western Australia
Okay so TFS 1.0 is still 'missing' a bunch of 'nice' functions that 0.3/4 had (I think?)
What I need to do is get a script working to stop people from falling below a set level.
For example, a character that dies at level 8 would log in as level 7, but then be immediately given level 8 again (with 100% till next level)

This was easy to do on 0.3/4 using the following script:
Code:
function onLogin(cid)

local minimumLevel = 8

    if getPlayerLevel(cid) < minimumLevel then
    doPlayerAddExperience(cid, (getExperienceForLevel(minimumLevel) - getPlayerExperience(cid)))
end
return TRUE
end

I've had a look around, but I couldn't find a way to achieve this in 1.0 yet.
If anyone can think of another way to achieve what I want it would be greatly appreciated =]

Thanks,
Michael
 
Code:
function onLogin(cid)
    local player, minimumLevel = Player(cid), 8
    if player:getLevel() < minimumLevel then
        player:addExperience(getExperienceForLevel(minimumLevel) - player:getExperience())
    end
    return true
end

Don't forget to add the function getExperienceForLevel in your global or compat.lua.
 
Code:
function getExpForLevel(level)
level = level - 1
return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
 
Code:
function getExpForLevel(level)
level = level - 1
return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end


Code:
data/creaturescripts/scripts/noloss.lua:onLogin
data/creaturescripts/scripts/noloss.lua:4: attempt to perform arithmetic on a boolean value
stack traceback:
        [C]: in function '__sub'
        data/creaturescripts/scripts/noloss.lua:4: in function <data/creaturescripts/scripts/noloss.lua:1>

Fml up

up
 
Last edited by a moderator:
Code:
function onLogin(cid)
    local player, minimumLevel = Player(cid), 13
    if player:getLevel() < minimumLevel then
        player:addExperience(getExperienceForLevel(minimumLevel) - player:getExperience())
    end
    return true
end
 
Now I'm confused :)

"data/creaturescripts/scripts/noloss.lua:4: attempt to perform arithmetic on a boolean value" ...
... means somewhere on line 4, something that's supposed to be a number is boolean instead.

It has to be one of these two:
  • getExperienceForLevel(minimumLevel)
  • player:getExperience()
but the names suggest they will both return numbers.


Did you put this code:
Code:
function getExpForLevel(level)
   level = level - 1
   return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

into global.lua ?
 
Back
Top