focus = 0 talk_start = 0 target = 0 dep = 0 wit = 0 trans = 0 following = false attacking = false gold_id = 2148 plat_id = 2152 crys_id = 2160 function onThingMove(creature, thing, oldpos, oldstackpos) end function onCreatureAppear(creature) end function onCreatureDisappear(cid, pos) if focus == cid then selfSay('Good bye.') focus = 0 talk_start = 0 doNpcSetCreatureFocus(0) end end function onCreatureTurn(creature) end function onCreatureSay(cid, type, msg) msg_org = msg msg = string.lower(msg) nome = getCreatureName(cid) --------------------------------------Begin---------------------------------------------- if (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'yo') or msgcontains(msg, 'elo') or msgcontains(msg, 'witam') or msgcontains(msg, 'cze')) and (focus == 0) and getDistanceToCreature(cid) < 4 then doNpcSetCreatureFocus(cid) dep = 0 wit = 0 trans = 0 selfSay('Witaj w banku ' .. nome .. '! Co moge dla Ciebie zrobic? Wyplacic, wplacic, sprawdzic stan konta, a moze przelac pieniadze na inne konto?') focus = cid talk_start = os.clock() elseif (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'yo') or msgcontains(msg, 'elo') or msgcontains(msg, 'witam') or msgcontains(msg, 'cze')) and (focus ~= cid) and getDistanceToCreature(cid) < 4 then --NPC is talking with other player selfSay('Przepraszam '..nome..', aktualnie rozmawiam z innym klientem.') end --------------------------------------Deposit---------------------------------------------- if dep == 0 then if (msgcontains(msg, 'deposit') or msgcontains(msg, 'wplac')) and (focus == cid) and getDistanceToCreature(cid) < 4 then selfSay('Ile chcesz wplacic na swoje konto?') dep = 1 wit = 0 trans = 0 talk_start = os.clock() end end if dep == 1 then if (focus == cid) and getDistanceToCreature(cid) < 4 then n = getNumber(msg) if n ~= 0 then --player told valid number, higher than 0 talk_start = os.clock() selfSay('Napewno chcesz wplacic '..n..' zlotych monet?') dep = 2 end end end if dep == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then if (msgcontains(msg, 'yes')) then --player want deposit dep = 0 talk_start = os.clock() if doPlayerRemoveMoney(cid, n) == TRUE then --get cash from player backpack setBA(nome,getBA(nome)+n) selfSay('OK, dodalem do Twojego konta '..n..' zlotych monet. Mozesz je wyplacic kiedy chcesz. Twoj stan konta wynosi teraz '..getBA(nome)..'.') else --player doesn't have enought cash in backpack selfSay('Nie masz przy sobie dosc zlota.') end end if (msgcontains(msg, 'no')) then --player doesn't want deposit selfSay('Jak chcesz. Moge cos jeszcze dla Ciebie zrobic?') dep = 0 talk_start = os.clock() end end -------------------------------------------Withdraw--------------------------------------- if wit == 0 then if (msgcontains(msg, 'withdraw')) and (focus == cid) and getDistanceToCreature(cid) < 4 then selfSay('Powiedz ile chcesz wyplacic.') dep = 0 trans = 0 wit = 1 talk_start = os.clock() end end if wit == 1 then if (focus == cid) and getDistanceToCreature(cid) < 4 then n = getNumber(msg) if n ~= 0 then --player told valid number, higher than 0 talk_start = os.clock() selfSay('Napewno chcesz wyplacic '..n..' zlotych monet z swojego konta bankowego?') wit = 2 end end end if wit == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then if (msgcontains(msg, 'yes')) then --player want withdraw wit = 0 talk_start = os.clock() if n <= getBA(nome) then --player has enought cash on account setBA(nome,getBA(nome)-n) --get cash from player account gold = n plat = 0 crys = {} crys[1] = 0 i = 1 --start counting how many crystal, platinum and gold coins NPC should givve repeat if gold >= 100 then plat = plat + 1 gold = gold - 100 end until gold < 100 repeat if plat >= 100 then if crys[i] == 100 then i = i + 1 crys[i] = 0 end crys[i] = crys[i] + 1 plat = plat - 100 end until plat < 100 --now script give crytal, platinum and gold coins to player (BP/hands if free) if crys[1] > 0 then repeat doPlayerAddItem(cid, crys_id, crys[i]) i = i-1 until i == 0 end if plat > 0 then doPlayerAddItem(cid, plat_id, plat) end if gold > 0 then doPlayerAddItem(cid, gold_id, gold) end selfSay('Trzymaj '..n..' zlotych monet. Twoj stan konta wynosi '..getBA(nome)..'.') else --player doesn't have enought cash on this bank account, can't withdraw that much selfSay('There is not enough gold on your account.') end end if (msgcontains(msg, 'no')) then --player doesn't want to withdraw selfSay('Klient ma zawsze racje. Przyjdz kiedy bedziesz chcial wyplacic pieniadze.') wit = 0 talk_start = os.clock() end end -------------------------------------------Balance--------------------------------------- if (msgcontains(msg, 'balance')) and (focus == cid) and getDistanceToCreature(cid) < 4 then --player who is talking with NPC want to know his account balance selfSay('Twoj stan konta wynosi '..getBA(nome)..' zlotych monet.') dep = 0 wit = 0 trans = 0 talk_start = os.clock() end -------------------------------------------Transfer--------------------------------------- if trans == 3 and (focus == cid) and getDistanceToCreature(cid) < 4 then if (msgcontains(msg, 'yes')) then --if he want to tranfer playerbalance = getBA(nome) --get balance value of player if setBA(rec, getBA(rec)+quant) > 0 then -- if script set new balance get cash from transfering player account playerbalance = playerbalance - quant setBA(nome, playerbalance) selfSay('Przelales '..quant..' zlota do '..rec_org..'. Twoj stan konta wynosi '..playerbalance..' zlotych monet.') trans = 0 talk_start = os.clock() else --problem with database? dont lose money.. selfSay('Problem z transferem. Sorry.') trans = 0 talk_start = os.clock() end elseif (msgcontains(msg, 'no')) then -- if he dont want to tranfer selfSay('OK. Co teraz?') trans = 0 talk_start = os.clock() end end if trans == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then if getBA(msg) >= 0 then --player with this name exist rec = msg rec_org = msg_org selfSay('Chcesz przelac '..quant..' zlotych monet do '..rec_org..'?') trans = 3 talk_start = os.clock() else --player with this name doesn't exist selfSay('Osoba o takim imieniu nie istnieje, podaj inne imie.') trans = 2 talk_start = os.clock() end end if trans == 1 and (focus == cid) and getDistanceToCreature(cid) < 4 then quant = getNumber(msg) if quant > 0 then -- its number and is higher than 0 if getBA(nome) >= quant then -- player who want to transfer has enought cash on account selfSay('Do kogo chcialbys przelac '..quant..' zlota?') trans = 2 talk_start = os.clock() else -- player who want to transfer has not enought cash on account selfSay('Nie masz dosc pieniedzy na koncie. Stan Twojego konta wynosi'..getBA(nome)..'. Powiedz ile chcesz przelac.') trans = 1 talk_start = os.clock() end else --player told 0 or lower number or word like "asd" (its not a number) selfSay('Powiedz ile zlota chcesz przelac.') talk_start = os.clock() trans = 1 end end if trans == 0 then if (msgcontains(msg, 'transfer')) and (focus == cid) and getDistanceToCreature(cid) < 4 then selfSay('Powiedz ile zlota chcesz przelac.') dep = 0 wit = 0 trans = 1 talk_start = os.clock() end end -------------------------------------------End-------------------------------------------- if (msgcontains(msg, 'bye') or msgcontains(msg, 'papa') or msgcontains(msg, 'nara') or msgcontains(msg, 'Do widzenia')) and (focus == cid) and getDistanceToCreature(cid) < 4 then --player say "bye" - npc answer doNpcSetCreatureFocus(0) selfSay('Do widzenia.') focus = 0 dep = 0 wit = 0 trans = 0 end end function onCreatureChangeOutfit(creature) end function onThink() if (os.clock() - talk_start) > 30 then --if player did not say anything from 30 seconds say "next please" and wait for another customer if focus > 0 then doNpcSetCreatureFocus(0) selfSay('Nastepny prosze...') end focus = 0 dep = 0 wit = 0 trans = 0 end if focus ~= 0 then if getDistanceToCreature(focus) > 5 then --if distance to player is higher than 5 say bye doNpcSetCreatureFocus(0) selfSay('Do widzenia.') focus = 0 dep = 0 wit = 0 trans = 0 end end end