Hi! I wrote my first script. It based on script for first wand/rod. (I am using TFS 1.5 downgrade to 8.6).
So... I wanna make a npc, which will give first sword/axe/club for a knight/elite knight.
This is my code:
The script works until the frase: "What kind of weapon do you prefer...?". When I am asking about sword/club/axe, there is no reaction from NPC and console (zero errors).
What I missed?
And I have a question about assigning storage value. I must register that somewhere before? And why there is value -1 and that works (in script with wand/rod)?
Sorry for my question and knowledge. I am learning yet.
So... I wanna make a npc, which will give first sword/axe/club for a knight/elite knight.
This is my code:
Lua:
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "first weapon") and player:getVocation():getBase():getId() == 4 then
npcHandler:say("What kind of weapon do you prefer? A {sword}, an {axe} or a {club}?", cid)
if msgcontains(msg, "sword") and player:getVocation():getBase():getId() == 4 then
if player:getStorageValue(PlayerStorageKeys.firstWeapon) == -1 then
npcHandler:say("So you ask me for a jagged sword to begin your adventure?", cid)
npcHandler.topic[cid] = 1
else
npcHandler:say("What? I have already gave you one jagged sword!", cid)
end
elseif msgcontains(msg, "axe") and player:getVocation():getBase():getId() == 4 then
if player:getStorageValue(PlayerStorageKeys.firstWeapon) == -1 then
npcHandler:say("So you ask me for a steel axe to begin your adventure?", cid)
npcHandler.topic[cid] = 2
else
npcHandler:say("What? I have already gave you one steel axe!", cid)
end
elseif msgcontains(msg, "club") and player:getVocation():getBase():getId() == 4 then
if player:getStorageValue(PlayerStorageKeys.firstWeapon) == -1 then
npcHandler:say("So you ask me for a daramanian mace to begin your adventure?", cid)
npcHandler.topic[cid] = 3
else
npcHandler:say("What? I have already gave you one daramian mace!", cid)
end
end
elseif msgcontains(msg, "yes") then
if npcHandler.topic[cid] == 1 then
player:addItem(8602, 1)
npcHandler:say("Here you are young adept, take care yourself.", cid)
player:setStorageValue(PlayerStorageKeys.firstWeapon, 1)
elseif npcHandler.topic[cid] == 2 then
player:addItem(8601, 1)
npcHandler:say("Here you are young adept, take care yourself.", cid)
player:setStorageValue(PlayerStorageKeys.firstWeapon, 1)
elseif npcHandler.topic[cid] == 3 then
player:addItem(2439, 1)
npcHandler:say("Here you are young adept, take care yourself.", cid)
player:setStorageValue(PlayerStorageKeys.firstWeapon, 1)
end
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
npcHandler:say("Ok, then.", cid)
npcHandler.topic[cid] = 0
elseif msgcontains(msg, "first weapon") and player:getVocation():getBase():getId() ~= 4 then
npcHandler:say("Sorry, you aren\'t a knight.",cid)
end
return true
end
The script works until the frase: "What kind of weapon do you prefer...?". When I am asking about sword/club/axe, there is no reaction from NPC and console (zero errors).
What I missed?
And I have a question about assigning storage value. I must register that somewhere before? And why there is value -1 and that works (in script with wand/rod)?
Sorry for my question and knowledge. I am learning yet.