• 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, Change gold

Zombiexon

Member
Joined
Mar 12, 2011
Messages
220
Reaction score
7
Location
/home/var/
Witam,

Mam mały problem otóż kiedy pisze do NPC , podczas rozmowy wywala mi 2x komunikat 1
i dostaje tylko 1 platinium coina.

PHP:
17:16 Tester: hi
17:16 Eva: Welcome Tester! What can I do for you?
17:16 Tester: change gold
17:16 Eva: How many platinum coins would you like to get?
17:16 Tester: 3
17:16 Eva: So you would like me to change 3 of your platinum coins into 300 gold coins?
17:16 Tester: yes
17:16 Eva: So you would like me to change 0 of your platinum coins into 0 gold coins?
17:17 Eva: Good bye.


Skrypt:
PHP:
local difference = 1
local typeToChange = ""
local newType = ""
local multiplier = 1
local count = 0
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 greetCallback(cid)
	-- Resetting talkState[talkUser]
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	talkState[talkUser] = 0
    return true
end

function getCountChangeGold(msg)
	-- made by Jiddo?
	local ret = 0
	local b, e = string.find(msg, "%d+")
	if b ~= nil and e ~= nil then
		ret = tonumber(string.sub(msg, b, e))
	end	
	return ret
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 creatureSayCallback (cid, type, msg)
	
	if(npcHandler.focus ~= cid) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
	if msgcontains(msg, 'time') then
		selfSay('It is exactly ' .. getWorldTime() .. '.')
	end
	
	if(msgcontains(msg, "change gold") or msgcontains(msg, "platinium coin")) then
		npcHandler:say("How many platinum coins would you like to get?",cid)
		talkState[talkUser] = 1
	
	elseif talkState[talkUser] == 1 then
	  if talkState[talkUser] == 1 then
			count = getCountChangeGold(msg)
			typeToChange = "platinum"
			newType = "gold"
			multiplier = 100	
			difference = 1	
			gold1 =count*multiplier
			gold2 =count*difference
			selfSay('So you would like me to change '.. count*difference ..' of your '.. typeToChange ..' coins into '.. count*multiplier ..' '.. newType ..' coins?')
			talkState[talkUser] = 1
			
		 if(msgcontains(msg, "yes") and talkState[talkUser] == 1) then
		   if doPlayerRemoveItem(cid,2148,gold1) == TRUE then -- edit the amount of gold here
		    doPlayerAddItem(cid,2152,gold2)
			talkState[talkUser] = 0
		   else
			selfSay('You don\'t have enough '.. typeToChange ..' coins.')
			talkState[talkUser] = 0
		   end
          		   
		 
		  end
	   end
			
	elseif(talkState[talkUser] == 1) then
	npcHandler:say("Not good enough, eh? What else can I do for you?", cid)
	talkState[talkUser] = 0
	
	end
	
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Wie ktoś może o co be?;p
 
Nie wiem o co be, ale wiem o co cho. Mianowicie NPC jest fe, trzeba poszukać nowego se.
 
Nie, to Ty masz jesli nie rozumiesz co napisal.
Najpierw pomysl.
Poprostu masz zbugowanego NPC wez orginal z TFS.
 
@slawkens , tak wiem masz inteligencje bakterii.

A ty masz pierdolca, skoro nie potrafisz nawet docenić tego że ktoś usiłuje ci pomóc. Czytanie ze zrozumieniem się kłania mistrzu.

@edit
Wybaczam, poznaj moją drugą, dobrą stronę : } pozdro.
 
Last edited:
@slawkens , Soory stary , ale trochę zły dzień a jeśli jeszcze ktoś pisze do mnie "Mianowicie NPC jest fe, trzeba poszukać nowego se." to n/c nie miałem zamiaru nikogo obrażać ale trochę inaczej wyszło; P sorka.

@Wymietek , Stary, nie wezmę npc z TFS'a na Tibię 7.4 bo nie będą pasować, po 2 npc nie jest zbugowany tylko miał mylne warunki , po 3 dużo nie mówi mi o błędzie "Mianowicie NPC jest fe, trzeba poszukać nowego se." a ja właśnie pytam o błąd a nie nowego npc. Osobiście już go napisałem .

Temat do zamknięcia.
 
Back
Top