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

[TFS 1.4.2]Could someone review this code for me?[HELP]

Zarosiano

New Member
Joined
Dec 9, 2022
Messages
21
Reaction score
1
So friends, this is the code.lua of an npc. He recognizes the storage and the item, takes the item and says something.
I tested it, it works in relation to reading the item, removing it, but in the part

selfSay("Obrigado! Ele se chama Azor e esta ao norte na entrada de Firmrock", cid)"

That text doesn't appear on the NPC, just an empty box. I'm learning how to create code so I might be doing something wrong that I didn't notice.

Script:

Lua:
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 config = {
    storage = 2803, -- Storage para acesso.
    item = 7495 }

if msgcontains(msg, 'irmao') then
 if setPlayerStorageValue(cid, config.storage) == 1 then
 selfSay(cid, 'Opa! Ele mandou um humano trazer o Rum ? Parece que ele quer realmente morar fora de Firmrock. Ei, voce pode entrar quando quiser, um amigo do meu irmao e meu amigo.')
 if doPlayerRemoveItem(cid, config.item, 1)
    -- coloque entre ' ' oq o npc ira falar quando o player tiver a storage
   end
   else
 selfSay(cid, 'Nao posso deixar voce passar sem motivo.')
 end

 
return true

end




npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
selfSay(cid, "Thanks! His name is Azor and he's north of the entrance to Firmrock")"

selfSay(creatureId, string)

make sure you are adding each variable in the correct param
 
selfSay(cid, "Thanks! His name is Azor and he's north of the entrance to Firmrock")"



selfSay(creatureId, string)


make sure you are adding each variable in the correct param

I just arrived from work. I noticed that I made a mistake in setting up the topic.
I mentioned the other npc of the quest, in this case the one who tells me to go take the item to another npc.

The error is in the other npc, which is the one in the photo, and the script I mentioned in the topic.
This part where the red arrow is, is where the dialogue does not come out, the whole scheme works, removing the item and giving another storage and such, but the npc's speech does not appear in the game, there is an empty spac

Sem título.png
 
The default configuration of the script has '. I adapted this script, and only added item reading (knowing if the player has the item) and item removal. And it's for the npc to say something like "I received the item and you can pass"
 
The default configuration of the script has '. I adapted this script, and only added item reading (knowing if the player has the item) and item removal. And it's for the npc to say something like "I received the item and you can pass"
line 22 you are missing at the end of the line then (you should share the error itself at least im trying to look into it with you
 
I add the ends, the script has no errors, it just doesn't generate the NPC message, it already performs the actions without showing the message
I don't get any error messages in the console. Because the script works, it's just not showing the npc text
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
função onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
função onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
função onThink() npcHandler:onThink() fim
função criaturaSayCallback(cid, type, msg)
if(não npcHandler:isFocused(cid)) então
retorna falso
fim
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT e 0 ou cid

configuração local = {
    storage = 2803, -- Storage para acesso.
    artigo = 7495 }

if msgcontains(msg, 'irmão') então
 se setPlayerStorageValue(cid, config.storage) == 1 então
 se doPlayerRemoveItem(cid, config.item, 1) então
 selfSay(cid, 'Opa! Ele mandou um humano trazer o Rum ? Parece que ele quer realmente morar fora de Firmrock. Ei, você pode entrar quando quiser, um amigo do meu irmão e meu amigo.')
 outro
    -- coloque entre '' oq o npc ira falar quando o player tiver um storage
   fim
   fim
   outro
 selfSay(cid, 'Nao posso deixar voce passar sem motivo.')
 fim
 
 
retornar verdadeiro

fim




npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, criaturaSayCallback)
npcHandler:addModule(FocusModule:new())
[/CÓDIGO]
Post automatically merged:

CORRECT: (Translate bug a other post)
Lua:
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 config = {
    storage = 2803, -- Storage para acesso.
    item = 7495 }

if msgcontains(msg, 'irmao') then
 if setPlayerStorageValue(cid, config.storage) == 1 then
 if doPlayerRemoveItem(cid, config.item, 1) then
 selfSay(cid, 'Opa! Ele mandou um humano trazer o Rum ? Parece que ele quer realmente morar fora de Firmrock. Ei, voce pode entrar quando quiser, um amigo do meu irmao e meu amigo.')
 else
    -- coloque entre ' ' oq o npc ira falar quando o player tiver a storage
   end
   end
   else
 selfSay(cid, 'Nao posso deixar voce passar sem motivo.')
 end
 
 
return true

end




npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
that part is messy
Lua:
if msgcontains(msg, 'irmao') then
 if setPlayerStorageValue(cid, config.storage) == 1 then
 if doPlayerRemoveItem(cid, config.item, 1) then
 selfSay(cid, 'Opa! Ele mandou um humano trazer o Rum ? Parece que ele quer realmente morar fora de Firmrock. Ei, voce pode entrar quando quiser, um amigo do meu irmao e meu amigo.')
 else
    -- coloque entre ' ' oq o npc ira falar quando o player tiver a storage
   end
   end
   else
 selfSay(cid, 'Nao posso deixar voce passar sem motivo.')
 end


why do you give storage before checking the item ? and why do you setStorage inside if condition nothing will stop a storage from being added there is no conditions for it to return false unless you entered numbers from hell like 1000000000 so that would be better

wait a min...

setPlayerStorageValue(cid, config.storage) == 1? well we have something to discuss

setPlayerStorageValue(cid, storageKey, storageValue) : This one will set the player storage so you can check it later, it doesn't have useful return. so we don't compare it like the what you did in the code (setPlayerStorageValue(cid, config.storage) == 1)

getPlayerStorageValue(cid, storageKey) this will return storageValue already assigned to this storageKey and it is what we compare like you did.

so im not sure what you are trying to do here but i believe i explained enough to understand where is the problem and how to solve it
 
Back
Top