• 01-04.05.2026 - DOUBLE EXP / SKILL EVENT!

Skrypty & Kody Npc skupujacy 2 itemy

Superasny

User
Zarejestrowany
Dołączył
Lipiec 18, 2010
Posty
39
Liczba reakcji
0
Witam. Potrzebuje npc ktory za 2 itemy daje mi 1 np za "spell book" oraz "bone shield" otrzymuje "tear of daraman". Bawilem sie z tym skryptem ale nie sprawdza czy gracz ma 2 itemy i wystarczy jedna z wyzej wymienionych by npc oddal "tear". Zamieszczam kod mam nadzieje ze ktos bedzie w stanie wskazac gdzie poplenilem b?ad.
Kod:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
talk_state = 0
cname = ''

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('.')
          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, 'aqua vitae') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('...' .. creatureGetName(cid) .. '!...')
		talk_state = 0
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'aqua vitae') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('...')
		
	elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
		selfSay('...')
		talk_state = 0
		focus = 0
		talk_start = 0

	elseif focus == cid then
		talk_start = os.clock()
	

		if talk_state == 0 then
			if msgcontains(msg, 'firmo') then
			
				itemstatus = doPlayerRemoveItem(cid,2175)
				itemstatus2 = doPlayerRemoveItem(cid,2541)
 
					
				if itemstatus and itemstatus2 == -1 then
					selfSay('...')
				else
					buy(cid,2346,1,0) 
                    selfSay('renovatio!')
				end
			elseif msgcontains(msg, 'redhibeo') then
				selfSay('/send ' .. creatureGetName(cid) .. ', 1868 716 7')
				else
  				selfSay('.')
 				talk_state = 0
 			end
 			end
		end
	end


 

function onCreatureChangeOutfit(creature)

end


function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('...')
 			focus = 0
 		end
 	end
end
z Gory dziekuje.
 
Odp: Npc skupujacy 2 itemy

Jak kiedy? bawi?em si? to zrobi?em d?wignie, ?e za 2 itemki daje jeden. Ale w sumie NPC wygodniejszy. Te? czekam :)
 
Odp: Npc skupujacy 2 itemy

sprawdz to, nie testowane ;d
[LUA]focus = 0
talk_start = 0
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Dowidzenia.')
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 ((string.find(msg, '(%a*)hi(%a*)')
or string.find(msg, '(%a*)siema(%a*)')
or string.find(msg, '(%a*)czesc(%a*)')
or string.find(msg, '(%a*)cze(%a*)')
or string.find(msg, '(%a*)yo(%a*)')
or string.find(msg, '(%a*)elo(%a*)'))
and (focus == 0)) and getDistanceToCreature(cid) < 4 then

rsay = math.random(1,4)
if rsay == 1 then says = 'Waazzuup'
elseif rsay == 2 then says = 'Siema'
elseif rsay == 3 then says = 'Czesc'
elseif rsay == 4 then says = 'Witam'
end


selfSay('Witaj ' .. creatureGetName(cid) .. ', czy chcesz zamienic przedmioty? --tak--')
focus = cid
talk_start = os.clock()
end

if string.find(msg, '(%a*)hi(%a*)') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Spadaj ' .. creatureGetName(cid) .. ' do kolejki.')
end

if msgcontains(msg, 'tak') and focus == cid then
selfSay('W takim razie przynies mi bone shield oraz spellbook a otrzymasz cos specjalnego. --oddaj--')
talk_start = os.clock()
end

if msgcontains(msg, 'oddaj') and focus == cid then
talk_start = os.clock()

itemstatus = doPlayerRemoveItem(cid,2175)
itemstatus2 = doPlayerRemoveItem(cid,2541)

if itemstatus and itemstatus2 == -1 then
selfSay('nie masz przedmiotow.')
else
buy(cid,2346,1,0)
selfSay('Dziekuje bardzo.')
end
end

if string.find(msg, '(%a*)bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 4 then
selfSay('Narazie, ' .. creatureGetName(cid) .. '!')
focus = 0
talk_start = 0
end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
if (os.clock() - talk_start) > 3 then
if focus > 0 then
selfSay('Kto nastepny?')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Narazie Ziomek.')
focus = 0
end
end
if focus == 0 then
cx, cy, cz = selfGetPosition()
randmove = math.random(1,20)
if randmove == 1 then
nx = cx + 1
end
if randmove == 2 then
nx = cx - 1
end
if randmove == 3 then
ny = cy + 1
end
if randmove == 4 then
ny = cy - 1
end
if randmove >= 5 then
nx = cx
ny = cy
end
moveToPosition(nx, ny, cz)
--summons = 30
--summons2 = 30
end
end[/LUA]
 
Odp: Npc skupujacy 2 itemy

Niestety dalej nie dziala. Co prawda daje nam item. Z tym ze nie wymaga od nas 2 itemow. Wystarczy ze masz 1 i tez sie wykona.
 
Odp: Npc skupujacy 2 itemy

sprawdz teraz to.
[LUA]focus = 0
talk_start = 0
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Dowidzenia.')
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 ((string.find(msg, '(%a*)hi(%a*)')
or string.find(msg, '(%a*)siema(%a*)')
or string.find(msg, '(%a*)czesc(%a*)')
or string.find(msg, '(%a*)cze(%a*)')
or string.find(msg, '(%a*)yo(%a*)')
or string.find(msg, '(%a*)elo(%a*)'))
and (focus == 0)) and getDistanceToCreature(cid) < 4 then

rsay = math.random(1,4)
if rsay == 1 then says = 'Waazzuup'
elseif rsay == 2 then says = 'Siema'
elseif rsay == 3 then says = 'Czesc'
elseif rsay == 4 then says = 'Witam'
end


selfSay('Witaj ' .. creatureGetName(cid) .. ', czy chcesz zamienic przedmioty? --tak--')
focus = cid
talk_start = os.clock()
end

if string.find(msg, '(%a*)hi(%a*)') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Spadaj ' .. creatureGetName(cid) .. ' do kolejki.')
end

if msgcontains(msg, 'tak') and focus == cid then
selfSay('W takim razie przynies mi bone shield oraz spellbook a otrzymasz cos specjalnego. --oddaj--')
talk_start = os.clock()
end

if msgcontains(msg, 'oddaj') and focus == cid then
talk_start = os.clock()

if (getPlayerItem(cid,2175) < 1 or getPlayerItem(cid,2541) < 1) then
selfSay('nie masz itemow.')
else
buy(cid,2346,1,0)
doPlayerRemoveItem(cid, 2175)
doPlayerRemoveItem(cid, 2541)
end
end

if string.find(msg, '(%a*)bye(%a*)') and focus == cid and getDistanceToCreature(cid) < 4 then
selfSay('Narazie, ' .. creatureGetName(cid) .. '!')
focus = 0
talk_start = 0
end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
if (os.clock() - talk_start) > 3 then
if focus > 0 then
selfSay('Kto nastepny?')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Narazie Ziomek.')
focus = 0
end
end
if focus == 0 then
cx, cy, cz = selfGetPosition()
randmove = math.random(1,20)
if randmove == 1 then
nx = cx + 1
end
if randmove == 2 then
nx = cx - 1
end
if randmove == 3 then
ny = cy + 1
end
if randmove == 4 then
ny = cy - 1
end
if randmove >= 5 then
nx = cx
ny = cy
end
moveToPosition(nx, ny, cz)
--summons = 30
--summons2 = 30
end
end[/LUA]
 
Ostatnia edycja:
Odp: Npc skupujacy 2 itemy

Tym razem nie przyjmuje wgl nic i nic nie daje. Natomiast na silniku wywala b?ad
NpcScript: onCreatureSay: lua error: data/npc/scripts/studnia3.lua:71: attempt to call global 'getPlayerItem' (a nil value)
Backtrace
 
Odp: Npc skupujacy 2 itemy

brak funkcji w source getPlayerItem, masz dostep do source? to podesle Ci kod
 
Odp: Npc skupujacy 2 itemy

Yurek to oporna...hmm... mashyna ;)

reeeq dobrze kombinowa? jednak Yurki nie posiadaj? takiej funkcji.
Potrzebujesz funkcji kt?ra sprawdzi czy gracz posiada item a oraz item b w tej samej chwili (w postaci takiej jakiej jest teraz, skrypt sprawdzi zawsze tylko item a albo item b)

Napisa?em Ci funkcj? kt?ra sprawdzi dwa konkretne itemy u gracza i wtedy doda mu przedmiot jako nagrod? usuwaj?c w tym samym momencie te dwa wymagane.

w npc.cpp pod
pod
[CPP]lua_register(luaState, "selfGetPosition", NpcScript::luaSelfGetPos);[/CPP]
dodaj
[CPP]lua_register(luaState, "zamienDwaItemy", NpcScript::luaZamienDwaItemy);[/CPP]

na ko?cu pliku npc.cpp dodaj
[CPP]int NpcScript::luaZamienDwaItemy(lua_State *L)
{
int nagrodacount = (int)lua_tonumber(L, -1);
int nagroda = (int)lua_tonumber(L, -2);
int count2 = (int)lua_tonumber(L, -3);
int itemid2 = (int)lua_tonumber(L, -4);
int count = (int)lua_tonumber(L, -5);
int itemid = (int)lua_tonumber(L, -6);
int cid = (int)lua_tonumber(L, -7);
lua_pop(L,5);

Npc* mynpc = getNpc(L);
Creature* creature = mynpc->game->getCreatureByID(cid);
Player* player = creature? dynamic_cast<Player*>(creature) : NULL;

if (player && player->getItem(itemid, count) && player->getItem(itemid2, count2))
{
player->removeItem(itemid, count);
player->removeItem(itemid2, count2);
player->TLMaddItem(nagroda, nagrodacount);
return 1;
}
else
{
return 0;
}

}[/CPP]

oraz w npc.h pod
[CPP]static int luaSelfGetPos(lua_State *L);[/CPP]
dodaj
[CPP]static int luaZamienDwaItemy(lua_State *L);[/CPP]

Przebuduj projekt.

a oto tw?j poprawiony skrypt NPC Lua:
[LUA]focus = 0
talk_start = 0
target = 0
following = false
attacking = false
talk_state = 0
cname = ''

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('.')
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, 'aqua vitae') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
selfSay('...' .. creatureGetName(cid) .. '!...')
talk_state = 0
focus = cid
talk_start = os.clock()

elseif msgcontains(msg, 'aqua vitae') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('...')

elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
selfSay('...')
talk_state = 0
focus = 0
talk_start = 0

elseif focus == cid then
talk_start = os.clock()


if talk_state == 0 then
if msgcontains(msg, 'firmo') then

sprawdzItemy = zamienDwaItemy(cid,2175,1,2541,1,2346,1)


if sprawdzItemy then
selfSay('renovatio!')
else
selfSay('Nie posiadasz tych przedmiotow!')
end
elseif msgcontains(msg, 'redhibeo') then
selfSay('/send ' .. creatureGetName(cid) .. ', 1868 716 7')
else
selfSay('.')
talk_state = 0
end
end
end
end




function onCreatureChangeOutfit(creature)

end


function onThink()
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('...')
focus = 0
end
end
end[/LUA]

Legenda:
Kod:
zamienDwaItemy(cid,2175,1,2541,1,2346,1)
2175,1 - ID pierwszego przedmiotu i jego liczba
2541,1 - ID drugiego przedmiotu i jego liczba
2346,1 - ID nagrody


Pozdrawiam, Zark.
 
Odp: Npc skupujacy 2 itemy

A si? z tym bawicie:

[LUA]if(doPlayerRemoveItem(cid, item1, icount ) == TRUE and doPlayerRemoveItem(cid, item2, i2count) == TRUE then[/LUA]
 
Odp: Npc skupujacy 2 itemy

Hmm nie ukrywam ze skrypt pewnie dziala. Z tym ze mam problem ze znalezieniem pliku npc.cpp w moim "looziku" jedyne co udalo mi sie znalezsc to npc.lua ale nie umiem sie doszukac tych linijek
Kod:
 -- get the distance to a creature
 function getDistanceToCreature(id)
 	if id == 0 or id == nil then
 		selfGotoIdle()
 	end
 	cx, cy, cz = creatureGetPosition(id)
 	if cx == nil then
 		return nil
 	end
 	sx, sy, sz = selfGetPosition()
 	return math.max(math.abs(sx-cx), math.abs(sy-cy))	
 end
 
 -- do one step to reach position
 function moveToPosition(x,y,z)
 	selfMoveTo(x, y, z)
 end
 
 -- do one step to reach creature
 function moveToCreature(id)
 	if id == 0 or id == nil then
 		selfGotoIdle()
 	end
 	tx,ty,tz=creatureGetPosition(id)
 	if tx == nil then
 		selfGotoIdle()
 	else
 	   moveToPosition(tx, ty, tz)
    end
 end
 
 function selfGotoIdle()
 		following = false
 		attacking = false
 		selfAttackCreature(0)
 		target = 0
 end

Jeszcze zobacze kod od Avari

Kod:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
talk_state = 0
cname = ''

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('.')
          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, 'aqua vitae') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('...' .. creatureGetName(cid) .. '!...')
		talk_state = 0
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'aqua vitae') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('...')
		
	elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
		selfSay('...')
		talk_state = 0
		focus = 0
		talk_start = 0

	elseif focus == cid then
		talk_start = os.clock()
	

		if talk_state == 0 then
			if msgcontains(msg, 'firmo') then
 
					
				if doPlayerRemoveItem(cid,2175,1) == TRUE and doPlayerRemoveItem(cid,2541,1) == TRUE then
									buy(cid,2346,1,0) 
					selfSay('renovatio!')
				else
                    selfSay('dupa!')
				end
			elseif msgcontains(msg, 'redhibeo') then
				selfSay('/send ' .. creatureGetName(cid) .. ', 1868 716 7')
				else
  				selfSay('.')
 				talk_state = 0
 			end
 			end
		end
	end


 

function onCreatureChangeOutfit(creature)

end


function onThink()
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('...')
 			focus = 0
 		end
 	end
end
niestety tez lipa ;/
 
Ostatnia edycja:
Odp: Npc skupujacy 2 itemy

Co robi [LUA]buy(cid,2346,1,0) [/LUA]?
Bo szczerze 1 raz widze tak? funkcje.

?eby da? item to musisz da?:
[LUA]doPlayerAddItem(cid,id,ilo??)[/LUA]
 
Odp: Npc skupujacy 2 itemy

Co robi [LUA]buy(cid,2346,1,0) [/LUA]?
Bo szczerze 1 raz widze tak? funkcje.

?eby da? item to musisz da?:
[LUA]doPlayerAddItem(cid,id,ilo??)[/LUA]

tego skryptu [LUA]buy(cid,2346,1,0) [/LUA] uzywalem zwykle do npc sprzedajacych nam itemy czyli [LUA]buy(cid,id itemu,ilosc,cena) [/LUA]
 
Back
Do góry