• 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

sobek07

Chce być fajny
Joined
Nov 16, 2009
Messages
231
Reaction score
0
Location
Poland / Poznań
Jak wiecie zbliżają się dla niektórych zbliżają się święta(np for me;)) I na moim N00bskim ots przydał by się event. Mianowicie potrzebuję NPC który będzie wymieniał 20x item id:0000 na nagordy o id: 0001, 2160 x 5, 0665. ITEM ID = PRZYKŁADY!

Jeżeli już tu zajrzałeś i nie możesz tego dla mnie zrobić nakarm głodne dziecko http://pajacyk.pl/zlicz.php


;)
 
Pomyśl troszkę bo możesz przerobić npc który wymienia softy na npc który wymienia item x na item y.
 
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

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, 'prezent')) then
        selfSay('Przyniosels mi co trzeba?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'tak') and talkState[talkUser] == 1) then
            if((getPlayerItemCount(cid, 0000) >= 20) == TRUE) then
			--- skrypcik ktory dodaje item ----
                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())

Poświecę się. powinno działać lecz nie pewny :P
 
Własnie przerobiłem sofciarza ;P Ale nie wiem jak zrobić żeby dawał random itemy.

Oto co sklepałem :D

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

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, 'present') or msgcontains(msg, 'present bag')) then
		selfSay('Do you want to change your 20 bags for present?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6497) >= 20) then
				doPlayerRemoveItem(cid, 6497, 20)
				doPlayerAddItem(cid, 0000, 0000, 0000 ,000)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough bags.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Code:
local items = math.random(0000,0001,0002,0003)
doPlayerAddItem(cid, items)
 
math.random(1, 100) potem w ifie ustawiasz dokladniej szanse

Nie chodziło mi o szanse tylko poprostu żeby wybierał sobie z jakiś 5 itemek ;) Ale z szansa też nie głupi pomysł.


Czy teraz jest prawidłowo?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local items = math.random(0000,0001,0002,0003)

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, 'present') or msgcontains(msg, 'present bag')) then
		selfSay('Do you want to change your 20 bags for present?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6497) >= 20) then
				doPlayerRemoveItem(cid, 6497, 20)
				doPlayerAddItem(cid, items)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough bags.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Dawno się nei bawiłem w takie klocki ale ci pomoge :P

Code:
local items = math.random(1,10)
local st = {[1] = 0000, [2] = 0001, [3] = 0002} -- i do 10 ;P
doPlayerAddItem(cid, st[items])

Tam gdzie 0000 itp podajesz id itemkow a tam gzdie [1]-[3] dopisujesz tak do 10 czy tam ilu


Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local items = math.random(1,10)
local st = {0000,0001,0002,0003,0004,0005,0006,0007,0008,0009}

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, 'present') or msgcontains(msg, 'present bag')) then
		selfSay('Do you want to change your 20 bags for present?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6497) >= 20) then
				doPlayerRemoveItem(cid, 6497, 20)
				doPlayerAddItem(cid, st[items])
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough bags.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Nie chodziło mi o szanse tylko poprostu żeby wybierał sobie z jakiś 5 itemek ;) Ale z szansa też nie głupi pomysł.


Czy teraz jest prawidłowo?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local items = math.random(0000,0001,0002,0003)

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, 'present') or msgcontains(msg, 'present bag')) then
		selfSay('Do you want to change your 20 bags for present?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6497) >= 20) then
				doPlayerRemoveItem(cid, 6497, 20)
				doPlayerAddItem(cid, items)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough bags.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		
	return true
end

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

No ok ale dzięki temu możesz sobie ustawić że słabsze nagrody będą dawane częściej niż jakieś cenne, domyślam się że nagród nie będzie dużo więc dodatkowe kilka linijek kodu nie powinno w niczym przeszkadzać a można dzięki temu bardziej zachęcić graczy cennymi nagrodami.
 
No to mam nadzieje że to:

NPC wyemieniający itemy final v6 by Jakubek :huh: xD


Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local items = math.random(1,3)
local st = {[1] = 0000, [2] = 0001, [3] = 0002} -- Może na początek 3 xD

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, 'present') or msgcontains(msg, 'present bag')) then
		selfSay('Do you want to change your 20 bags for present?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6497) >= 20) then
				doPlayerRemoveItem(cid, 6497, 20)
				doPlayerAddItem(cid, st[items])
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough bags.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I teraz mogę walnąć głupotę bo nie jestem do końca pewien ale

local items = math.random(1,3)
local st = {[1] = 0000, [2] = 0001, [3] = 0002} -- Może na początek 3 xD

powinieneś wkleić pod funkcją a nie nad ponieważ losowanie odbywało się będzie przy starcie serwera i wynik losowania będzie zawsze taki sam (pisząc to wydaje mi się że nie mam raczej racji ;) )
 
Kurwa :D Miałbyć final version :D Poczekam aż ktoś się jeszcze wypowie, ale dzięki za angaż ;)

Nie to nie już nie pomagam.

Ale tak szczerze to jestem ciekaw czy będzie tak jak mówiłem wyżej czy tylko mi się coś w głowie uroiło.
 
Jejku przepraszam :* Własnie testuje to zaraz Edit post.


EDIT:

Próbowałem już zamykać endami i nie chce mi śmigać coś jest nie domknięte :/

Code:
[29/03/2010 20:06:43] [Error - LuaScriptInterface::loadFile] data/npc/scripts/Sell/event.lua:35: 'end' expected (to close 'function' at line 13) near 'elseif'
[29/03/2010 20:06:43] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Sell/event.lua
[29/03/2010 20:06:43] data/npc/scripts/Sell/event.lua:35: 'end' expected (to close 'function' at line 13) near 'elseif'
[29/03/2010 20:06:43] [Error - LuaScriptInterface::loadFile] data/npc/scripts/Sell/event.lua:35: 'end' expected (to close 'function' at line 13) near 'elseif'
[29/03/2010 20:06:43] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Sell/event.lua
[29/03/2010 20:06:43] data/npc/scripts/Sell/event.lua:35: 'end' expected (to close 'function' at line 13) near 'elseif'
[29/03/2010 20:06:43] [Error - LuaScriptInterface::loadFile] data/npc/scripts/Sell/event.lua:35: 'end' expected (to close 'function' at line 13) near 'elseif'
[29/03/2010 20:06:43] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Sell/event.lua

Event.lua

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local items = math.random(1, 100)
local st = {[1] = 2160, [2] = 2148, [3] = 8888} -- Może na początek 3 xD

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, 'present') or msgcontains(msg, 'present bag')) then
		selfSay('Do you want to change your 20 bags for present?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6497) >= 20) then
				doPlayerRemoveItem(cid, 6497, 20)
				doPlayerAddItem(cid, st[items])
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough bags.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
		elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
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...
 
Back
Top