Hiho!
primeiramente, os devidos creditos de quem criou esse funçao:
Creditos a:
rob101 do otfans. (por faser toda funçao)
Zorzin do xtibia. (pra faser funcionar tambem em xml)
eu só estou aqui para mostrar para vcs mesmo =]
Funçoes: deposit, withdraw, balance, transfer e pagamento das houses pelo bank
Testado em: Forgotten Otserver SQL
notas:
-o que tiver *** é a parte que o zorzin fez
-se você usa server SQL, siga nos titulos (para xml e sql) ou (para sql)
-se você usa server XML, siga nos titulos (para xml e sql) ou (para xml)
começando:
luascript.cpp (para xml e sql)
depois de:
lua_register(m_luaState, "getPlayerPremiumDays", LuaScriptInterface::luaGetPlayerPremiumDays);
adicione:
//doPlayerDeposit(cid, cash) lua_register(m_luaState, "doPlayerDeposit", LuaScriptInterface::luaDoPlayerDeposit); //doPlayerWithdraw(cid, cash) lua_register(m_luaState, "doPlayerWithdraw", LuaScriptInterface::luaDoPlayerWithdraw); //getPlayerBalance(cid) lua_register(m_luaState, "getPlayerBalance", LuaScriptInterface::luaGetPlayerBalance); //doPlayerDepositTrans(name, cash) lua_register(m_luaState, "doPlayerDepositTrans", LuaScriptInterface::luaDoPlayerDepositTrans);
depois de:
case PlayerInfoPremDays: value = player->premDays; break;
adicione:
case PlayerInfoBank: value = player->bank; break;
depois de:
int LuaScriptInterface::luaGetPlayerPremiumDays(lua_State *L){ return internalGetPlayerInfo(L,PlayerInfoPremDays);}
adicione:
int LuaScriptInterface::luaGetPlayerBalance(lua_State *L){ return internalGetPlayerInfo(L,PlayerInfoBank);}
no final, adicione:
int LuaScriptInterface::luaDoPlayerDeposit(lua_State *L) { //doPlayerDeposit(cid, cash) int64_t cash = (int64_t)popNumber(L); uint32_t cid = popNumber(L); ScriptEnviroment* env = getScriptEnv(); Player* player = env->getPlayerByUID(cid); if(player){ player->bank += cash; lua_pushnumber(L, LUA_TRUE); } else{ lua_pushnumber(L, LUA_ERROR); } return 1; } int LuaScriptInterface::luaDoPlayerWithdraw(lua_State *L) { //doPlayerWithdraw(cid, cash) int64_t cash = (int64_t)popNumber(L); uint32_t cid = popNumber(L); ScriptEnviroment* env = getScriptEnv(); Player* player = env->getPlayerByUID(cid); if(player){ player->bank -= cash; lua_pushnumber(L, LUA_TRUE); } else{ lua_pushnumber(L, LUA_ERROR); } return 1; } int LuaScriptInterface::luaDoPlayerDepositTrans(lua_State *L) { //doPlayerDepositTrans(name, cash) int64_t cash = (int64_t)popNumber(L); std::string name = popString(L); unsigned long guid; if(!IOPlayer::instance()->getGuidByName(guid, name)){ lua_pushnumber(L, LUA_ERROR); } if(Player* player = g_game.getPlayerByName(name)){ player->bank += cash; lua_pushnumber(L, LUA_TRUE); } else if(IOPlayer::instance()->playerExists(name)){ Player* player = new Player(name, NULL); if(!IOPlayer::instance()->loadPlayer(player, name)){ delete player; lua_pushnumber(L, LUA_ERROR); } player->bank += cash; IOPlayer::instance()->savePlayer(player); delete player; lua_pushnumber(L, LUA_TRUE); } return 1; }
luascript.h (para xml e sql)
depois de:
PlayerInfoPremDays,
adicione:
PlayerInfoBank,
depois de:
static int internalGetPlayerInfo(lua_State *L, PlayerInfo_t info);
adicione:
static int luaDoPlayerDeposit(lua_State *L); static int luaDoPlayerWithdraw(lua_State *L); static int luaGetPlayerBalance(lua_State *L); static int luaDoPlayerDepositTrans(lua_State *L);
ioplayersql.cpp (para sql)
depois de:
player->soul = result.getDataInt("soul");
adicione:
player->bank = result.getDataLong("bank");
depois de:
query << "`soul` = " << player->soul << ", ";
adicione:
query << "`bank` = " << player->bank << ", ";
ioplayerxml.cpp (para xml)***
depois de:
if(readXMLInteger(root, "soul", intValue)){ player->soul = intValue; }
adicione:
if(readXMLInteger(root, "bank", intValue)){ player->bank = intValue; } else player->bank = 0;
depois de:
sb.str(""); sb << player->soul; xmlSetProp(root, (const xmlChar*)"soul", (const xmlChar*)sb.str().c_str());
adicione:
sb.str(""); sb << player->bank; xmlSetProp(root, (const xmlChar*)"bank", (const xmlChar*)sb.str().c_str());
player.cpp (para xml e sql)
depois de:
soul = 0;
adicione:
bank = 0;
player.h (para xml e sql)
depois de:
int32_t soul, soulMax;
adicone:
int64_t bank;
game.cpp (para xml e sql)
no final, adicione:
bool Game::bankWithdraw(Player* player, int64_t money, uint32_t flags) { if(player){ if (player->bank >= money) { player->bank -= money; return true; } else { return false; } } else{ return false; } }
game.h (para xml e sql)
depois de:
void changeSkull(Player* player, Skulls_t newSkull);
adicione:
bool bankWithdraw(Player* player, int64_t money, uint32_t flags);
house.cpp (para xml e sql)
troque isso:
if(g_game.removeMoney(depot, house->getRent(), FLAG_NOLIMIT)){
por isso:
//if(g_game.removeMoney(depot, house->getRent(), FLAG_NOLIMIT)){ if(g_game.bankWithdraw(player, house->getRent(), FLAG_NOLIMIT)){
troque isso:
player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in your depot of this city.");
por isso:
//player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in your depot of this city."); player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in your bank account.");
database do sql (para sql)
ALTER TABLE `players` ADD `bank` INT( 64 ) NOT NULL DEFAULT '0' AFTER `soul` ;
examplo de NPC
(baseado no NPC Banker do Colex)
local focus = 0local talk_start = 0
local target = 0
local dep = 0
local wit = 0
local trans = 0
local following = false
local attacking = false
local msg = ''
local nome = ''
local ux = 0
local n = 0
local na = 0
local rec = ''
local gold = na
local plat = 0
local crys = {}
local i = 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_start = 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)
msg = string.lower(msg)
nome = creatureGetName(cid)
if (string.find(msg, 'hi') or string.find(msg, 'hello')) and (focus == 0) and getDistanceToCreature(cid) < 4 then
dep = 0
wit = 0
trans = 0
selfSay('Hello ' .. nome .. '! Well come to the local bank, what do you want to do? here you can access your bank account saying (deposit, withdraw, balance, transfer).')
focus = cid
talk_start = os.clock()
elseif string.find(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')
end
if dep == 0 then
if (string.find(msg, 'deposit')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('How much do you wish to deposit?')
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
talk_start = os.clock()
selfSay('Do you really want to deposit '..n..' gold pieces?')
dep = 2
end
end
end
if dep == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (string.find(msg, 'yes')) then
dep = 0
talk_start = os.clock()
if doPlayerRemoveMoney(cid,n) then
doPlayerDeposit(cid,n)
selfSay('Deposit Succesful!')
else
selfSay('Sorry, you dont have enought money!')
end
end
if (string.find(msg, 'no')) then
selfSay('Ok then.')
dep = 0
talk_start = os.clock()
end
end
if wit == 0 then
if (string.find(msg, 'withdraw')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('How much do you wish to withdraw?')
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
talk_start = os.clock()
selfSay('Do you really want to withdraw '..n..' gold pieces?')
wit = 2
end
end
end
if wit == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (string.find(msg, 'yes')) then
wit = 0
talk_start = os.clock()
if n <= getPlayerBalance(cid) then
doPlayerWithdraw(cid,n)
doPlayerAddCash(cid,n)
selfSay('withdraw successful!')
else
selfSay('Sorry, you dont have enought money in your account!')
end
end
if (string.find(msg, 'no')) then
selfSay('Ok then.')
wit = 0
talk_start = os.clock()
end
end
if (string.find(msg, 'balance')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('You have got '..getPlayerBalance(cid)..' gold pieces in your bank account.')
dep = 0
wit = 0
trans = 0
talk_start = os.clock()
end
if trans == 4 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (string.find(msg, 'yes')) then
if (doPlayerDepositTrans(rec, quant) == 1) then
doPlayerWithdraw(cid, quant)
selfSay('The money was successfuly transfered!')
trans = 0
talk_start = os.clock()
else
selfSay('This player does exist!')
end
elseif (string.find(msg, 'no')) then
selfSay('Ok then!')
trans = 0
talk_start = os.clock()
end
end
if trans == 3 and (focus == cid) and getDistanceToCreature(cid) < 4 then
rec = msg
selfSay('Do you want to transfer '..quant..' gps to '..rec..'?')
trans = 4
talk_start = os.clock()
end
if trans == 2 and (focus == cid) and getDistanceToCreature(cid) < 4 then
if (string.find(msg, 'yes')) then
if getPlayerBalance(cid) >= quant then
selfSay('Who do you want to trasnfer the money to?')
trans = 3
talk_start = os.clock()
else
selfSay('Sorry, you do not have enough money!')
trans = 0
talk_start = os.clock()
end
elseif (string.find(msg, 'no')) then
selfSay('Ok then!')
talk_start = os.clock()
trans = 0
end
end
if trans == 1 and (focus == cid) and getDistanceToCreature(cid) < 4 then
quant = getNumber(msg)
if quant > 0 then
selfSay('Do you really want to transfer '..quant..' gold pieces?')
trans = 2
talk_start = os.clock()
end
end
if trans == 0 then
if (string.find(msg, 'transfer')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('How much do you want to transfer?')
dep = 0
wit = 0
trans = 1
talk_start = os.clock()
end
end
if (msgcontains(msg, 'bye')) and (focus == cid) and getDistanceToCreature(cid) < 4 then
selfSay('Have a nice day Sir!')
focus = 0
dep = 0
wit = 0
trans = 0
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
dep = 0
wit = 0
trans = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
dep = 0
wit = 0
trans = 0
end
end
end
function getNumber(txt)
ux = string.gsub(txt,"%a","")
ux = tonumber(ux)
if ux ~= nill and ux > 0 then
return ux
else
return 0
end
end
function doPlayerAddCash(cid, na)
gold = na
plat = 0
crys = {}
crys[1] = 0
i = 1
repeat
if gold >= 100 then
plat = plat + 1
gold = gold - 100
end
until gold < 100
repeat
if plat >= 100 then
if crys == 100 then
i = i + 1
crys = 0
end
crys = crys + 1
plat = plat - 100
end
until plat < 100
if crys[1] > 0 then
repeat
doPlayerAddItem(cid,2160,crys)
i = i-1
until i == 0
end
if plat > 0 then
doPlayerAddItem(cid,2152,plat)
end
if gold > 0 then
doPlayerAddItem(cid,2148,gold)
end
end
é isso, espero que aproveite!
lembrando que eu NAO fiz essa função, foi o rob101 do otfans.
cya... :hi: