Reklama
Pokazuje wyniki od 1 do 3 z 3

Temat: [8.54] NPC-gadanie.

  1. #1
    Avatar Demonolog
    Data rejestracji
    2008
    Posty
    73
    Siła reputacji
    16

    Domyślny [8.54] NPC-gadanie.

    Chciałem zrobić coś własnego u npc ale nie mogę tego nawet przetestować bo cały czas jakieś błędy mam.

    Moim celem było, żeby npc 'Więzień' sprawdzał czy drzwi na danym polu są otwarte.

    Ogólnie sam nie umiem pisać skryptów to skopiowałem z jakiegoś innego większość i własną funkcje chciałem mu dodać.

    Cały skrypt:
    Kod:
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    local doorpos = {x=1064, y=1238, z=12}
    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
    
    
    if msgcontains(msg, 'hi;hello;h') then
    		npcHandler:say("Please, can you open this doors? Im not a bandit or anything, someone thrown me here and closed the doors.. Im a prisoner now. Wanna know where the key is?", cid)
    		
    	else
    		npcHandler:say("Trust me, downstairs there are many treasures and rare items! You can get them if you open this doors. Wanna know where the key is?", cid)
    
    
    elseif msgcontains(msg, 'yes;key;pass;door;') then	
    
    		npcHandler:say("Ok then, the key is in dead tree, the dead tree is close to dragon lords and close from here, go and search it!", cid)
    
    end
    
    
    
    if msgcontains(msg, 'open;door;hi;') then
                function check (item, toposition)
                if item.itemid == 5111
                itempos = getThingfromPos(doorpos) then
    
               npcHandler:say("You openned the doors!! Mwahahhaha, go for you reward now mortal! Im free and gonna rule the world!", cid)
    end
     
    
    
    		
    	else
    		npcHandler:say("Mwahahaha azure syh sumer fallah tahn!", cid)
    end
    
    return TRUE
    end
    
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())
    Podkreślone i kolorem jest to co chciałem dodać od siebie.

    Przykładowy błąd:
    [Error - LuaScriptInterface::loadFile] data/npc/scripts/zigirrongh.lua:24: 'end' expected (to close 'if' at line 17) near 'elseif'
    [26/07/2010 00:09:16] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/zigirrongh.lua
    [26/07/2010 00:09:16] data/npc/scripts/zigirrongh.lua:24: 'end' expected (to close 'if' at line 17) near 'elseif'
    Pisze niby, że brakuje 'end' tam, a jak dodam end to pisze wtedy, że jakby za dużo ich dałem >.<

    ps:Tak przy okazji, dlaczego quest mi działa skoro nie zmieniłem w nim storage (jest 50305) a na mapce i w actions jest 57497?? Jak dałbym to 50305 uid. do skrzynki questowej to by nie działało wtedy ;/.. Ma ktoś jakieś racjonalne wytłumaczenie?
    http://forum.tibia.org.pl/showthread.php?t=366038
    - Moja mapa :), zapraszam do oglądania..

  2. #2
    Avatar Grim90
    Data rejestracji
    2007
    Położenie
    Toruń / Brzozówka
    Wiek
    34
    Posty
    586
    Siła reputacji
    17

    Domyślny

    Cytuj Demonolog napisał Pokaż post
    Cytat został ukryty, ponieważ ignorujesz tego użytkownika. Pokaż cytat.
    Chciałem zrobić coś własnego u npc ale nie mogę tego nawet przetestować bo cały czas jakieś błędy mam.

    Moim celem było, żeby npc 'Więzień' sprawdzał czy drzwi na danym polu są otwarte.

    Ogólnie sam nie umiem pisać skryptów to skopiowałem z jakiegoś innego większość i własną funkcje chciałem mu dodać.

    Cały skrypt:
    Kod:
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    local doorpos = {x=1064, y=1238, z=12}
    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
    
    
    if msgcontains(msg, 'hi;hello;h') then
    		npcHandler:say("Please, can you open this doors? Im not a bandit or anything, someone thrown me here and closed the doors.. Im a prisoner now. Wanna know where the key is?", cid)
    		
    	else
    		npcHandler:say("Trust me, downstairs there are many treasures and rare items! You can get them if you open this doors. Wanna know where the key is?", cid)
    
    
    elseif msgcontains(msg, 'yes;key;pass;door;') then	
    
    		npcHandler:say("Ok then, the key is in dead tree, the dead tree is close to dragon lords and close from here, go and search it!", cid)
    
    end
    
    
    
    if msgcontains(msg, 'open;door;hi;') then
                function check (item, toposition)
                if item.itemid == 5111
                itempos = getThingfromPos(doorpos) then
    
               npcHandler:say("You openned the doors!! Mwahahhaha, go for you reward now mortal! Im free and gonna rule the world!", cid)
    end
     
    
    
    		
    	else
    		npcHandler:say("Mwahahaha azure syh sumer fallah tahn!", cid)
    end
    
    return TRUE
    end
    
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:addModule(FocusModule:new())
    Podkreślone i kolorem jest to co chciałem dodać od siebie.

    Przykładowy błąd:


    Pisze niby, że brakuje 'end' tam, a jak dodam end to pisze wtedy, że jakby za dużo ich dałem >.<

    ps:Tak przy okazji, dlaczego quest mi działa skoro nie zmieniłem w nim storage (jest 50305) a na mapce i w actions jest 57497?? Jak dałbym to 50305 uid. do skrzynki questowej to by nie działało wtedy ;/.. Ma ktoś jakieś racjonalne wytłumaczenie?
    To:
    Kod:
    if msgcontains(msg, 'hi;hello;h') then
    Zmień na:
    Kod:
    if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'h') then
    Lub:
    Kod:
    local powitania = {"hi", "hello", "h"}
    
    if isInArray("powitania", msg) then
    Ostatniego nie testowałem, napisałem na szybkiego.

    To po pierwsze, po drugie masz źle uszeregowane instrukcje warunkowe.

    Musi to wyglądać tak

    Kod:
    if ... then
    	<...>
    end
    lub

    Kod:
    if ... then
    	<...>
    else
    	<...>
    end
    lub

    Kod:
    if ... then
    	<...>
    elseif ... then
    	<...>
    else
    	<...>
    end
    Ostatnio zmieniony przez Grim90 : 26-07-2010, 00:32
    Piszę skrypty do OTS. Chcesz mieć unikalny quest, lub skrypt na swoim serwerze? Pisz do mnie. Na pewno się dogadamy.
    Piszę skrypty PHP, strony oraz gotowe serwisy, jeśli jesteś zainteresowany, napisz.
    http://radeg.pl

    Masz facebooka? Zapraszamy do grupy: Grim OTS!
    http://www.facebook.com/?ref=logo#!/...07707075989449

  3. Reklama
  4. #3
    Avatar Demonolog
    Data rejestracji
    2008
    Posty
    73
    Siła reputacji
    16

    Domyślny

    Nie rozumiem za bardzo :D..

    Kod:
    if msgcontains(msg, 'hi') or msgcontains(msg, 'door') then
                function check (item, toposition)
                elseif item.itemid == 5111 then
                itempos == getThingfromPos(doorpos) then
    
               npcHandler:say("You openned the doors!! Mwahahhaha, go for you reward now mortal! Im free and gonna rule the world!", cid)
    end
    Tak zrobiłem i..

    [26/07/2010 12:55:00] [Error - LuaScriptInterface::loadFile] data/npc/scripts/zigirrongh.lua:24: 'end' expected (to close 'if' at line 17) near 'elseif'
    [26/07/2010 12:55:00] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/zigirrongh.lua
    [26/07/2010 12:55:00] data/npc/scripts/zigirrongh.lua:24: 'end' expected (to close 'if' at line 17) near 'elseif'
    Ostatnio zmieniony przez Demonolog : 26-07-2010, 13:05
    http://forum.tibia.org.pl/showthread.php?t=366038
    - Moja mapa :), zapraszam do oglądania..

Reklama

Informacje o temacie

Użytkownicy przeglądający temat

Aktualnie 1 użytkowników przegląda ten temat. (0 użytkowników i 1 gości)

Podobne tematy

  1. NPC i ich gadanie..
    Przez cinuy w dziale Tibia
    Odpowiedzi: 5
    Ostatni post: 23-09-2013, 07:34
  2. Saphira - Granie i Gadanie
    Przez foczkassj w dziale Tibia
    Odpowiedzi: 0
    Ostatni post: 21-06-2011, 21:23
  3. [7.6][NPC] AutoServer Restart o wyznaaczonym czasie!
    Przez konto usunięte w dziale Skrypty i technika
    Odpowiedzi: 36
    Ostatni post: 14-06-2009, 09:09
  4. Npc Hoggle -Zwariowany rybak
    Przez Didier w dziale Tibia
    Odpowiedzi: 15
    Ostatni post: 28-09-2006, 02:51
  5. NPC Lugri & Ruthless Seven
    Przez ejbi w dziale Tibia
    Odpowiedzi: 33
    Ostatni post: 19-09-2006, 13:19

Zakładki

Zakładki

Zasady postowania

  • Nie możesz pisać nowych tematów
  • Nie możesz pisać postów
  • Nie możesz używać załączników
  • Nie możesz edytować swoich postów
  •