jestemPolakiem
New Member
Cash Machinet
by jestemPolakiem
by jestemPolakiem
script has been tested on The Forgotten Server 0.3.6pl1 and worked
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: