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

Boot charging NPC creating.

CesarZ

Well-Known Member
Joined
Sep 20, 2012
Messages
268
Solutions
4
Reaction score
63
Hey Guys i have been working on my coding for the past months i have been working on some stuff, im needing a little help here. im trying transform the henricus.lua to a NPC that charge your boots. first im starting with the soft boots to see if it succeed. im Using TFS 1.3

so this is what i have done.


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

local function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
   
    if(msgcontains(msg, "charge soft boots")) then
        npcHandler:say("Would you like to charge yo soft boots for 10000 gold? you need to have 1 empty soft boot and 10000 gold.")
        if (msgcontains(msg, "Yes")) then
            player:removeItem(6132) -- empty soft boots taken away
            player:removeMoney(10000) -- collect the money
            player:addItem(2640) -- add the new boots
    else
        npcHandler:say("Come back when you have everything i asked for")
        end  
            return true
    end
end

npcHandler:setMessage(MESSAGE_GREET, "Hello would like to {charge soft boots} today? |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good luck!, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



Code:
player:addItem(2640)
its not set up right. because its collecting and adding at the same time without checking the collection first and then adding

its giving me a nil error when i say yes.

my plan was

INI:
if (players say("charge soft boots")) then
                npc:say("Would you like to charge you soft for ect ect ect?")
        if (player:say("yes")) then
                removeItemfromplayer(itemid)
                removemoney(amount)
                additem(new softboots charged item id)
            else
                npc:say("sorry you suck on money")
        end
            return true
end
 
Solution

@Xikini

Lua:
npchandler.topic[cid] -- whats this for?
it's kinda working like a variable, but
how you using it in this script what is it doing?
It's an array.
It looks like this
Lua:
npchandler = {}
Lua:
npchandler = {
    topic = {}
}
Lua:
npchandler = {
    topic = {
        [cid] = 0
    }
}
It's pre-built into the npc libs.
We are storing / modifying the variable inside the array, to use later.

It would be the same as using
Lua:
local thing = 0

The key difference, is that we are using the creatureId (cid) in order to differentiate players from one another.
Hey Guys i have been working on my coding for the past months i have been working on some stuff, im needing a little help here. im trying transform the henricus.lua to a NPC that charge your boots. first im starting with the soft boots to see if it succeed. im Using TFS 1.3

so this is what i have done.


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

local function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
 
    if(msgcontains(msg, "charge soft boots")) then
        npcHandler:say("Would you like to charge yo soft boots for 10000 gold? you need to have 1 empty soft boot and 10000 gold.")
        if (msgcontains(msg, "Yes")) then
            player:removeItem(6132) -- empty soft boots taken away
            player:removeMoney(10000) -- collect the money
            player:addItem(2640) -- add the new boots
    else
        npcHandler:say("Come back when you have everything i asked for")
        end
            return true
    end
end

npcHandler:setMessage(MESSAGE_GREET, "Hello would like to {charge soft boots} today? |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good luck!, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())



Code:
player:addItem(2640)
its not set up right. because its collecting and adding at the same time without checking the collection first and then adding

its giving me a nil error when i say yes.

my plan was

INI:
if (players say("charge soft boots")) then
                npc:say("Would you like to charge you soft for ect ect ect?")
        if (player:say("yes")) then
                removeItemfromplayer(itemid)
                removemoney(amount)
                additem(new softboots charged item id)
            else
                npc:say("sorry you suck on money")
        end
            return true
end

Properly tabbing your script is something you MUST learn.
80% of your time spent scripting, is going to be reading your script, so you want to make reading your script as easy as possible.

The rest of it.. ahh
There's a lot to fix.. so I'm just going to show you the proper way to do it.

If you don't understand something, let me know, and I'll try to explain why I've done it.

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

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
   
    if msgcontains(msg, "charge soft boots") then
        npcHandler:say("Would you like to charge yo soft boots for 10000 gold? you need to have 1 empty soft boot and 10000 gold.")
        npcHandler.topic[cid] = 1
       
    elseif npcHandler.topic[cid] == 1 then
        if msgcontains(msg, "yes") then
            if player:getItemCount(6132) >= 1 and player:getMoney() >= 10000 then
                player:removeItem(6132, 1) -- empty soft boots taken away
                player:removeMoney(10000) -- collect the money
                player:addItem(2640) -- add the new boots
            else
                npcHandler:say("Come back when you have everything i asked for")
            end
        else
            npcHandler:say("Another time then.")
        end
        npcHandler.topic[cid] = 0
       
    end
    return true
end

local function onAddFocus(cid)
    npcHandler.topic[cid] = 0
end

local function onReleaseFocus(cid)
    npcHandler.topic[cid] = nil
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setMessage(MESSAGE_GREET, "Hello would like to {charge soft boots} today? |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good luck!, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 

@Xikini

Lua:
npchandler.topic[cid] -- whats this for?
it's kinda working like a variable, but
how you using it in this script what is it doing?
 

@Xikini

Lua:
npchandler.topic[cid] -- whats this for?
it's kinda working like a variable, but
how you using it in this script what is it doing?
It's an array.
It looks like this
Lua:
npchandler = {}
Lua:
npchandler = {
    topic = {}
}
Lua:
npchandler = {
    topic = {
        [cid] = 0
    }
}
It's pre-built into the npc libs.
We are storing / modifying the variable inside the array, to use later.

It would be the same as using
Lua:
local thing = 0

The key difference, is that we are using the creatureId (cid) in order to differentiate players from one another.
 
Solution
Back
Top