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

[NPC] Buff Problem [1.0]

Eldin

Eldin Projects
Joined
Jun 12, 2008
Messages
1,334
Reaction score
615
Location
Sweden
NPC Problem:

This NPC should be giving a person a "Buff" if they are the right Vocation for the right amount of Cash. It shows no error but simply wont proceed. I tryed for hours and edited, changed etc to find the NPC giving a distance buff to simply not giving anything at all again. It stopped answer when I was supposed to say "Yes" and get the Buff. I tryed to go back to where it actually worked with only Distance Buff, but that didn't work either, therefor, I posted the original script to see if ANYONE may see any error at all that could cause this. Important for my Elfs to get those Buffs aswell as Humans getting others. I will have to split the script into 2 parts as its too big, but its THE SAME SCRIPT IN ONE.


Even found the base script:
http://otland.net/threads/buffer.131246/
Also note that I got my "Human Edition" to work perfectly, something happend during my Elf Edit.

Elathriel.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Elathriel" script="data/npc/scripts/AbDendrielBuffer.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="64" head="69" body="0" legs="69" feet="0" addons="3"/>

    <parameters>
        <parameter key="message_greet" value="{Nature} is Power!" />
        <parameter key="module_keywords" value="1" />
        <parameter key="keywords" value="nature" />
        <parameter key="keyword_reply1" value="As an Elf, you have the power of nature within you. I can show you how to use it, ask me for {help} any time." />
    </parameters>
</npc>[/PHP]

AbDendrielBuffer.lua
[PHP]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

-- Buff Config beginning --

-- configs
local config = {
    storage = 77700,
    value = 1,
}
money = 500
invisibleseconds = 3600
magicshieldseconds = 3600
regeseconds = 3600
speedseconds = 3600
skillsseconds = 3600
skillsupgrade = {}
skillsupgrade['distance'] = 15
skillsupgrade['ml'] = 10
-- end configs

-- Configs of buffs

local conditionMagic = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionMagic, CONDITION_PARAM_BUFF, true)
setConditionParam(conditionMagic, CONDITION_PARAM_TICKS, skillsseconds * 1000)
setConditionParam(conditionMagic, CONDITION_PARAM_STAT_MAGICLEVEL, skillsupgrade['ml'])

local combatInvisible = createConditionObject(CONDITION_INVISIBLE)
setConditionParam(combatInvisible, CONDITION_PARAM_BUFF, true)
setConditionParam(combatInvisible, CONDITION_PARAM_TICKS, invisibleseconds*1000)

local conditionDistance = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionDistance, CONDITION_PARAM_BUFF, true)
setConditionParam(conditionDistance, CONDITION_PARAM_TICKS, skillsseconds*1000)
setConditionParam(conditionDistance, CONDITION_PARAM_SKILL_DISTANCE, skillsupgrade['distance'])

local combatUtamo = createConditionObject(CONDITION_MANASHIELD)
setConditionParam(combatUtamo, CONDITION_PARAM_BUFF, true)
setConditionParam(combatUtamo, CONDITION_PARAM_TICKS, magicshieldseconds*1000)

local conditionRege = createConditionObject(CONDITION_REGENERATION)
setConditionParam(conditionRege, CONDITION_PARAM_BUFF, true)
setConditionParam(conditionRege, CONDITION_PARAM_TICKS, regeseconds*1000)
setConditionParam(conditionRege, CONDITION_PARAM_HEALTHGAIN, 5)
setConditionParam(conditionRege, CONDITION_PARAM_HEALTHTICKS, 2000)

local conditionspeed = createConditionObject(CONDITION_HASTE)
setConditionParam(conditionspeed, CONDITION_PARAM_BUFF, true)
setConditionParam(conditionspeed, CONDITION_PARAM_TICKS, speedseconds*1000)
setConditionFormula(conditionspeed, 1.0, -86, 1.0, -86)
 
CONTINUE, SAME SCRIPT

Code:
-- Configs of buffs

function magicl(cid, message, keywords, parameters, node)
    local guid = getPlayerGUID(cid)

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

    if(getPlayerVocation(cid) == 7) == true and getPlayerStorageValue(cid, config.storage) == -1 then
        if getPlayerMoney(cid) >= 500 then
            doPlayerRemoveMoney(cid, 500)
            doAddCondition(cid, conditionMagic)
            npcHandler:say('Well done, your Magic level has increased by 10 for 1 Hour.', cid)
            setPlayerStorageValue(cid, config.storage, config.value)    
            addEvent(db.executeQuery, skillsseconds * 1000, "UPDATE `player_storage` SET `key` = " .. config.storage .. ", `value` = -1 WHERE `player_id` = " .. guid .. " LIMIT 1;")
        else
            npcHandler:say('Im sorry, I forgot to tell you that I need 500 Gold to help you. Its cheap afterall.', cid)
        end
    else
        npcHandler:say('Good choise, but only Elf Aracanists are mentaly strong for this.', cid)
    end
end

function invisible(cid, message, keywords, parameters, node)
    local guid = getPlayerGUID(cid)

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

    if(getPlayerVocation(cid) == 6) == true then elseif(getPlayerVocation(cid) == 7) == true and getPlayerStorageValue(cid, config.storage) == -1 then
        if getPlayerMoney(cid) >= 500 then
            doPlayerRemoveMoney(cid, 500)
            npcHandler:say('Well done, you will stay invisible for 1 Hour.', cid)
            doAddCondition(cid, combatInvisible)
            setPlayerStorageValue(cid, config.storage, config.value)    
            addEvent(db.executeQuery, invisibleseconds * 1000, "UPDATE `player_storage` SET `key` = " .. config.storage .. ", `value` = -1 WHERE `player_id` = " .. guid .. " LIMIT 1;")
        else
            npcHandler:say('Im sorry, I forgot to tell you that I need 500 Gold to help you. My supplies are not cheap.', cid)
        end
    else
        npcHandler:say('You are too weak.', cid)
    end
end

function distance(cid, message, keywords, parameters, node)
    local guid = getPlayerGUID(cid)

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

    if(getPlayerVocation(cid) == 6) == true then elseif(getPlayerVocation(cid) == 7) == true and getPlayerStorageValue(cid, config.storage) == -1 then
        if getPlayerMoney(cid) >= 500 then
            doPlayerRemoveMoney(cid, 500)
                doAddCondition(cid, conditionDistance)
            npcHandler:say('Well done, your Distance fighting has increased by 10 for 1 Hour.', cid)
            setPlayerStorageValue(cid, config.storage, config.value)    
            addEvent(db.executeQuery, skillsseconds * 1000, "UPDATE `player_storage` SET `key` = " .. config.storage .. ", `value` = -1 WHERE `player_id` = " .. guid .. " LIMIT 1;")
        else
            npcHandler:say('Im sorry, I forgot to tell you that I need 500 Gold to help you. My supplies are not cheap.', cid)
        end
    else
        npcHandler:say('You are too weak.', cid)
    end
end

function magicshield(cid, message, keywords, parameters, node)
    local guid = getPlayerGUID(cid)

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

    if(getPlayerVocation(cid) == 7) == true and getPlayerStorageValue(cid, config.storage) == -1 then
        if getPlayerMoney(cid) >= 500 then
            doPlayerRemoveMoney(cid, 500)
                  doAddCondition(cid, combatUtamo)
            npcHandler:say('Well done, you will have Mana Shield for 1 Hour.', cid)
            setPlayerStorageValue(cid, config.storage, config.value)    
            addEvent(db.executeQuery, magicshieldseconds * 1000, "UPDATE `player_storage` SET `key` = " .. config.storage .. ", `value` = -1 WHERE `player_id` = " .. guid .. " LIMIT 1;")
        else
            npcHandler:say('Im sorry, I forgot to tell you that I need 500 Gold to help you. My supplies are not cheap.', cid)
        end
    else
        npcHandler:say('Good choise, but only Elf Aracanists are mentaly strong for this', cid)
    end
end

function regener(cid, message, keywords, parameters, node)
    local guid = getPlayerGUID(cid)

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

    if(getPlayerVocation(cid) == 6) == true then elseif(getPlayerVocation(cid) == 7) == true and getPlayerStorageValue(cid, config.storage) == -1 then
        if getPlayerMoney(cid) >= 500 then
            doPlayerRemoveMoney(cid, 500)
                  doAddCondition(cid, conditionRege)
            npcHandler:say('Well done, your HP will regenerate faster for 1 Hour.', cid)
            setPlayerStorageValue(cid, config.storage, config.value)    
            addEvent(db.executeQuery, regeseconds * 1000, "UPDATE `player_storage` SET `key` = " .. config.storage .. ", `value` = -1 WHERE `player_id` = " .. guid .. " LIMIT 1;")
        else
            npcHandler:say('Im sorry, I forgot to tell you that I need 500 Gold to help you. My supplies are not cheap.', cid)
        end
    else
        npcHandler:say('You are too weak.', cid)
    end
end

function speed(cid, message, keywords, parameters, node)
    local guid = getPlayerGUID(cid)

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

    if(getPlayerVocation(cid) == 6) == true then elseif(getPlayerVocation(cid) == 7) == true and getPlayerStorageValue(cid, config.storage) == -1 then
        if getPlayerMoney(cid) >= 500 then
            doPlayerRemoveMoney(cid, 500)
                doAddCondition(cid, conditionSpeed)
            npcHandler:say('Well done, your speed has increased for 1 Hour.', cid)
            setPlayerStorageValue(cid, config.storage, config.value)    
            addEvent(db.executeQuery, speedseconds * 1000, "UPDATE `player_storage` SET `key` = " .. config.storage .. ", `value` = -1 WHERE `player_id` = " .. guid .. " LIMIT 1;")
        else
            npcHandler:say('Im sorry, I forgot to tell you that I need 500 Gold to help you. My supplies are not cheap.', cid)
        end
    else
        npcHandler:say('You are too weak.', cid)
    end
end
-- Buff Config End --

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I can help you increase your {distance}, {magic level}, {regeneration}, {invisibility}, {magic shield} and {speed}."})

local node1 = keywordHandler:addKeyword({'magic level'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to increase your magic level for a certain time?'})
    node1:addChildKeyword({'yes'}, magicl, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the Nature be with you, come back when you are ready.', reset = true})

local node2 = keywordHandler:addKeyword({'invisibility'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to be invisible for a certain time?'})
    node2:addChildKeyword({'yes'}, invisible, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the Nature be with you, come back when you are ready.', reset = true})

local node3 = keywordHandler:addKeyword({'distance'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to increase your distance skills for a certain time?'})
    node3:addChildKeyword({'yes'}, distance, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the Nature be with you, come back when you are ready.', reset = true})

local node4 = keywordHandler:addKeyword({'magic shield'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to receive a mana shield for a certain time?'})
    node4:addChildKeyword({'yes'}, magicshield, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node4:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the Nature be with you, come back when you are ready.', reset = true})

local node5 = keywordHandler:addKeyword({'regeneration'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to increase your HP regeneration for a certain time?'})
    node5:addChildKeyword({'yes'}, regener, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the Nature be with you, come back when you are ready.', reset = true})

local node6 = keywordHandler:addKeyword({'speed'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to increase your speed for a certain time?'})
    node6:addChildKeyword({'yes'}, speed, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node6:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the Nature be with you, come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())

LOGG ERROR:
Code:
None

Kind Regards,
Eldin.
 
I don't know about other buffs(I'm on mobile now), but you have missing subid in condition_attribute and maybe combat in regeneration.

Bullseye potion and recovery spell should provide good examples.
 
Aha you set it to find the errors? :D

Now got:
Code:
The Forgotten Server - Version 1.0
Compilied on Dec 11 2013 10:15:34 for arch x86

A server developed by Mark Samman
Visit our forum for updates, support, and resources: http://otland.net/.

>> Loading config
>> Establishing database connection...
[Warning] max_allowed_packet might too low for house item storage
Use the following query to raise max_allow_packet: SET GLOBAL max_allowed_packet
 = 16777216 MySQL 6.0.0
>> Running database manager
>> Loading vocations
>> Loading items
>> Loading script systems
>> Loading monsters
>> Loading outfits
>> Checking world type... PVP
>> Loading map
> Map size: 2048x2048.
> Map loading time: 6.38 seconds.

Lua Script Error: [Npc interface]
data/npc/scripts/AbDendrielBuffer.lua
LuaScriptInterface::luaSetConditionParam(). Condition not found
stack traceback:
  [C]: in function 'setConditionParam'
  data/npc/scripts/AbDendrielBuffer.lua:31: in main chunk

Lua Script Error: [Npc interface]
data/npc/scripts/AbDendrielBuffer.lua
LuaScriptInterface::luaSetConditionParam(). Condition not found
stack traceback:
  [C]: in function 'setConditionParam'
  data/npc/scripts/AbDendrielBuffer.lua:41: in main chunk

Lua Script Error: [Npc interface]
data/npc/scripts/AbDendrielBuffer.lua
LuaScriptInterface::luaSetConditionParam(). Condition not found
stack traceback:
  [C]: in function 'setConditionParam'
  data/npc/scripts/AbDendrielBuffer.lua:51: in main chunk
> Loaded house items in: 0.04 s
>> Initializing gamestate
>> Loaded all modules, server starting up...
>> RaceWars Server Online!

So, Error at 31, 41 and 51 then, Magic, Distance and Regeneration!

Kind Regards,
Eldin.
 
I tryed yours Ninja aswell as mixed with mine myself, both got the same error, here is mine:
http://pastebin.com/Kb33dcii

I can talk to the NPC, but once I try to say "Yes" to get as for example a dist buff, it directly passes to the end line "You are too weak" "You're not the right voc" etc even if I got the right vocation and so on. No error appears in the logg.

Here is my Human Buffer, she Works:
http://pastebin.com/SHQQ7NUh

Can't see the difference why the Elf buffer wouldn't work... :/

Once I got the Buff "Distance" from my Human Buffer, this happend in the logg: (But still works)
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/CarlinBuffer.lua:onCreatureSay
LuaScriptInterface::luaAddEvent(). callback parameter should be a function.
stack traceback:
  [C]: in function 'addEvent'
  data/npc/scripts/CarlinBuffer.lua:118: in function 'callback'
  data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessag
e'
  data/npc/lib/npcsystem/keywordhandler.lua:136: in function 'processNodeM
essage'
  data/npc/lib/npcsystem/keywordhandler.lua:104: in function 'processMessa
ge'
  data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
  data/npc/scripts/CarlinBuffer.lua:7: in function <data/npc/scripts/Carli
nBuffer.lua:7>

Kind Regards,
Eldin.
 
The script is working for me, and you get those responses because you already have the storage value 1 (NPC is checking values below 1)


- - - Updated - - -

This should work, replaced all db.executeQuery with setPlayerStorageValue, fixed CONDITION_HASTE
http://pastebin.com/EkvvZS3C
 
Last edited:
Like you said, it can simply be that they already got the storage value.
Probably that........ ^^

Kind Regards,
Eldin.
 
Back
Top