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

Lua uppercase and lowercase npc

Lais Prad

Disgusting Scammer
Joined
Apr 12, 2017
Messages
153
Solutions
6
Reaction score
15
Hello, how to apply this function on this script npc?
tfs 1.3
Example: if player say "change sex doll" dont work, if he say "Change Sex Doll" will work

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 storeTable = {}
local itemsTable = {
    ["Change Sex Doll"] = {itemId = 13030, count = 15},
    ["Crystal Crossbow"] = {itemId = 18453, count = 5}
}
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        local table = itemsTable[msg]
        if table then
            npcHandler:say("So you want to exchange "..msg..", for ".. table.count .." lucky coins?", cid)
            storeTable[cid] = msg
            npcHandler.topic[cid] = 1
        end
end

npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
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 storeTable = {}
local itemsTable = {
    ["change sex doll"] = {itemId = 13030, count = 15},
    ["crystal crossbow"] = {itemId = 18453, count = 5}
}
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then...
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 storeTable = {}
local itemsTable = {
    ["change sex doll"] = {itemId = 13030, count = 15},
    ["crystal crossbow"] = {itemId = 18453, count = 5}
}
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        local table = itemsTable[msg:lower()]
        if table then
            npcHandler:say("So you want to exchange "..msg..", for ".. table.count .." lucky coins?", cid)
            storeTable[cid] = msg
            npcHandler.topic[cid] = 1
        end
end

npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
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 storeTable = {}
local itemsTable = {
    ["change sex doll"] = {itemId = 13030, count = 15},
    ["crystal crossbow"] = {itemId = 18453, count = 5}
}
local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if npcHandler.topic[cid] == 0 then
        local table = itemsTable[msg:lower()]
        if table then
            npcHandler:say("So you want to exchange "..msg..", for ".. table.count .." lucky coins?", cid)
            storeTable[cid] = msg
            npcHandler.topic[cid] = 1
        end
end

npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Thanks works, but the npc dont Awnser anymore.. I think we need to put lower on npc speak too

I tryed this without sucess:
LUA:
npcHandler:say("So you want to exchange "..msg:lower()..", for ".. table.count .." gold tokens?", cid)
 
Thanks works, but the npc dont Awnser anymore.. I think we need to put lower on npc speak too

I tryed this without sucess:
LUA:
npcHandler:say("So you want to exchange "..msg:lower()..", for ".. table.count .." gold tokens?", cid)

Does it awnser at all?
Try removing :lower() on line 20 and see if that fixes it, if it does try string.lower(msg) insted.
If that dosn't work write print("1") 2, 3, etc etc till you see where the code stops.

But do you have any errors in your console and did you restart the server or just reload?
NPCs can in my experience bug when you just reload for some reason.
 
Back
Top