• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC NPC That changes gold for platinum coins.

rockseller

Lua & .NET Programmer
Joined
May 10, 2008
Messages
159
Reaction score
9
Location
México
What's up Otland.


I've a question about this kind of NPC, i'm wondering if someone has this script?, i found this one:

Code:
-- Change Gold NPC, includes banking functions except transfer
-- Made by Ispiro.
-- Credits to Colex for some of the banker functions
-- Credits to Jiddo for getCount function
-- Credits to Sapphire for some fixes

local focus = 0
local talk_start = 0
local talk_state = 0
-- change gold variables
local difference = 1
local typeToChange = ""
local newType = ""
local multiplier = 1
local count = 0
-- banker
local name = ""
local amountToHandle = 0

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
	if focus == cid then
		selfSay('Good bye then.')
		focus = 0
		talk_state = 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)
	if focus == 0 then
		if (msgcontains(msg, 'hi')) and getDistanceTo(cid) < 4 then
			focus = cid
			talk_start = os.clock()	
			name = getPlayerName(cid)
			selfSay('Welcome ' .. name .. '! Daraman\'s blessings.')	
		end	
	elseif focus == cid then
		talk_start = os.clock()
		if talk_state > 0 then
			if talk_state >= 2 and talk_state <= 6 then
				count = getCountChangeGold(msg)
				if talk_state == 3 then	
					if (msgcontains(msg, 'gold')) then
						talk_state = 5
						selfSay('How much platinums would you like to change?')
					elseif (msgcontains(msg, 'crystal')) then	
						talk_state = 6	
						selfSay('How many crystal would you like to get?')							
					else
						talk_state = 0
						selfSay('Well, can I help you with something else?')
					end		
				elseif count ~= 0 then
					if talk_state == 2 then
						typeToChange = "gold"
						newType = "platinum"
						difference = 100
						multiplier = 1
					
					elseif talk_state == 4 then	
						typeToChange = "crystal"
						newType = "platinum"	
						multiplier = 100	
						difference = 1		
					elseif talk_state == 5 then	
						typeToChange = "platinum"
						newType = "gold"
						multiplier = 100	
						difference = 1		
					elseif talk_state == 6 then	
						typeToChange = "platinum"
						newType = "crystal"	
						multiplier = 1	
						difference = 100							
					end
					if(talk_state <= 6 and talk_state >= 2) then
						selfSay('So you would like me to change '.. count*difference ..' of your '.. typeToChange ..' coins into '.. count*multiplier ..' '.. newType ..' coins?')	
						talk_state = 7
					end	
				end			
			elseif talk_state == 7 then
				if (msgcontains(msg, 'yes')) then
					local haveEnough = changeGold(cid, count, typeToChange, newType, difference, multiplier)
					if haveEnough ~= 0 then
						selfSay('Here you are.')
					else
						selfSay('You don\'t have enough '.. typeToChange ..' coins.')				
					end
				else
					selfSay('Well, can I help you with something else?')
				end	
				talk_state = 0
			elseif talk_state > 7 then
			-- banker functions
				if (talk_state == 8) then -- deposit all
					if(msgcontains(msg, 'yes')) then
						local depmoney = depositAllMoney(name)
						selfSay('You have safely deposited '.. depmoney ..' gold coins into your account.')
					else
						selfSay('Maybe later.')
					end					
					talk_state = 0
				elseif (talk_state == 9) then  -- deposit certain amount	
					amountToHandle = getCountChangeGold(msg)
					if(amountToHandle > 0) then
						selfSay('Do you want to deposit '.. amountToHandle ..' gold coins?')
						talk_state = 12
					else
						selfSay('Maybe later...')
						talk_state = 0
					end
				elseif (talk_state == 12) then  -- deposit certain amount
					if(msgcontains(msg, 'yes')) then
						if(doPlayerRemoveMoney(cid, amountToHandle) == TRUE) then
							local playerMoney = getAmountOfMoney(name)
							changeMoney(name, playerMoney + amountToHandle)
							selfSay('Your money has been deposited safely.')
						else
							selfSay('You do not have that much money.')
						end	
					else
						selfSay('Maybe later...')
					end
					talk_state = 0				
				elseif talk_state == 13 then  -- deposit certain amount	
					amountToHandle = getCountChangeGold(msg)
					if(amountToHandle > 0) then
						selfSay('Would you like to withdraw '.. amountToHandle ..' gold?')
					else
						selfSay('Maybe Later...')
					end	
					talk_state = 14	
				elseif (talk_state == 14) then  -- deposit certain amount	
					if(msgcontains(msg, 'yes')) then
						local playerMoney = getAmountOfMoney(name)
						if(playerMoney >= amountToHandle) then
							changeMoney(name, playerMoney - amountToHandle)
							addMoney(cid, amountToHandle)
							selfSay('Here you go.')
						else
							selfSay('You do not have that much money in your balance.')
						end
					else
						selfSay('Maybe later...')
					end	
					talk_state = 0						
				end	
					
			end		
			
		else
			if (msgcontains(msg, 'hi')) then
				selfSay('I\'m already talking to you!')	
				
			elseif (msgcontains(msg, 'offer')) then
				selfSay('We can change money for you. ')
				
			elseif ((msgcontains(msg, 'bye')) and (focus == cid))then
				selfSay('Daraman\'s blessings. ')	
				focus = 0
				talk_state = 0	
			elseif (msgcontains(msg, 'change gold')) then -- 1
				selfSay('How many platinum coins would you like to get?')
				talk_state = 2
			elseif (msgcontains(msg, 'change platinum')) then -- 2
				selfSay('Do you want to get gold or crystal coins?')
				talk_state = 3
			elseif (msgcontains(msg, 'change crystal')) then
				selfSay('How many crystal coins would you like to change to platinum?')
				talk_state = 4	
			elseif (msgcontains(msg, 'balance')) then
				selfSay('You have '.. getAmountOfMoney(getPlayerName(cid)) ..' gold coins in your balance.')
			elseif (msgcontains(msg, 'deposit all')) then
				selfSay('Would you like to deposit all your money?')	
				talk_state = 8	
			elseif (msgcontains(msg, 'deposit')) then
				amountToHandle = getCountChangeGold(msg)
				if(amountToHandle > 0) then
					talk_state = 12
					selfSay('Do you want to deposit '.. amountToHandle ..' gold coins?')		
				else
					selfSay('How much gold coins do you wish to deposit?')		
					talk_state = 9
				end	
			elseif (msgcontains(msg, 'withdraw')) then
				amountToHandle = getCountChangeGold(msg)
				if(amountToHandle > 0) then
					selfSay('Would you like to withdraw '.. amountToHandle ..' gold?')	
					talk_state = 14
				else
					selfSay('How much do you wish to withdraw?')
					talk_state = 13
				end				
			-- transfer will be added when it's 						
			end
		end
	end	
end


function onCreatureChangeOutfit(creature)

end

function onThink()
	doNpcSetCreatureFocus(focus)
	if(focus ~= 0) then
		if (os.clock() - talk_start) > 40 then
  			selfSay('Next Please...')
			focus = 0
			talk_state = 0
  		elseif getDistanceTo(focus) > 5 then
 			selfSay('Good bye then.')
			focus = 0
			talk_state = 0
 		end
 	end
end

function changeGold(cid, count, typeToChange, newType, difference, multiplier)
-- Made by Ispiro
	local countToChange = 0
	local goldType = 0	
	local newGoldType = 0
	local gpstogive = count*multiplier
	
	if typeToChange == "platinum" then		
		goldType = 2152
	elseif typeToChange == "gold" then
		goldType = 2148
	elseif typeToChange == "crystal" then
		goldType = 2160
	else
		return 0	
	end
	
	countToChange = getPlayerItemCount(cid, goldType)
	if countToChange >= count*difference then
		if newType == "platinum" then
			newGoldType = 2152
		elseif newType == "gold" then
			newGoldType = 2148
		elseif newType == "crystal" then
			newGoldType = 2160
		else
			return 0
		end	
		doPlayerRemoveItem(cid, goldType, count*difference)
		while gpstogive > 100 do
			gpstogive = gpstogive - 100
			doPlayerAddItem(cid, newGoldType, 100)
		end
		doPlayerAddItem(cid, newGoldType, gpstogive)
		return countToChange
	end
	return 0
end

function changeMoney(name, newMoney)
	local file = io.open("data/bank/"..name..".dat", "w")
	file:write("" .. newMoney .. "")
	file:close()
	return 1
end

function getAmountOfMoney(name)
	local file = io.open("data/bank/"..name..".dat", "r")
	if file == nil then 
		changeMoney(name, 0) 
		return 0
	end
	local x = file:read("*number")
	file:close()
	return x
end

function getPlayerMoney(cid)
	local crystalcoins = getPlayerItemCount(cid, 2160)*10000
	local platinumcoins = getPlayerItemCount(cid, 2152)*100
	local goldcoins = getPlayerItemCount(cid, 2148)
	return crystalcoins + platinumcoins + goldcoins
end

function depositAllMoney(name)
	local money = getPlayerMoney(getPlayerByName(name))
	local amountMoneyBank = getAmountOfMoney(name)
	changeMoney(name, amountMoneyBank + money)
	doPlayerRemoveMoney(getPlayerByName(name), money)
	return money
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 addMoney(cid, gpsrewarded)
	-- Made by Ispiro
	local crystalcoins = 0
	local platinumcoins = 0
	local goldcoins = 0	
	
	while gpsrewarded >= 10000 do 
		crystalcoins = crystalcoins + 1 
		gpsrewarded = gpsrewarded - 10000
	end
	while gpsrewarded >= 100 do
		platinumcoins = platinumcoins + 1 
		gpsrewarded = gpsrewarded - 100 
	end
	while gpsrewarded >= 1 do 
		goldcoins = goldcoins + 1
		gpsrewarded = gpsrewarded - 1 
	end
	doPlayerAddItemIspiro(cid, 2148, goldcoins)
	doPlayerAddItemIspiro(cid, 2152, platinumcoins)
	while(crystalcoins > 100) do
			doPlayerAddItemIspiro(cid, 2160, 100)
			crystalcoins = crystalcoins - 100
	end
	doPlayerAddItemIspiro(cid, 2160, crystalcoins)	
end

function doPlayerAddItemIspiro(cid, itemid, count)
	while(count > 100) do
		doPlayerAddItem(cid, itemid, 100)
		count = count - 100
	end
	doPlayerAddItem(cid, itemid, count)

end


Wich is good, but is there a way to delete the BANK thing and leave the change gold function alone?

Thanks in advice!!


By the way, i can disable the Change gold function of right clic, in actions file right?
 
Wich is good, but is there a way to delete the BANK thing and leave the change gold function alone?
Jup just delete the changegold.lua file on: data\actions\scripts(\other) if you use mystic spirit.

In actions.xml you delete this:
Code:
	<action itemid="2148" script="other/changegold.lua"/>
	<action itemid="2152" script="other/changegold.lua"/>
	<action itemid="2160" script="other/changegold.lua"/>

The npc I will mayby fix tomorrow but I wanna get some rest ;)
 
Jup just delete the changegold.lua file on: data\actions\scripts(\other) if you use mystic spirit.

In actions.xml you delete this:
Code:
	<action itemid="2148" script="other/changegold.lua"/>
	<action itemid="2152" script="other/changegold.lua"/>
	<action itemid="2160" script="other/changegold.lua"/>

The npc I will mayby fix tomorrow but I wanna get some rest ;)

Thanks alot mate :) will be waiting for your help
 
Bump

Please somebody out there, i just need the npc that changes gold/plat/crystal
 
Back
Top