• 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!

NPC [TFS 1.3] Bank NPC

Togu

Advanced OT User
Joined
Jun 22, 2018
Messages
308
Solutions
1
Reaction score
178
Location
Brazil
Since the original forgottenserver on GitHub doesn't have an Bank NPC, I will post that one that I made getting some codes on the internet.

Using this feature I've found many functions, they deserve the credits:
orts/server

You will have to add on data/lib/core/player.lua: pasteBin
Lua:
function Player.depositMoney(self, amount)
   if not self:removeMoney(amount) then
       return false
   end

   self:setBankBalance(self:getBankBalance() + amount)
   return true
end

function Player.withdrawMoney(self, amount)
   local balance = self:getBankBalance()
   if amount > balance or not self:addMoney(amount) then
       return false
   end

   self:setBankBalance(balance - amount)
   return true
end

function Player.transferMoneyTo(self, target, amount)
   local balance = self:getBankBalance()
   if amount > balance then
       return false
   end

   local targetPlayer = Player(target)
   if targetPlayer then
       targetPlayer:setBankBalance(targetPlayer:getBankBalance() + amount)
   else
       if not playerExists(target) then
           return false
       end
       db.query("UPDATE `players` SET `balance` = `balance` + '" .. amount .. "' WHERE `name` = " .. db.escapeString(target))
   end

   self:setBankBalance(self:getBankBalance() - amount)
   return true
end

and then in data/npc/scripts/bank.lua: pasteBin

I didn't tested the guild bank functions and features, but player deposit, withdraw, balance and transfer are working.
 
[...]
db.query("UPDATE `players` SET `balance` = `balance` + '" .. amount .. "' WHERE `name` = " .. db.escapeString(target))
[...]

This part could make a lot of troubles :)
How?
1. Login as player A and player B
2. Transfer money from player A to player B
3. There is database UPDATE
4. Logout as player B
5. There is database uptade on player B row, that could overwrite changes
6. Money dissapear

Rest functions look nice. I guess if everythink will work as it should, it should be merged in github.
 
This part could make a lot of troubles :)
How?
1. Login as player A and player B
2. Transfer money from player A to player B
3. There is database UPDATE
4. Logout as player B
5. There is database uptade on player B row, that could overwrite changes
6. Money dissapear

Rest functions look nice. I guess if everythink will work as it should, it should be merged in github.
I don't know how to force this error. Actually I didn't understand how the code can reach this db.query (I simply copied it and tested and it was working). Cause if the target player exists he will add money in his bank. But if he didn't exist he will return false before reaching the db.query.

Do you know why there isn't datapacks commits on forgottenserver on GitHub? It could have the NPCs and actions from a global map.
 
This part could make a lot of troubles :)
How?
1. Login as player A and player B
2. Transfer money from player A to player B
3. There is database UPDATE
4. Logout as player B
5. There is database uptade on player B row, that could overwrite changes
6. Money dissapear

Rest functions look nice. I guess if everythink will work as it should, it should be merged in github.
No, it wont make any trouble.
Code checks if player is online and sets the balance, otherwise it query the change directly to database.
 
Back
Top