• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[NPC] który wymienia dany item na nagrode :o

elseifa nie musisz zamykac?:$

Hmm wszystko jest zamknięte przecież, chyba że ślepy jestem.

Ponieważ kolejny if zagłębiony jest w elseif'ie ale że przed kolejnym elseif'em zamykam if'a więc wszystko jest pozamykane.
 
Przyjrzyj się dokładnie jak wygląda struktura jego kodu

LUA:
if
elseif
  if
  else
  end
else -- nigdy nie sprawdzałem czy może być if->elseif->else ale pewnie może być
end
???
elseif -- nie ma if'a który by zaczynał
end -- zakończenie funkcji a nie if'a a tym bardziej elseif'a
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

local st = 
{
[1] = 0000, -- tu podajesz id itema ktory wylosujesz
[2] = 0001, 
[3] = 0002
} 

local iditema = xxxx -- tu podajesz id itema ktory musisz przyniesc

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 rand = st[math.random(1, #st)]	
    if(msgcontains(msg, 'prezent')) then
        selfSay('Przyniosels mi co trzeba?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'tak') and talkState[talkUser] == 1) then
            if((getPlayerItemCount(cid, iditema) >= 20) == TRUE) then	
				doPlayerAddItem(cid, rand)
                selfSay('ok :)', cid)
            else
                selfSay('nie masz tego co trza.', cid)
            end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'nie') and talkState[talkUser] == 1) then  
        selfSay('ok', cid)
		talkState[talkUser] = 0
    end
    
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


A może tak, a może nie?
Może za trzy minuty lub za dwie? Zaczyna się przedstawienie Co będzie na arenie? - Ja nie wiem! Nie jestem pewien...

Wszystko fajnie hula ale gdy prowadzę konwersacje z npc, wygląda to tak:
22:10 Jakubek [1]: hi
22:10 Eryn: Hello Jakubek.
22:10 Jakubek [1]: prezent
22:10 Eryn: Przyniosels mi co trzeba?
22:10 Jakubek [1]: tak
22:10 Eryn: ok :)

Po czym present bagi zostają w bp i daja nagrody.

Jak zrobić aby losował spośród CC? od 3 - 10cc ?

skrypt po wpisaniu ID:

Code:
  local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

local st =
{
[1] = 8888, -- tu podajesz id itema ktory wylosujesz
[2] = 2160,
[3] = 2472
}

local iditema = 6497 -- tu podajesz id itema ktory musisz przyniesc

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 rand = st[math.random(1, #st)]   
    if(msgcontains(msg, 'prezent')) then
        selfSay('Przyniosels mi co trzeba?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'tak') and talkState[talkUser] == 1) then
            if((getPlayerItemCount(cid, iditema) >= 20) == TRUE) then  
                                doPlayerAddItem(cid, rand)
                selfSay('ok :)', cid)
            else
                selfSay('nie masz tego co trza.', cid)
            end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'nie') and talkState[talkUser] == 1) then  
        selfSay('ok', cid)
                talkState[talkUser] = 0
    end
   
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
LUA:
  local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

local st =
{
[1] = 8888, -- tu podajesz id itema ktory wylosujesz
[2] = 2160,
[3] = 2472,
[3] = 2160
}

local iditema = 6497 -- tu podajesz id itema ktory musisz przyniesc
local ilosc = 1

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 rand = st[math.random(1, #st)]   
    if(msgcontains(msg, 'prezent')) then
        selfSay('Przyniosels mi co trzeba?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'tak') and talkState[talkUser] == 1) then
            if(doPlayerRemoveItem(cid, iditema, ilosc) == TRUE) then  
				if rand == 4 then
					cc =  math.random(3, 10)
					doPlayerAddItem(cid, rand, cc)
				else
					doPlayerAddItem(cid, rand)
				end
                selfSay('ok :)', cid)
            else
                selfSay('nie masz tego co trza.', cid)
            end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'nie') and talkState[talkUser] == 1) then  
        selfSay('ok', cid)
                talkState[talkUser] = 0
    end
   
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Możesz wkleić ten skrypt.

To nie ja powinienem się prosić o skrypt tylko ty sam powinieneś wiedzieć by go wstawić chyba że nie chcesz już pomocy.
 
Code:
  local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

local st =
{
[1] = 8888, -- tu podajesz id itema ktory wylosujesz
[2] = 2160,
[3] = 2472
}

local iditema = 6497 -- tu podajesz id itema ktory musisz przyniesc

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 rand = st[math.random(1, #st)]   
    if(msgcontains(msg, 'prezent')) then
        selfSay('Przyniosels mi co trzeba?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'tak') and talkState[talkUser] == 1) then
            if((getPlayerItemCount(cid, iditema) >= 20) == TRUE) then  
                                doPlayerAddItem(cid, rand)
                selfSay('ok :)', cid)
            else
                selfSay('nie masz tego co trza.', cid)
            end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'nie') and talkState[talkUser] == 1) then  
        selfSay('ok', cid)
                talkState[talkUser] = 0
    end
   
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
jak byś wkleił ostatni mój skrypt to by działał (po coś robiłem w nim zmiany)
 
Podepnę się pod temat gdyż mam podobny problem z NPC

Potrzebuję skrypt który zamieni item za item z tym że jeżeli gracz ma dwa itemy to mu je zamieni na 2 inne, jeżeli ma 3 itemy to zamieni na 3 inne etc.

Mógłbym to zrobić tak:
Code:
function 1gem(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    if getPlayerItemCount(cid,2158) = 1 then
        if doPlayerRemoveItem(cid,2158,1) then
            npcHandler:say('Take your reward!', cid)
            doPlayerAddItem(cid,5910,1)
        end
        else
            npcHandler:say('Are you trying to mess with me?!', cid)
        end
    end
		
function 2gem(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    if getPlayerItemCount(cid,2158) = 2 then
        if doPlayerRemoveItem(cid,2158,2) then
			npcHandler:say('Take your reward!', cid)
            doPlayerAddItem(cid,5910,2)
        end
        else
            npcHandler:say('Are you trying to mess with me?!', cid)
        end
    end
i tak dalej...

Tylko że to troche śmiesznie dodawać 100+ funkcji, jak to skrócić?
rep+
 
LUA:
function gem(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local itemid = xxxx
	local ilosc = getPlayerItemCount(cid,itemid)
    if ilosc >= 1 then
        if doPlayerRemoveItem(cid,2158,ilosc) then
			npcHandler:say('Take your reward!', cid)
            doPlayerAddItem(cid,5910,ilosc)
        end
        else
            npcHandler:say('Are you trying to mess with me?!', cid)
        end
    end

Nie zaczynaj nazwy funkcji od cyfry.
 
Back
Top