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

I need npc script

look
Code:
local focus = 0
local talk_start = 0
local target = 0
local cena = 250   --cena biletu (w gp!)
local ticket = 15834  --Tego nie zmieniaj!
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
      end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)
      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
         selfSay('Hiho ' .. creatureGetName(cid) .. '! How may I help you '.. creatureGetName(cid)..'? I can sell tickets for the ore wagon service.')
         focus = cid
         talk_start = os.clock()
      elseif focus == cid then
        talk_start = os.clock()
        if msgcontains(msg, 'ticket') or msgcontains(msg, 'tickets') then
            selfSay('Do you want to purchase a weekly ticket for the ore wagons? With it you can travel freely and fast through Kazordoon for one week. '.. cena ..' gold only. Deal?')
            talk_state = 1
        elseif talk_state == 1 then
            if msgcontains(msg, 'yes') then
                if getPlayerStorageValue(cid, ticket) == -1 then
                    if doPlayerRemoveMoney(cid, cena) == TRUE then
                        if setPlayerStorageValue(cid, ticket, os.time() + 604800) == TURE then
                            selfSay('You have succesfull buy a weekly ticket for the ore wagon service.')
                        else
                            selfSay('Sory, i can\'t...')
                        end
                    else
                        selfSay('Sorry, you do not have enough money.')
                    end
                else
                    selfSay('You have buy a weekly ticket!')
                end
             end
            talk_state = 0
          elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
              selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
              focus = 0
              talk_start = 0
          end
      end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
    doNpcSetCreatureFocus(focus)
      if (os.clock() - talk_start) > 30 then
          if focus > 0 then
              selfSay('Next Please...')
          end
              focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end
BUT THAT NOT WORK
 
Code:
local focus = 0
local talk_start = 0
local target = 0
local cena = 250   --cena biletu (w gp!)
local ticket = 15834  --Tego nie zmieniaj!
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
      end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
      return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
function onCreatureSay(cid, type, msg)
      msg = string.lower(msg)
      if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
         selfSay('Hiho ' .. creatureGetName(cid) .. '! How may I help you '.. creatureGetName(cid)..'? I can sell tickets for the ore wagon service.')
         focus = cid
         talk_start = os.clock()
      elseif focus == cid then
        talk_start = os.clock()
        if msgcontains(msg, 'ticket') then
            selfSay('Do you want to purchase a weekly ticket for the ore wagons? With it you can travel freely and fast through Kazordoon for one week. '.. cena ..' gold only. Deal?')
            talk_state = 1
        elseif talk_state == 1 then
            if msgcontains(msg, 'yes') then
                if getPlayerStorageValue(cid, ticket) == -1 then
                    if doPlayerRemoveMoney(cid, cena) == TRUE then
                        if setPlayerStorageValue(cid, ticket, os.time() + 604800) == TURE then
                            selfSay('You have succesfull buy a weekly ticket for the ore wagon service.')
                        else
                            selfSay('Sory, i can\'t...')
                        end
                    else
                        selfSay('Sorry, you do not have enough money.')
                    end
                else
                    selfSay('You have buy a weekly ticket!')
                end
             end
            talk_state = 0
          elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
              selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
              focus = 0
              talk_start = 0
          end
      end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
    doNpcSetCreatureFocus(focus)
      if (os.clock() - talk_start) > 30 then
          if focus > 0 then
              selfSay('Next Please...')
          end
              focus = 0
      end
     if focus ~= 0 then
         if getDistanceToCreature(focus) > 5 then
             selfSay('Good bye then.')
             focus = 0
         end
     end
end
 
not work...
Code:
 [11:10:36.538] [Error - NpcScript Interface]
[11:10:36.538] data/npc/scripts/Lokur.lua:onCreatureSay
[11:10:36.538] Description:
[11:10:36.538] data/npc/scripts/Lokur.lua:25: attempt to call global 'creatureGe
tName' (a nil value)
[11:10:36.538] stack traceback:
[11:10:36.539]  data/npc/scripts/Lokur.lua:25: in function <data/npc/scripts/Lok
ur.lua:22>
 
Check this and repair becouse that not work too
Code:
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
local price = 250
local ticket = 15834
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if(msgcontains(msg, 'ticket') then
        selfSay('Do you want to purchase a weekly ticket for the ore wagons? With it you can travel freely and fast through Kazordoon for one week. ' .. price .. ' gold only. Deal?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if(getPlayerStorageValue(cid, ticket) < os.time()) then
            if(doPlayerRemoveMoney(cid, price) == TRUE) then
                setPlayerStorageValue(cid, ticket, (os.time() + 604800))
                selfSay('You have succesfull buy a weekly ticket for the ore wagon service.', cid)
            else
                selfSay('Sorry, you do not have enough money.', cid)
            end
        else
            selfSay('You have buy a weekly ticket!', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
John Ticket.xml
XML:
<?xml version="1.0"?>
<npc name="John Ticket" floorchange="0" walkinterval="2500">
    <health now="150" max="150"/>
    <look type="133" head="20" body="120" legs="75" feet="13"/>

    <interaction range="3" idletime="30">
        <interact keywords="hi" focus="1">
            <keywords>hello</keywords>
            <response text="Hello. How may I help you |NAME|?"/>
        </interact>

        <interact keywords="bye" focus="0">
            <keywords>farewell</keywords>
            <response text="It was a pleasure to help you."/>
        </interact>

        <interact event="onPlayerLeave" focus="0">
            <response text="It was a pleasure to help you |NAME|."/>
        </interact>
        
        <interact keywords="ticket">
            <list>tickets</list>
            <response>
                <action name="script">
                    <![CDATA[
                        storage = 19745
                        if exhaustion.get(cid, storage) then
                            selfSay('Your ticket has not expired yet.', cid)
                        else
                            exhaustion.set(cid, storage, 60 * 60 * 24 * 7)
                            selfSay('There, I gave you a ticket that lasts 7 days.', cid)
                        end
                    ]]>
                </action>
            </response>
        </interact>

        <interact keywords="job">
            <response text="I give tickets."/>
        </interact>

    </interaction>
</npc>

to verify in other scripts if player has active storage use
Lua:
if exhaustion.get(cid, storage) then
 
Code:
 <?xml version="1.0" encoding="UTF-8"?>
<npc name="Lokur" script="data/npc/scripts/Lokur.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="160" head="57" body="79" legs="98" feet="95" addons="0"/>
<voices>
<voice text="If you need help with letters or parcels, just ask me. I can explain everything." interval2="100" margin="1" yell="no"/>
<voice text="Also selling weekly tickets for the ore wagon service!" interval2="120" margin="1" yell="no"/>
<voice text="Welcome to the post office!" interval2="90" margin="1" yell="no"/>
</voices>
<parameters>
		<parameter key="module_shop" value="1" />
		<parameter key="shop_buyable" value="label,2599,1;parcel,2595,15;letter,2597,8;" />
        <parameter key="message_greet" value="How may I help you |PLAYERNAME|? Ask me for a {trade} if you want to buy something. I can also explain the {mail} system, sell {tickets} for the ore wagon service or give you access to your {bank} account."/>
        <parameter key="message_farewell" value="Come back if you need my services, |PLAYERNAME|."/>
		<parameter key="message_walkaway" value="Come back if you need my services, |PLAYERNAME|." />
		<parameter key="message_sendtrade" value="Here. Don't forget that you need to buy a label too if you want to send a parcel. Always write the name of the {receiver} in the first line and the name of the {city} in the second line." />
    </parameters>
	        <interact keywords="ticket">
            <list>tickets</list>
            <response>
                <action name="script">
                    <![CDATA[
                        storage = 19745
                        if exhaustion.get(cid, storage) then
                            selfSay('Your ticket has not expired yet.', cid)
                        else
                            exhaustion.set(cid, storage, 60 * 60 * 24 * 7)
                            selfSay('There, I gave you a ticket that lasts 7 days.', cid)
                        end
                    ]]>
                </action>
            </response>
        </interact>
</npc>
please add function ticket for 250gp
 
XML:
<?xml version="1.0"?>
<npc name="John Ticket" floorchange="0" walkinterval="2500">
    <health now="150" max="150"/>
    <look type="133" head="20" body="120" legs="75" feet="13"/>
 
    <interaction range="3" idletime="30">
        <interact keywords="hi" focus="1">
            <keywords>hello</keywords>
            <response text="Hello. How may I help you |NAME|?"/>
        </interact>
 
        <interact keywords="bye" focus="0">
            <keywords>farewell</keywords>
            <response text="It was a pleasure to help you."/>
        </interact>
 
        <interact event="onPlayerLeave" focus="0">
            <response text="It was a pleasure to help you |NAME|."/>
        </interact>
 
        <interact keywords="ticket">
            <list>tickets</list>
            <response>
                <action name="script">
                    <![CDATA[
                        storage = 19745
                        if exhaustion.get(cid, storage) then
                            selfSay('Your ticket has not expired yet.', cid)
                        elseif not doPlayerRemoveMoney(cid, 250) then
                            selfSay('You need 250 gold coins to buy me a ticket.', cid)
                        else
                            exhaustion.set(cid, storage, 60 * 60 * 24 * 7)
                            selfSay('There, I gave you a ticket that lasts 7 days.', cid)
                        end
                    ]]>
                </action>
            </response>
        </interact>
 
        <interact keywords="job">
            <response text="I give tickets for 250 gold coins."/>
        </interact>
 
    </interaction>
</npc>
 
i have to copy only
Code:
         <interact keywords="ticket">
            <list>tickets</list>
            <response>
                <action name="script">
                    <![CDATA[
                        storage = 19745
                        if exhaustion.get(cid, storage) then
                            selfSay('Your ticket has not expired yet.', cid)
                        elseif not doPlayerRemoveMoney(cid, 250) then
                            selfSay('You need 250 gold coins to buy me a ticket.', cid)
                        else
                            exhaustion.set(cid, storage, 60 * 60 * 24 * 7)
                            selfSay('There, I gave you a ticket that lasts 7 days.', cid)
                        end
                    ]]>
                </action>
            </response>
        </interact>
to move on my npc?
 
look i need too question buy
Code:
Do you want to purchase a weekly ticket for the ore wagons? With it you can travel freely and fast through Kazordoon for one week. 250 gold only. Deal?
and yes or no
 
Back
Top