foundation5
New Member
- Joined
- Oct 26, 2023
- Messages
- 5
- Reaction score
- 0
I have this npc script to travel it is working, I would like to make just one change...
In the case if the player has money in the bag and the player tries to travel it works, however if the player doesn't have money in the bag but has money in the bank it doesn't work.
so basically you would need to make the script check if the player has money in the bank and if so he can travel normally.
script
modules.lua
In the case if the player has money in the bag and the player tries to travel it works, however if the player doesn't have money in the bag but has money in the bank it doesn't work.
so basically you would need to make the script check if the player has money in the bank and if so he can travel normally.
script
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local 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
function creatureSayCallback(cid, type, msg)
function lowerTable(tabela) -- by vodkart
local tab = {}
for var, ret in next, tabela do
tab[var:lower()] = ret
end
return tab
end
if not npcHandler:isFocused(cid) then
return false
end
local talkUser,msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, msg:lower()
local viagens = {
['Dark City'] = {premium = false, level = 0, cost = 200, destination = {x=766, y=1090, z=6}},
}
local magician_pos = {x=1249, y=783, z=6}
local travel = lowerTable(viagens)
if travel[msg] then
local var = travel[msg]
if var.level > 0 and getPlayerLevel(cid) < var.level then
npcHandler:say("Sorry but you must be level ".. var.level .." to travel to this place.", cid) return true
elseif var.premium and not isPremium(cid) then
npcHandler:say("Sorry, to go to "..msg.." it is necessary to be VIP.", cid) return true
elseif not doPlayerRemoveMoney(cid, var.cost) then
npcHandler:say("Sorry, you don't have enough GPS. Is required ".. var.cost .."gps to go to "..msg..".", cid) return true
end
if var.chance ~= nil and var.chance > 0 then
if getPlayerSlotItem(cid, CONST_SLOT_NECKLACE).itemid == 10219 then
mychance = 100
else
mychance = var.chance
end
end
npcHandler:say("Bon voyage!", cid)
npcHandler:releaseFocus(cid)
if var.chance ~= nil and var.chance > 0 then
if mychance > math.random(1, 100) then
doTeleportThing(cid, garath_pos)
npcHandler:say("The boat lost its way and stopped in Magician, Careful!", cid)
else
doTeleportThing(cid, var.destination)
end
else
doTeleportThing(cid, var.destination)
end
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
else
selfSay("I don't sail to this city...", cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
modules.lua
function Player.removeMoneyNpc(self, amount)
local moneyCount = self:getMoney()
local bankCount = self:getBankBalance()
if amount > moneyCount + bankCount then
return false
end
self:removeMoney(math.min(amount, moneyCount))
if amount > moneyCount then
local newBalance = bankCount - math.max(amount - moneyCount, 0)
self:setBankBalance(newBalance)
if moneyCount == 0 then
self:sendTextMessage(MESSAGE_INFO_DESCR, ("You paid %d gps from your bank account. Your balance went from %d to %d gps."):format(amount, bankCount, newBalance))
else
self:sendTextMessage(MESSAGE_INFO_DESCR, ("You paid %d from inventory and %d gold from bank account. Your account balance went from %d to %d gps."):format(moneyCount, amount - moneyCount, bankCount, newBalance))
end
end
return true
end