luq14
Cookie Cotton Joe's
Hello!
I have a problem with all NPC's with Buyable and Sellable modules!
Scripts works fine, but when I ask NPC for example: "buy red tapestry" there is no any answer, but one error in console:
I don't know why is it there because all forum users are using this scrpit and it works fine for them!
Check this out!:
I've also tried to change it and insert module into XML file, but its still not working!
And here is second problem for npc that kill Pkays (from this forum):
Here is Lua file:
Please help me! I am really bored when I see all those errors :thumbup:
I have a problem with all NPC's with Buyable and Sellable modules!
Scripts works fine, but when I ask NPC for example: "buy red tapestry" there is no any answer, but one error in console:
Code:
[B][08/04/2008 21:14:56] data/npc/lib/npcsystem/modules.lua:669: attempt to index global 'npcHandler' (a nil value)[/B]
I don't know why is it there because all forum users are using this scrpit and it works fine for them!
Check this out!:
Code:
[B]XML file:[/B]
- <npc name="Allen" script="data/npc/scripts/furniture.lua" autowalk="1" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150" />
<look type="128" head="116" body="61" legs="57" feet="76" addons="0" corpse="2212" />
- <parameters>
<parameter key="message_greet" value="Welcome to my little shop, |PLAYERNAME|! I can offer you tapestries, chairs, tables, statues and some other things. I also have wooden stake if you want." />
</parameters>
</npc>
[B]Lua file:[/B]
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThingMove(creature, thing, oldpos, oldstackpos) npcHandler:onThingMove(creature, thing, oldpos, oldstackpos) end
function onCreatureAppear(creature) npcHandler:onCreatureAppear(creature) end
function onCreatureDisappear(id) npcHandler:onCreatureDisappear(id) end
function onCreatureTurn(creature) npcHandler:onCreatureTurn(creature) end
function onCreatureChangeOutfit(creature) npcHandler:onCreatureChangeOutfit(creature) end
function onThink() npcHandler:onThink() end
-- OTServ event handling functions end
function creatureSayCallback(cid, type, msg)
if(npcHandler.focus ~= cid) then
return false
end
not_enough_money = 'You do not have enough of money'
stake_give = 'Argh... my heart aches! Alright... a promise is a promise. Here - take this wooden stake, and now get lost.'
player_gold = getPlayerItemCount(cid,2148)
player_plat = getPlayerItemCount(cid,2152)*100
player_crys = getPlayerItemCount(cid,2160)*10000
player_money = player_gold + player_plat + player_crys
-- Wooden Stake --
if msgcontains(msg, 'wooden stake') then
total = 2000
selfSay('Making a stake from a chair? Are you insane??! I won\'t waste my chairs on you for free! You will have to pay for it, but since I consider your plan a blasphemy, it will cost '..total..' gold pieces. Okay?')
talk_state = 1
-- Confirm yes --
elseif msgcontains(msg, 'yes') and talk_state == 1 then
if doPlayerRemoveMoney(cid, total) == TRUE then
selfSay(stake_give)
doPlayerGiveItem(cid, 5941, 1)
focus = 0
else
selfSay(not_enough_money)
end
-- Decline --
elseif msgcontains(msg, 'no') and talk_state == 1 then
selfSay('Thanks god, that I won\'t have to ruin my chair!')
talk_state = 0
end
return true
end
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
-- Statues --
shopModule:addBuyableItem({'knight statue'}, 1442, 50, 'Knight Statue')
shopModule:addBuyableItem({'minotaur statue'}, 1446, 50, 'Minotaur Statue')
shopModule:addBuyableItem({'goblin statue'}, 1447, 50, 'Goblin Statue')
-- Tables --
shopModule:addBuyableItem({'small table'}, 3912, 15, 'Small Table')
shopModule:addBuyableItem({'small round table'}, 3911, 15, 'Small Round Table')
shopModule:addBuyableItem({'stone table'}, 3913, 20, 'Stone Table')
shopModule:addBuyableItem({'square table'}, 3910, 20, 'Square Table')
shopModule:addBuyableItem({'big table'}, 3909, 25, 'Big Table')
shopModule:addBuyableItem({'tusk table'}, 3914, 25, 'Tusk Table')
shopModule:addBuyableItem({'bamboo table'}, 3919, 25, 'Bamboo Table')
-- Chairs --
shopModule:addBuyableItem({'wooden chair'}, 3901, 25, 'Wooden Chair')
shopModule:addBuyableItem({'sofa chair'}, 3902, 50, 'Sofa Chair')
shopModule:addBuyableItem({'red cushioned chair'}, 3903, 40, 'Red Cushioned Chair')
shopModule:addBuyableItem({'green cushioned chair'}, 3904, 40, 'Green Cushioned Chair')
shopModule:addBuyableItem({'tusk chair'}, 3905, 30, 'Tusk Chair')
shopModule:addBuyableItem({'ivory chair'}, 3906, 30, 'Ivory Chair')
shopModule:addBuyableItem({'tree stump'}, 3907, 15, 'Tree Stump')
-- other --
shopModule:addBuyableItem({'coal basin'}, 3908, 40, 'Coal Basin')
shopModule:addBuyableItem({'harp'}, 3917, 45, 'Harp')
shopModule:addBuyableItem({'bird cage'}, 3918, 45, 'Bird Cage')
shopModule:addBuyableItem({'thick trunk'}, 3920, 15, 'Thick Trunk')
shopModule:addBuyableItem({'drawers'}, 3921, 40, 'Drawers')
shopModule:addBuyableItem({'barrel'}, 3923, 15, 'Barrel')
shopModule:addBuyableItem({'piano'}, 3926, 50, 'Piano')
shopModule:addBuyableItem({'globe'}, 3927, 25, 'Globe')
shopModule:addBuyableItem({'potted flower'}, 3928, 25, 'Potted Flower')
shopModule:addBuyableItem({'indoor plant'}, 3929, 25, 'Indoor Plant')
shopModule:addBuyableItem({'christmas tree'}, 3931, 35, 'Christmas Tree')
shopModule:addBuyableItem({'dresser'}, 3932, 20, 'Dresser')
shopModule:addBuyableItem({'pendulum clock'}, 3933, 45, 'Pendulum Clock')
shopModule:addBuyableItem({'locker'}, 3934, 35, 'Locker')
shopModule:addBuyableItem({'trough'}, 3935, 15, 'Trough')
shopModule:addBuyableItem({'bookcase'}, 3936, 40, 'Bookcase')
shopModule:addBuyableItem({'table lamp'}, 3937, 25, 'Table Lamp')
shopModule:addBuyableItem({'large trunk'}, 3938, 35, 'Large Trunk')
-- Tapestries --
shopModule:addBuyableItem({'purple tapestry'}, 1857, 25, 'Purple Tapestry')
shopModule:addBuyableItem({'green tapestry'}, 1860, 25, 'Green Tapestry')
shopModule:addBuyableItem({'yellow tapestry'}, 1863, 25, 'Yellow Tapestry')
shopModule:addBuyableItem({'orange tapestry'}, 1866, 25, 'Orange Tapestry')
shopModule:addBuyableItem({'red tapestry'}, 1869, 25, 'Red Tapestry')
shopModule:addBuyableItem({'blue tapestry'}, 1872, 25, 'Blue Tapestry')
shopModule:addBuyableItem({'white tapestry'}, 1880, 25, 'White Tapestry')
npcHandler:addModule(FocusModule:new())
keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can offer you tapestries, chairs, tables, statues and some other things.'})
keywordHandler:addKeyword({'tapestries'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I have seven colors of tapestries: purple, green, yellow, orange, red, blue and white.'})
keywordHandler:addKeyword({'chairs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I have wooden, sofa, red cushioned, green cushioned, tusk and ivroy chairs. Also you are able to buy here tree stump..'})
keywordHandler:addKeyword({'tables'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Tables are most sellable furniture in my shop. I have: small, small round, stone, square, big, tusk and bamboo tables.'})
keywordHandler:addKeyword({'statues'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I am not exactly statue seller but I can offer you knight, minotaur and goblin statues.'})
keywordHandler:addKeyword({'other'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can also offer you: coal basin, harp, bird cage, thick trunk, drawers, barrel, piano, globe, potted flower, indoor plant, christmas tree, dresser, pendulum clock, locker, trough, bookcase, table lamp and large trunk.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Sorry, I am not looking for any workers now.'})
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
I've also tried to change it and insert module into XML file, but its still not working!
And here is second problem for npc that kill Pkays (from this forum):
Code:
[B][08/04/2008 21:19:11] Lua Script Error: [Npc interface]
[08/04/2008 21:19:11] data/npc/scripts/guard skull.lua:onThink
[08/04/2008 21:19:11] data/npc/scripts/guard skull.lua:108: attempt to perform arithmetic on global 'check_clock' (a nil value)[/B]
Here is Lua file:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local fire = createConditionObject(CONDITION_FIRE)
addDamageCondition(fire, 4, 6000, -20)
addDamageCondition(fire, 4, 6000, -10)
local level = 10
local maglevel = 10
local min_multiplier = 2.1
local max_multiplier = 4.2
local check_interval = 5
local radiusx = 7
local radiusy = 5
local Attack_message = "Take this!"
local town_name = "CITYNAME"
local Attack_monsters = FALSE
local Attack_swearers = TRUE
local Attack_pkers = TRUE
local health_left = 10
local swear_message = "Take this!"
local swear_words = {"ass", "pussy", "kurwa", "dziwka", "bitch", "dick", "craw", "fuck"}
local hit_effect = CONST_ME_HITBYFIRE
local shoot_effect = CONST_ANI_NONE
local damage_colour = TEXTCOLOR_ORANGE
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()
talk = math.random(1,40)
if talk == 1 then
selfSay("Long life to the king!")
end
end
function creatureSayCallback(cid, type, msg)
if(npcHandler.focus ~= cid) then
return FALSE
end
if msgcontains(msg, 'job') then
selfSay("My duty is to protect Verona graves from unwanted intruders.")
elseif msgcontains(msg, 'king') then
selfSay("I would protect the king with my own like if necessary!")
elseif msgcontains(msg, 'ass') or msgcontains(msg, 'pussy') or msgcontains(msg, 'kurwa') or msgcontains(msg, 'dziwka') or msgcontains(msg, 'dick') or msgcontains(msg, 'bitch') or msgcontains(msg, 'craw') or msgcontains(msg, 'fuck') then
selfSay("Take this!")
doCreatureSay(cid, "Ouch!", TALKTYPE_ORANGE_1)
doTargetCombatCondition(0, cid, fire, CONST_ME_NONE)
elseif msgcontains(msg, 'heal') and getCreatureHealth(cid) < 65 then
selfSay("You're hurt, let me heal you.")
heal = 65 - getCreatureHealth(cid)
doCreatureAddHealth(cid, heal)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
elseif msgcontains(msg, 'heal') and getCreatureHealth(cid) >= 65 then
selfSay("You don't need to be healed.")
end
return true
end
function getMonstersfromArea(pos, radiusx, radiusy, stack)
local monsters = { }
local starting = {x = (pos.x - radiusx), y = (pos.y - radiusy), z = pos.z, stackpos = stack}
local ending = {x = (pos.x + radiusx), y = (pos.y + radiusy), z = pos.z, stackpos = stack}
local checking = {x = starting.x, y = starting.y, z = starting.z, stackpos = starting.stackpos}
repeat
creature = getThingfromPos(checking)
if creature.itemid > 0 then
if isCreature(creature.uid) == TRUE then
if isPlayer(creature.uid) == FALSE then
if Attack_monsters == TRUE then
table.insert (monsters, creature.uid)
check_clock = os.clock()
end
elseif isPlayer(creature.uid) == TRUE then
if Attack_pkers == TRUE then
if getPlayerSkullType(creature.uid) > 0 then
table.insert (monsters, creature.uid)
check_clock = os.clock()
end
end
end
end
end
if checking.x == pos.x-1 and checking.y == pos.y then
checking.x = checking.x+2
else
checking.x = checking.x+1
end
if checking.x > ending.x then
checking.x = starting.x
checking.y = checking.y+1
end
until checking.y > ending.y
return monsters
end
function onThink()
if (Attack_monsters == TRUE and Attack_pkers == TRUE) or (Attack_monsters == TRUE and Attack_pkers == FALSE) or (Attack_monsters == FALSE and Attack_pkers == TRUE) then
if (os.clock() - check_clock) > check_interval then
monster_table = getMonstersfromArea(getCreaturePosition(getNpcCid( )), radiusx, radiusy, 253)
if #monster_table >= 1 then
selfSay('' .. Attack_message ..' ')
for i = 1, #monster_table do
doNpcSetCreatureFocus(monster_table[i])
local damage_min = (level * 2 + maglevel * 3) * min_multiplier
local damage_max = (level * 2 + maglevel * 3) * max_multiplier
local damage_formula = math.random(damage_min,damage_max)
doSendDistanceShoot(getCreaturePosition(getNpcCid( )), getThingPos(monster_table[i]), shoot_effect)
doSendMagicEffect(getThingPos(monster_table[i]),hit_effect)
doSendAnimatedText(getThingPos(monster_table[i]),damage_formula,damage_colour)
doCreatureAddHealth(monster_table[i],-damage_formula)
check_clock = os.clock()
focus = 0
end
elseif table.getn(monster_table) < 1 then
focus = 0
check_clock = os.clock()
end
end
end
focus = 0
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Please help me! I am really bored when I see all those errors :thumbup: