• 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 Cash Machine

jestemPolakiem

New Member
Joined
Oct 17, 2009
Messages
48
Reaction score
2
Location
Poland
Cash Machinet
by jestemPolakiem

script has been tested on The Forgotten Server 0.3.6pl1 and worked

mapaw.png


Code:
[B]To use the script, just use start talking with NPC.[/B]
WELCOME TO THE WOLRD BANKING SYSTEM!

data/npc/Cash Machine.xml
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Cash Machine" script="cashmachine.lua" floorchange="0" walkinterval="0">
	<health now="500" max="500"/>
	<look typeex="11136"/>
</npc>

data/npc/scripts/cashmachine.lua
PHP:
local keywordHandler             			= KeywordHandler:new() 
local npcHandler                 			= NpcHandler:new(keywordHandler) 
NpcSystem.parseParameters(npcHandler) 
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 
NpcHandler:setMessage(MESSAGE_GREET, "WELCOME TO THE WOLRD BANKING SYSTEM!")

function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid 
    if (not npcHandler:isFocused(cid)) then 
        return false 
    end
	if (getPlayerItemCount(cid, 6387) == 0) then
		return npcHandler:say("YOU DO NOT HAVE A CREDIT CARD.", cid)
	end
	if (msgcontains(msg, "help")) then
		npcHandler:say("HELP CENTER :\n"..
		"» {balance} CHECKS THE STATUS OF YOUR ACCOUNT\n"..
		"» {deposit} ALLOWS YOU TO MAINTAIN A CERTAIN AMOUNT OF MONEY IN THE BANK\n"..
		"» {deposit all} ALLOW TO PRESERVATION OF THE ENTIRE SUM OF MONEY IN THE BANK\n"..
		"» {withdraw} CHOOSE ANY AMOUNT OF MONEY FROM THE BANK\n", cid)
		talkState[talkUser] = 0
	elseif (talkState[talkUser] == 10) then
		if (tonumber(msg) > 0) then
			if (getPlayerMoney(cid) >= tonumber(msg)) then
				npcHandler:say("SAVE "..tonumber(msg).." GP IN A BANK.", cid)
				doPlayerDepositMoney(cid, tonumber(msg))
				talkState[talkUser] = 0
			else
				npcHandler:say("YOU DO NOT HAVE SUCH A SUM", cid)
				talkState[talkUser] = 0
			end
		else
			npcHandler:say("NOT THE CORRECT NUMBER.", cid)
			talkState[talkUser] = 0
		end
	elseif (talkState[talkUser] == 20) then
		if (tonumber(msg) > 0) then
			if (getPlayerBalance(cid) >= tonumber(msg)) then
				npcHandler:say("RESTORE "..tonumber(msg).." GP IN A BANK.", cid)
				doPlayerWithdrawMoney(cid, tonumber(msg))
				talkState[talkUser] = 0
			else
				npcHandler:say("YOU DO NOT HAVE SUCH A SUM", cid)
				talkState[talkUser] = 0
			end
		else
			npcHandler:say("NOT THE CORRECT NUMBER.", cid)
			talkState[talkUser] = 0
		end
	elseif (msgcontains(msg, "deposit all")) then
		npcHandler:say("SAVE "..getPlayerMoney(cid).." GP IN A BANK.", cid)
		doPlayerDepositAllMoney(cid)
	elseif (msgcontains(msg, "deposit")) then
		npcHandler:say("PLEASE ENTER THE AMOUNT", cid)
		talkState[talkUser] = 10
	elseif (msgcontains(msg, "balance")) then
		npcHandler:say("THE CURRENT STATUS OF YOUR ACCOUNT IS "..getPlayerBalance(cid).." GP.", cid)
		talkState[talkUser] = 0
	elseif (msgcontains(msg, "withdraw")) then
		npcHandler:say("PLEASE ENTER THE AMOUNT", cid)
		talkState[talkUser] = 20
	end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

data/items/items.xml - add before </items>
PHP:
<item id="6387" override="yes" article="a" name="bank card">
	<attribute key="weight" 	 value="50" />
	<attribute key="writeable"   value="0" />
</item>



Greets
jestemPolakiem
 
Last edited:
It's writing everything with capital letters, lol , that's annoying^^


Code:
local keywordHandler                         = KeywordHandler:new()  
local npcHandler                             = NpcHandler:new(keywordHandler)  
NpcSystem.parseParameters(npcHandler)  
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  
NpcHandler:setMessage(MESSAGE_GREET, "Welcome to the world banking system!") 

function creatureSayCallback(cid, type, msg) 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid  
    if (not npcHandler:isFocused(cid)) then  
        return false  
    end 
    if (getPlayerItemCount(cid, 6387) == 0) then 
        return npcHandler:say("You do not have a credit card.", cid) 
    end 
    if (msgcontains(msg, "help")) then 
        npcHandler:say("Help center :\n".. 
        "» {balance} checks the status of your account\n".. 
        "» {deposit} allows you to maintain a certain amount of money in the bank\n".. 
        "» {deposit all} allow to preservation of the entire sum of money in the bank\n".. 
        "» {withdraw} choose any amount of money from the bank\n", cid) 
        talkState[talkUser] = 0 
    elseif (talkState[talkUser] == 10) then 
        if (tonumber(msg) > 0) then 
            if (getPlayerMoney(cid) >= tonumber(msg)) then 
                npcHandler:say("SAVE "..tonumber(msg).." gp in the bank.", cid) 
                doPlayerDepositMoney(cid, tonumber(msg)) 
                talkState[talkUser] = 0 
            else 
                npcHandler:say("You do not have such a sum", cid) 
                talkState[talkUser] = 0 
            end 
        else 
            npcHandler:say("Not the correct number.", cid) 
            talkState[talkUser] = 0 
        end 
    elseif (talkState[talkUser] == 20) then 
        if (tonumber(msg) > 0) then 
            if (getPlayerBalance(cid) >= tonumber(msg)) then 
                npcHandler:say("RESTORE "..tonumber(msg).." gp in a bank.", cid) 
                doPlayerWithdrawMoney(cid, tonumber(msg)) 
                talkState[talkUser] = 0 
            else 
                npcHandler:say("You do not have such a sum", cid) 
                talkState[talkUser] = 0 
            end 
        else 
            npcHandler:say("Not the correct number.", cid) 
            talkState[talkUser] = 0 
        end 
    elseif (msgcontains(msg, "deposit all")) then 
        npcHandler:say("SAVE "..getPlayerMoney(cid).." gp in a bank.", cid) 
        doPlayerDepositAllMoney(cid) 
    elseif (msgcontains(msg, "deposit")) then 
        npcHandler:say("Please enter the amount", cid) 
        talkState[talkUser] = 10 
    elseif (msgcontains(msg, "balance")) then 
        npcHandler:say("The current status of your account is "..getPlayerBalance(cid).." gp.", cid) 
        talkState[talkUser] = 0 
    elseif (msgcontains(msg, "withdraw")) then 
        npcHandler:say("Please enter the amount", cid) 
        talkState[talkUser] = 20 
    end 
end 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
All my npcs are now saying welcome to the world of banking system after i add this npc...
 
All my npcs are now saying welcome to the world of banking system after i add this npc...
Code:
[B][COLOR="Red"]n[/COLOR][/B]pcHandler:setMessage(MESSAGE_GREET, "WELCOME TO THE WOLRD BANKING SYSTEM!")
 
Back
Top