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

Lua NPC FROM LEVEL

SlaVko

New Member
Joined
Nov 30, 2014
Messages
24
Reaction score
0
Hello all,
I want to NPC to be ready, when player have 50 level.
I tried, but did not give advice.. :(

Code:
random_items = {
{350,2160,25}, --  0.5% to get teddy bear
{400,9019,1},
{400,8982,1},
{400,8300,1},
{1000,2687,8} -- 100% to get 8 cookies
}
PRESENT_STORAGE = 54163 -- storage ID



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


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 santaNPC(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if (parameters.present == true) then
        if (getPlayerStorageValue(cid, PRESENT_STORAGE) < 1) then
            local item = {}
            local reward = 0
            local count = ""
            for i = 1, #random_items do
                item = random_items[i]
                if (math.random(0,999) < item[1]) then
                    reward = item[2]
                    subType = item[3]
                    if subType > 1 then
                        count = subType .. " "
                    end
                    break
                end
            end
            doPlayerAddItem(cid, reward, subType)
            setPlayerStorageValue(cid, PRESENT_STORAGE, 1)
            npcHandler:say('HO HO HO! You were good like a little dwarf this year! I got ' .. count .. getItemNameById(reward) .. ' for you.', cid)
        else
            npcHandler:say('I gave you a present already.', cid)
        end
    else
        npcHandler:say('Come back when you start behaving good.', cid)
    end
    npcHandler:resetNpc()
    return true
end
 
npcHandler:setMessage(MESSAGE_GREET, "Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got presents for good children.")

local noNode = KeywordNode:new({'no'}, santaNPC, {present = false})
local yesNode = KeywordNode:new({'yes'}, santaNPC, {present = true})

local node = keywordHandler:addKeyword({'pre'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Were you good this year?'})
    node:addChildKeywordNode(yesNode)
    node:addChildKeywordNode(noNode)
npcHandler:addModule(FocusModule:new())

Thanks for help.

I have tfs 0.4 3884.
 
Last edited by a moderator:
i can't understand you :eek:
you need the npc appear when player reach level 50 ?
or npc give the gift when player is level 50 ? xD
so you need it to be like if i'm level 50+ and i do like that
Player : Hi
Npc : Hello Player , do you need to check out my gift? just say gift
Player : gift
and here are 2 options

option 1

Player 50+ will get this answer
Npc : Oh !! here is my awesome gift for you . Merry Xmas

option 2

Player < 50
Npc : Hey !! go get level 50 first , then come and talk for me . hurry up don't miss the gift .
 
or simply change:

if (getPlayerStorageValue(cid, PRESENT_STORAGE) < 1) then

to

if (getPlayerStorageValue(cid, PRESENT_STORAGE) < 1 and getPlayerLevel(cid) >= 50) then
 
Evil your change is ok and working, but in my console this:

[20:29:21.134] [Error - NpcScript Interface]
[20:29:21.134] data/npc/scripts/santa.lua
[20:29:21.134] Description:
[20:29:21.134] (internalGetPlayerInfo) Player not found when requesting player info #3
 
Back
Top