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

NPC Reset System

Linuss

#use rs232(baud = 19200)
Joined
Apr 17, 2015
Messages
3
Reaction score
6
You can configure whether the price increase to each reset, if you want the level to reset increase and if vc wants life reset along (and as % of current life will be life after reset).


Tested in tfs 1.1 Version to 10.77


Go to data/npc/lib/ make npc_resets.lua :

Code:
--[[Script made 100% by Nogard, Night Wolf and Linus.
   You can feel free to edit anything you want, but don't remove the credits]]

config = {

    minlevel = 150, --- Level inical para resetar
    price = 10000, --- Preço inicial para resetar
    newlevel = 20, --- Level após reset
    priceByReset = 0, --- Preço acrescentado por reset
    percent = 30, ---- Porcentagem da vida/mana que você terá ao resetar (em relação à sua antiga vida total)
    maxresets = 50, ---- Maximo de resets
    levelbyreset = 0 --- Quanto de level vai precisar a mais no próximo reset

}

function getResets(uid)
    resets = getPlayerStorageValue(uid, 378378)
        if resets < 0 then
            resets = 0
        end
    return resets
end

function addReset(cid)
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `description` = ' [Reset: "..description.."]' WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
    return true
end

You can edit stirring here, the script above :
Code:
config = {

    minlevel = 150, --- Level inical para resetar
    price = 10000, --- Preço inicial para resetar
    newlevel = 20, --- Level após reset
    priceByReset = 0, --- Preço acrescentado por reset
    percent = 30, ---- Porcentagem da vida/mana que você terá ao resetar (em relação à sua antiga vida total)
    maxresets = 50, ---- Maximo de resets
    levelbyreset = 0 --- Quanto de level vai precisar a mais no próximo reset

}
go to data/npc/ make reseter.XML :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Reseter" script="reseter.lua">
    <health now="1000" max="1000"/>
    <look type="133" head="95" body="86" legs="86" feet="38" addons="3"/>
        <parameters>
            <parameter key="message_greet" value="Hello |PLAYERNAME|.I've been waiting for you to come.. Say 'reset' or 'quantity'" />
            <parameter key="message_farewell" value="Cya folk." />
            <parameter key="message_walkaway" value="How Rude!" />
        </parameters>
</npc>



go to data/npc/scripts make reseter.lua :

Code:
dofile('data/npc/lib/npc_resets.lua')

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                  npcHandler:onThink()                  end

function creatureSayCallback(cid, type, msg)

    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    local newPrice = config.price + (getResets(cid) * config.priceByReset)
    local newminlevel = config.minlevel + (getResets(cid) * config.levelbyreset)

    if msgcontains(msg, 'reset') then
        if getResets(cid) < config.maxresets then
            npcHandler:say('You want to reset your character? It will cost '..newPrice..' gp\'s!', cid)
            npcHandler.topic[cid] = 1
        else
            npcHandler:say('You already reached the maximum reset level!', cid)
        end
    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
        if player:getLevel() > newminlevel then
            if player:removeMoney(newPrice) then
                addEvent(function()
                    if isPlayer(cid) then
                        addReset(cid)
                    end
                end, 3000)
                local number = getResets(cid)+1
                local msg ="---[Reset: "..number.."]-- You have reseted!  You'll be disconnected in 3 seconds."
                player:popupFYI(msg)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
            else
                npcHandler:say('Its necessary to have at least '..newPrice..' gp\'s for reseting!', cid)
                npcHandler.topic[cid] = 0
            end
        else
            npcHandler:say('The minimum level for reseting is '..newminlevel..'!', cid)
            npcHandler.topic[cid] = 0
        end
    elseif(msgcontains(msg, 'no')) and isInArray({1}, talkState[talkUser]) == TRUE then
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
        npcHandler:say('Ok.', cid)
    elseif msgcontains(msg, 'quantity') then
        npcHandler:say('You have a total of '..getResets(cid)..' reset(s).', cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Img :

sI81vfCpT.png
 
Last edited:
Can’t understand the language, what is the bonus of resetting a character? More max health?
 
Would be nice to have this on @zbizu 's point system.
 
Code:
    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
        if player:getLevel() > newminlevel then
            if player:removeMoney(newPrice) then
                addEvent(function()
                    if isPlayer(cid) then
                        addReset(cid)


Any way of making this able to just reduce the max HP and max MANA of a character?
 
Code:
    elseif msgcontains(msg, 'yes') and npcHandler.topic[cid] == 1 then
        if player:getLevel() > newminlevel then
            if player:removeMoney(newPrice) then
                addEvent(function()
                    if isPlayer(cid) then
                        addReset(cid)


Any way of making this able to just reduce the max HP and max MANA of a character?
Code:
function addReset(cid)
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `description` = ' [Reset: "..description.."]' WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
    return true
end

Check this out =)
 
Could this also change the name of the character to "characters name" + Roman numeral (indicating how many resets a player has made)?
 
Code:
function addReset(cid)
local resetsNum = {I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XIII, XIV, XV, XVI, XVII, XVIII, XIX, XX, XXI, XXII, XXIII, XXIV, XXV, XXVI, XXVII, XXVIII, XXIX, XXX}
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
-------------------------------
    numeral = resetsNum[player:getStorageValue(378378)]
    newName = player:getName().." "..numeral
-------------------------------
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `description` = ' [Reset: "..description.."]' WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `name`="..newName.." WHERE `players`.`id`= ".. playerid .."")
    return true
end
 
Code:
function addReset(cid)
local resetsNum = {I, II, III, IV, V, VI, VII, VIII, IX, X, XI, XII, XIII, XIV, XV, XVI, XVII, XVIII, XIX, XX, XXI, XXII, XXIII, XXIV, XXV, XXVI, XXVII, XXVIII, XXIX, XXX}
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
-------------------------------
    numeral = resetsNum[player:getStorageValue(378378)]
    newName = player:getName().." "..numeral
-------------------------------
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `description` = ' [Reset: "..description.."]' WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `name`="..newName.." WHERE `players`.`id`= ".. playerid .."")
    return true
end



Awsome!

Thank you so much!
-Tys


-edit, I made a mistake!
 
@Itutorial


I was able to test this out and ended up with the following error.

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/npc/lib/otto.lua:38: attempt to concatenate global 'numeral' (a nil value)
stack traceback:
[C]: in function '__concat'
data/npc/lib/otto.lua:38: in function 'addReset'
data/npc/scripts/otto.lua:35: in function <data/npc/scripts/otto.lua:33>


Side notes:
The health and mana adjust to the correct values per reset.
The level does NOT reset down to level 1
The character does not log out after 3 seconds
The character does not receive a new addition to their name.

Any ideas?
Thanks
-tys
 
Code:
function addReset(cid)
--1 - 30--
local resetsNum = {
[1] = "I", [2] = "II", [3] = "III", [4] = "IV", [5] = "V", 
[6] = "VI", [7] = "VII", [8] = "VIII", [9] = "IX", [10] = "X",
[11] = "XI", [12] = "XII", [13] = "XIII", [14] = "XIV", [15] = "XV", 
[16] = "XVI", [17] = "XVII", [18] = "XVIII", [19] = "XIX", [20] = "XX", 
[21] = "XXI", [22] = "XXII", [23] = "XXIII", [24] = "XXIV", [25] = "XXV", 
[26] = "XXVI", [27] = "XXVII", [28] = "XXVIII", [29] = "XXIX",[30] = "XXX"
}
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
    numeral = resetsNum[player:getStorageValue(378378)]
    newName = player:getName().." "..numeral
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `description` = ' [Reset: "..description.."]' WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
    db.query("UPDATE `players` SET `name`="..newName.." WHERE `players`.`id`= ".. playerid .."")
    return true
end
 
Better!
Now the character logs off and level gets reset down to 1.
The name doesn't add the roman numeral yet!

Here is the error:

[Error - mysql_real_query] Query: UPDATE `players` SET `description` = ' [Reset: 1]' WHERE `players`.`id`= 11 Message: Unknown column 'description' in 'field list' [Error - mysql_real_query] Query: UPDATE `players` SET `name`=Herbalista I WHERE `players`.`id`= 11 Message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'I WHERE `players`.`id`= 11' at line 1


Thanks!
-tys
 
Okay, it could be because there is no description table in database.... Try doing this:

data/events/scripts/player.lua
Code:
if thing:isCreature() then
            if thing:isPlayer() then --search for this to find where to put it.
            local resets = player:getStorageValue(378378)
                description = string.format("%s\n[RESETS]: %d", description, resets)
            end
        end

Then for the main code:
Code:
function addReset(cid)
--1 - 30--
local resetsNum = {
[1] = "I", [2] = "II", [3] = "III", [4] = "IV", [5] = "V", 
[6] = "VI", [7] = "VII", [8] = "VIII", [9] = "IX", [10] = "X",
[11] = "XI", [12] = "XII", [13] = "XIII", [14] = "XIV", [15] = "XV", 
[16] = "XVI", [17] = "XVII", [18] = "XVIII", [19] = "XIX", [20] = "XX", 
[21] = "XXI", [22] = "XXII", [23] = "XXIII", [24] = "XXIV", [25] = "XXV", 
[26] = "XXVI", [27] = "XXVII", [28] = "XXVIII", [29] = "XXIX",[30] = "XXX"
}
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
    numeral = resetsNum[player:getStorageValue(378378)]
    newName = player:getName().." "..numeral
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid ..";")
    db.query("UPDATE `players` SET `name` = "..newName.." WHERE `players`.`id`= ".. playerid ..";")
    return true
end
 
If it doesn't work try putting local infront of newName = player:getName().." "..numeral so

Code:
local newName = player:getName().." "..numeral
 
Seems to be getting closer,

I tried the first with no luck and this error:


Test has logged out.
[Error - mysql_real_query] Query: UPDATE `players` SET `name` = Test I WHERE `pl
ayers`.`id`= 4;
Message: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'I WHERE `players
`.`id`= 4' at line 1
Test has logged in.

And this is with the "Local" added.

Woodsmana has logged out.
[Error - mysql_real_query] Query: UPDATE `players` SET `name` = Woodsmana I WHER
E `players`.`id`= 12;
Message: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'I WHERE `players
`.`id`= 12' at line 1
Woodsmana has logged in.

And hints? :p

Thanks,
-tys
 
Sorry for the double post,
This is interesting though, when i tried to reset with another character ive tested with before i cam across this:

Dash has logged in.
Dash has logged out.
[Error - mysql_real_query] Query: UPDATE `players` SET `name` = Dash VII WHERE `
players`.`id`= 14;
Message: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'VII WHERE `playe
rs`.`id`= 14' at line 1
Dash has logged in.

So it seems that something knows what his name should be... just doesn't display it above his head!
 
Code:
if thing:isCreature() then
            if thing:isPlayer() then --search for this to find where to put it.
            local resets = player:getStorageValue(378378)
                description = string.format("%s\n[RESETS]: %d", description, resets)
            end
        end

Then for the main code:
Code:
function addReset(cid)
--1 - 30--
local resetsNum = {
[1] = "I", [2] = "II", [3] = "III", [4] = "IV", [5] = "V",
[6] = "VI", [7] = "VII", [8] = "VIII", [9] = "IX", [10] = "X",
[11] = "XI", [12] = "XII", [13] = "XIII", [14] = "XIV", [15] = "XV",
[16] = "XVI", [17] = "XVII", [18] = "XVIII", [19] = "XIX", [20] = "XX",
[21] = "XXI", [22] = "XXII", [23] = "XXIII", [24] = "XXIV", [25] = "XXV",
[26] = "XXVI", [27] = "XXVII", [28] = "XXVIII", [29] = "XXIX",[30] = "XXX"
}
    player = Player(cid)
    resets = getResets(cid)
    hp = player:getMaxHealth()
    resethp = hp*(config.percent/100)
    player:setMaxHealth(resethp)
    mana = player:getMaxMana()
    resetmana = mana*(config.percent/100)
    player:setMaxMana(resetmana)
    playerid = player:getGuid()
    player:setStorageValue(378378, resets+1)
    numeral = resetsNum[player:getStorageValue(378378)]
    newName = player:getName().." "..numeral
    player:remove()
    description = resets+1
    db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid ..";")
    db.query("UPDATE `players` SET `name` = "..newName.." WHERE `players`.`id`= ".. playerid ..";")
    return true
end

Updated just now
 
Much the same i'm afraid!

Code:
Dash has logged in.
Dash has logged out.
[Error - mysql_real_query] Query: UPDATE `players` SET `name` = Dash VIII WHERE
`players`.`id`= 14;
Message: You have an error in your SQL syntax; check the manual that corresponds
 to your MySQL server version for the right syntax to use near 'VIII WHERE `play
ers`.`id`= 14' at line 1
Dash has logged in.


Just doesn't display in game :(

Thanks :D
 
Alright, try this last one...

Code:
function addReset(cid)
--1 - 30--
local resetsNum = {
[1] = "I", [2] = "II", [3] = "III", [4] = "IV", [5] = "V",
[6] = "VI", [7] = "VII", [8] = "VIII", [9] = "IX", [10] = "X",
[11] = "XI", [12] = "XII", [13] = "XIII", [14] = "XIV", [15] = "XV",
[16] = "XVI", [17] = "XVII", [18] = "XVIII", [19] = "XIX", [20] = "XX",
[21] = "XXI", [22] = "XXII", [23] = "XXIII", [24] = "XXIV", [25] = "XXV",
[26] = "XXVI", [27] = "XXVII", [28] = "XXVIII", [29] = "XXIX",[30] = "XXX"
}
player = Player(cid)
resets = getResets(cid)
hp = player:getMaxHealth()
resethp = hp*(config.percent/100)
player:setMaxHealth(resethp)
mana = player:getMaxMana()
resetmana = mana*(config.percent/100)
player:setMaxMana(resetmana)
playerid = player:getGuid()
player:setStorageValue(378378, resets+1)
numeral = resetsNum[player:getStorageValue(378378)]
newName = player:getName().." "..numeral
player:remove()
description = resets+1
db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid ..";")
db.query("UPDATE `players` SET `name` = '"..newName.."' WHERE `players`.`id`= ".. playerid ..";")
return true
end
 
Back
Top