• 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 Acu NPC'S [Attack & Defense refiner]

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,261
Solutions
13
Reaction score
184
Location
Venezuela
Otland Greetings dear friends in this moment i will share my NPC that refines weapons.
The configuration is simple

PHP:
    -------------- Easy config ----------------
    -- How much attack you want in each refine?
    attack = 2,
 
    -- How much defense you want in each refine?
    defense = 2,
 
    -- What item will be required to refine? i use the id 8300 for example
    gem = 8300,
 
    -- How much is the limit attack to refine?
    limitAttack = 85,
 
    -- Slot where you put the weapon to refine (i use left hand) you can change it
    obj = getPlayerSlotItem(cid, CONST_SLOT_LEFT),
 
    -- Add here the items blocked to refine (example -> bright sword (id 2407)
    blocked_items = {2407}

Here is the npc

PHP:
<?xml version="1.0" encoding="UTF-8"?>
    <npc name="Reynolds" script="data/npc/scripts/refine.lua" walkinterval="2000" speed="199" floorchange="0">
    <health now="100" max="100"/>
    <look type="160" head="95" body="94" legs="132" feet="118" addons="0"/>
    <voices>
        <voice text="Im the expert of the weapons..." interval2="20" margin="1" yell="yes"/>
    </voices>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME| if you want refine your weapon say {refine}."/>
    </parameters>
 
</npc>

and the script

PHP:
--------------------------------------------------------------------------------------------------------------------------
-- [You can config the attack,defense values and the limit for each refine too the id of the gem to refine your weapon ] --
-- [NPC Upgrade weapons by Acubens]                                                                                                  --
---------------------------------------------------------------------------------------------------------------------------


local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid


local ref = {
 
    -------------- Easy config ----------------
    -- How much attack you want in each refine?
    attack = 2,
 
    -- How much defense you want in each refine?
    defense = 2,
 
    -- What item will be required to refine? i use the id 8300 for example
    gem = 8300,
 
    -- How much is the limit attack to refine?
    limitAttack = 85,
 
    -- Slot where you put the weapon to refine (i use left hand) you can change it
    obj = getPlayerSlotItem(cid, CONST_SLOT_LEFT),
 
    -- Add here the items blocked to refine (example -> bright sword (id 2407)
    blocked_items = {2407}
 
    }
    if(msgcontains(msg, 'refine')) then 
        if(ref.obj.itemid < 1) then
            doSendMagicEffect(getPlayerPosition(cid), 2)
            npcHandler:say('Please put the weapon that you want refine in your left hand to continue.', cid)
        else
            npcHandler:say('If you want refine some weapon, please place it in your left hand. and then write {continue}.', cid)
            talkState = 1
        end
    elseif(msgcontains(msg, 'continue') and talkState == 1) then
        if(ref.obj.itemid > 0 and isWeapon(ref.obj)) then
            npcHandler:say('You want refine your {' .. getItemNameById(ref.obj.itemid) ..'} with the {"..ref.gem.."}?', cid)
            talkState = 2
        else
            doSendMagicEffect(getPlayerPosition(cid), 2)
            npcHandler:say('Please put the weapon that you want refine in your left hand to continue.', cid)
        end
    elseif(msgcontains(msg, 'yes') and talkState == 2) then
        if(ref.obj.itemid > 0) then                 
            if(getPlayerItemCount(cid,gem) > 0)    then                                 
                if(isInArray({1, 2, 3}, getItemWeaponType(ref.obj.uid)) and not isInArray(ref.blocked_items, ref.obj.itemid)) then                                         
                    if(getItemAttack(ref.obj) < ref.limitAttack) then
                        doPlayerRemoveItem(cid,gem,1)
                        doItemSetAttribute(ref.obj.uid, "attack", (getItemAttack(ref.obj) + ref.attack))
                        doItemSetAttribute(ref.obj.uid, "defense", (getItemDefense(ref.obj) + ref.defense))
                        doItemSetAttribute(ref.obj.uid, "name", getItemNameById(ref.obj.itemid) .." *")
                        doSendMagicEffect(getPlayerPosition(cid), 30)
                        npcHandler:say('Your weapon has been refined with '..ref.attack..' points of attack and '..ref.defense..' points of defense.', cid)
                        talkState = 0
                    else
                        doSendMagicEffect(getPlayerPosition(cid), 2)
                        npcHandler:say('Oh Im sorry you {'..getItemNameById(ref.obj.itemid)..'} cant be refined, reach the limit.', cid)
                        talkState = 0
                    end
                else                                                         
                    doSendMagicEffect(getPlayerPosition(cid), 2)
                    npcHandler:say('Im sorry {'..getPlayerName(cid)..'} my job is only refine weapons.', cid)
                    talkState = 0
                end
            else
                doSendMagicEffect(getPlayerPosition(cid), 2)
                npcHandler:say('To refine your necessary item you own a {'..getItemNameById(ref.gem)..'}.', cid)
                talkState = 0
            end
        else
            npcHandler:say('To refine the weapon needs to be placed on the player.', cid)
        end
    else
        npcHandler:say('If you want refine some weapon type {refine}.', cid)
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
I love this system you created!

I'm trying to make it work on TFS 1.0 but I've run into a road block:


Code:
Lua Script Error: [Npc interface]
data/npc/scripts/refine.lua:onCreatureSay
data/npc/scripts/refine.lua:63: attempt to call global 'isWeapon' (a nil value)
stack traceback:
        [C]: in function 'isWeapon'
        data/npc/scripts/refine.lua:63: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:393: in function 'onCreatureSay'
        data/npc/scripts/refine.lua:19: in function <data/npc/scripts/refine.lua
:18>

I tried isItem but then I wasn't getting any response from the NPC, any ideas what might do the trick?
 
Add this function to you global.lua

PHP:
function isWeapon(uid) return isInArray({1,2,3}, getItemWeaponType(uid)) end
 
tfs 0.3.6
[07/05/2014 21:27:04] [Error - LuaScriptInterface::loadFile] data/npc/scripts/refine.lua:11: function arguments expected near ':'
[07/05/2014 21:27:04] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/refine.lua
[07/05/2014 21:27:04] data/npc/scripts/refine.lua:11: function arguments expected near ':'
 
tfs 0.3.6
[07/05/2014 21:27:04] [Error - LuaScriptInterface::loadFile] data/npc/scripts/refine.lua:11: function arguments expected near ':'
[07/05/2014 21:27:04] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/refine.lua
[07/05/2014 21:27:04] data/npc/scripts/refine.lua:11: function arguments expected near ':'

copy the script again
 
copy the script again

20:02 Reynolds: If you want refine some weapon, please place it in your left hand. and then write continue.
20:02 GOD Drixo [350]: continue

[08/05/2014 20:03:18] [Error - Npc interface]
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:eek:nCreatureSay
[08/05/2014 20:03:18] Description:
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:53: attempt to call global 'isWeapon' (a nil value)
[08/05/2014 20:03:18] stack traceback:
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:53: in function 'callback'
[08/05/2014 20:03:18] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:13: in function <data/npc/scripts/refine.lua:13>



I don't have a global.lua , so I don't know where to add:
function isWeapon(uid) return isInArray({1,2,3}, getItemWeaponType(uid)) end

After adding it to lib\050-function.lua I get this error:

[08/05/2014 20:06:35] [Error - Npc interface]
[08/05/2014 20:06:35] data/npc/scripts/refine.lua:eek:nCreatureSay
[08/05/2014 20:06:35] Description:
[08/05/2014 20:06:35] (luaGetThing) Thing not found
 
I love this system you created!

I'm trying to make it work on TFS 1.0 but I've run into a road block:


Code:
Lua Script Error: [Npc interface]
data/npc/scripts/refine.lua:onCreatureSay
data/npc/scripts/refine.lua:63: attempt to call global 'isWeapon' (a nil value)
stack traceback:
        [C]: in function 'isWeapon'
        data/npc/scripts/refine.lua:63: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:393: in function 'onCreatureSay'
        data/npc/scripts/refine.lua:19: in function <data/npc/scripts/refine.lua
:18>

I tried isItem but then I wasn't getting any response from the NPC, any ideas what might do the trick?

Got it to work with the code global.lua code Abucens told you about?

Kind Regards,
Eldin .
 
Got it to work with the code global.lua code Abucens told you about?

Kind Regards,
Eldin .

Hey Eldin,

No unfortunately there were more errors, I instead used Zbizu's upgrade system but I plan on comming back to this one soon and fixing it for tfs 1.0 because it's a really nice idea. I'll let you know if I get it working 100%.

Best Regards,
imkingran
 
i have this error
[08/05/2014 20:03:18] [Error - Npc interface]
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:eek:nCreatureSay
[08/05/2014 20:03:18] Description:
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:53: attempt to call global 'isWeapon' (a nil value)
[08/05/2014 20:03:18] stack traceback:
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:53: in function 'callback'
[08/05/2014 20:03:18] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[08/05/2014 20:03:18] data/npc/scripts/refine.lua:13: in function <data/npc/scripts/refine.lua:13>
 
Code:
[16/10/2015 10:42:27] [Error - Npc interface]
[16/10/2015 10:42:27] data/npc/scripts/refine.lua:onCreatureSay
[16/10/2015 10:42:28] Description:
[16/10/2015 10:42:28] (luaGetThing) Thing not found
 
Back
Top