• 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 Resetter TFS 1.0

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,051
Solutions
2
Reaction score
260
Location
United States
Hello and im trying to fix this npc, i want to add it to my server incase players get bored and it might be something cool to have.

data/npc/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>

data/npc/scripts/reseter.lua:
Code:
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)
config = {
minlevel = 80, --- Level to reset
price = 1000000, --- Start price for reset
newlevel = 8, --- Level after reset
priceByReset = 1500000, --- Added price for reset
percent = 15, ---- Percentage of life / mana you will have to reset (in relation to its former full life)
maxresets = 2, ---- Maximum of resets
levelbyreset = 100 --- As the level will need more in the next reset


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:remove()
db.query("UPDATE `players` SET `resets`="..resets.. + 1",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
db.query("UPDATE `players` SET `level`="..config.newlevel..",`experience`= 0 WHERE `players`.`id`= ".. playerid .."")
    return true
end


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())

To configure this part of the npc:
Code:
config = {
minlevel = 80, --- Level to reset
price = 1000000, --- Start price for reset
newlevel = 8, --- Level after reset
priceByReset = 1500000, --- Added price for reset
percent = 15, ---- Percentage of life / mana you will have to reset (in relation to its former full life)
maxresets = 2, ---- Maximum of resets
levelbyreset = 100 --- As the level will need more in the next reset
 
Code:
    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

    local c = {
        minlevel = 80, --- Level to reset
        price = 1000000, --- Start price for reset
        newlevel = 8, --- Level after reset
        priceByReset = 1500000, --- Added price for reset
        percent = 15, ---- Percentage of life / mana you will have to reset (in relation to its former full life)
        maxresets = 2, ---- Maximum of resets
        levelbyreset = 100 --- As the level will need more in the next reset
    }

    function creatureSayCallback(cid, type, msg)

        if not npcHandler:isFocused(cid) then
            return false
        end
   
        local player = Player(cid)
   
        local function addReset(pid)
            if isPlayer(pid) then
                local player = Player(pid)
                player:setMaxHealth( player:getMaxHealth() * (c.percent / 100) )
                player:setMaxMana( player:getMaxMana() * (c.percent / 100) )
                player:remove()
                db.query("UPDATE `players` SET `resets`=" .. (getResets(pid) + 1) .. ",`experience`= 0 WHERE `players`.`id`= " .. pid .. ";")
                db.query("UPDATE `players` SET `level`=" .. c.newlevel .. ",`experience`= 0 WHERE `players`.`id`= " .. pid .. ";")
            end
        end


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


        if msgcontains(msg, 'reset') then
            if getResets(cid) < c.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(addReset, 3000, player:getId())
                    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)
                    return true
                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]) 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())
 
Last edited:
small problem : s

EqiX8P7.png
 
small problem : s

EqiX8P7.png
Exactly, it was in your script so i just added it in, in the future be more clear about where you got the script especially if you just copied and pasted from somewhere else.

On a final note, how can all you people who host servers not know 1 oz of programming is beyond me... this is the real problem here.
 
Exactly, it was in your script so i just added it in, in the future be more clear about where you got the script especially if you just copied and pasted from somewhere else.

On a final note, how can all you people who host servers not know 1 oz of programming is beyond me... this is the real problem here.
i am still learning ^^ i know alot about servers, im just getting new to scripting and programming.
 
Found this function at the same place I found the script your using:
https://otland.net/threads/i-need-help-with-reset-system-7-92.212800/

This is how the function getReset looks like in the link. (Converted to 1.X)
Code:
function getResets(cid)
   local player = Player(cid)
   resets = player:getStoraveValue(378378)
     if resets < 0 then
     resets = 0
  end
   return resets
end
 
Back
Top