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

Solved TFS 1.x

Itutorial

Board Moderator
Staff member
Board Moderator
Joined
Dec 23, 2014
Messages
2,462
Solutions
68
Reaction score
1,129
What is wrong with this script....Player kills monster gains 1 level...

Code:
function onKill(player, target)
    if getCreatureName(target) == "Crystal Wolf" then
    playerSelect = Player(player)
        playerSelect:addExperience(getExpForLevel(playerSelect:getLevel() + 1) - playerSelect:getExperience(), false)
    end
return true
end
 
In TFS 1.x, player and target are now objects instead of creature ids.
Code:
function onKill(player, target)
    if target:getName() == "Crystal Wolf" then
        player:addExperience(getExpForLevel(player:getLevel() + 1) - player:getExperience(), false)
    end
end
 
I think I tried this already, let me check.

Do I need to add anything into the monsters file?
 
Last edited by a moderator:
Try this:
Code:
function onKill(player, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() == "crystal wolf" then
        player:addExperience(getExpForLevel(player:getLevel() + 1) - player:getExperience(), false)
    end
end
 
Not working for me

Do I have to add a <script> code in the monsters xml file?
 
Last edited by a moderator:
Don't you need to register it for players on login?
On phone atm, so I can't give u exact code.

You could add it just to the crystal wolf monster as a script, but you'd need to change the code from onkill to ondeath (would be the smarter way to do it considering your application).
 
I have registered it in login.lua and creaturescript.xml ..... If someone could tell me how to get in the <script> code to monsters I would appreciate it. I have been scripting for a long time now just never did this before.....weird enough.
 
Try this:
Code:
function onKill(player, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() == "crystal wolf" then
        player:addExperience(getExpForLevel(player:getLevel() + 1) - player:getExperience(), false)
    end
end

Return value matters with onKill :p

I have registered it in login.lua and creaturescript.xml ..... If someone could tell me how to get in the <script> code to monsters I would appreciate it. I have been scripting for a long time now just never did this before.....weird enough.

Use the script he posted, add a return true before the last end.
 
Ahh I figured it out.... There is a line in there not supported by global.lua....To make it easier I added it into there...

The function "getExpForLevel" is not in the global... The file I ad pulled the add level portion from had the function made inside of it.

So here it is finalized:

Code:
local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(player, target)
    local targetMonster = player:getTarget()
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() == "crystal wolf" then
        player:addExperience(getExpForLevel(player:getLevel() + 1) - player:getExperience(), false)
    end
    return true
end
 
Back
Top