Loan Shark
Boa tarde,
Estava eu trabalhando quando tive a ideia de programar um script qualquer, aí desenvolvi esse script.
Bom, é um NPC simples, ele empresta uma quantia de dinheiro ao jogador, e cobra 50% de juros por dia, com um limite de 2 dias, ou seja um agiota.
Se o jogador não pagar o dinheiro devido, ao entrar no servidor, com auxílio de um creaturescript, seu HP é reduzido para 1 e ele ganha uma red skull, simulando que o Agiota mandou caçar-lo.
Bom, é isso aí.
npc/scripts/loan shark.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 local storage = { [1] = 12345, [2] = 12346, [3] = 12347, } function onCreatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end msg = msg:lower() or "" local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local loan = getPlayerLevel(cid) * 2000 if getCreatureStorage(cid, storage[1]) == -1 then if not talkState[talkUser] or talkState[talkUser] == 0 then if msgcontains(msg, "money") then selfSay("Well, well. I can loan some money to you, but I'm not stupid, don't try to be a smartass with me, agreed?", cid) talkState[talkUser] = 1 end elseif talkState[talkUser] == 1 then if msgcontains(msg, "yes") then selfSay("Okay, are you really desperate, heh? Well, I can loan to you, a maximum amount of ".. loan .." gold.", cid) selfSay("So, how much money, do you need?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, "no") then selfSay("Okay.") talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end elseif talkState[talkUser] == 2 then if not tonumber(msg) then selfSay("Say a number amount, stupid.") else if tonumber(msg) > loan then selfSay("Hey, smartass, I can loan to you a maximum amount of ".. loan .." gold.", cid) else doCreatureSetStorage(cid, storage[2], tonumber(msg)) selfSay("You will need ".. tonumber(msg) .." gold? Okay, my interest is 50% by day, agreed?", cid) talkState[talkUser] = 3 end end elseif talkState[talkUser] == 3 then if msgcontains(msg, "yes") then selfSay("Good choice, kid. Here is your money, but don't forget to pay me in 2 days, or my boys will beat up you pretty bad, after that I will forgive the debt.", cid) doPlayerAddMoney(cid, getCreatureStorage(cid, storage[2])) doCreatureSetStorage(cid, storage[1], 1) doCreatureSetStorage(cid, storage[3], os.time()) npcHandler:releaseFocus(cid) elseif msgcontains(msg, "no") then selfSay("Do you give up? Ooh, I forgot you are a milksop.", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end end else local days = math.floor((os.time() - getCreatureStorage(cid, storage[3])) / 86400) local value = (days > 0 and (getCreatureStorage(cid, storage[2]) * (1.5 ^ days)) or getCreatureStorage(cid, storage[2])) if not talkState[talkUser] or talkState[talkUser] == 0 then selfSay("Well, well... ".. getCreatureName(cid) ..", do you remember you borrowed ".. getCreatureStorage(cid, storage[2]) .." gold from me, right?", cid) talkState[talkUser] = 1 elseif talkState[talkUser] == 1 then if msgcontains(msg, "yes") then selfSay("Good, because you need to pay me for ".. (days == 0 and "no" or days) .." days using my money.", cid) selfSay("The value you owe me is ".. value .." gold. Do you have it?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, "no") then selfSay("Okay, then...", cid) selfSay("Just kidding, bitch! You need to pay me ".. value .." gold for ".. (days == 0 and "no" or days) .." days using my money. Do you have it, right?", cid) talkState[talkUser] = 2 end elseif talkState[talkUser] == 2 then if msgcontains(msg, "yes") then if getPlayerMoney(cid) >= value then doPlayerRemoveMoney(cid, value) selfSay("Very good, daug! If you need my money again, you can ask me, heheh...", cid) doCreatureSetStorage(cid, storage[1], -1) doCreatureSetStorage(cid, storage[2], -1) doCreatureSetStorage(cid, storage[3], -1) else selfSay("You don't have my money, no problem, you have ".. (days > 1 and "no more days" or "one day") .." before my boys hunt you, heh.", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end elseif msgcontains(msg, "no") then selfSay("So, it is good to get my money, because you have ".. (days > 1 and "no more days" or "one day") .." before my boys hunt you.", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end end end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback) npcHandler:addModule(FocusModule:new())
creaturescripts/scripts/loan shark.lua
local storage = { [1] = 12345, [2] = 12346, [3] = 12347, } function onLogin(cid) local days = math.floor((os.time() - getCreatureStorage(cid, storage[3])) / 86400) if getCreatureStorage(cid, storage[1]) == 1 and days > 2 then doCreatureSetStorage(cid, storage[1], -1) doCreatureSetStorage(cid, storage[2], -1) doCreatureSetStorage(cid, storage[3], -1) doCreatureAddHealth(cid, (1 - getCreatureMaxHealth(cid))) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "The Loan Shark's boys beat up you pretty hard because you didn't paid the your debt in 2 days.") doSendMagicEffect(getCreaturePosition(cid), CONST_ME_BLOCKHIT) doCreatureSetSkullType(cid, SKULL_RED) end return true end
creaturescripts/creaturescripts.xml
<event type="login" name="LoanShark" event="script" value="loan shark.lua"/>
O arquivo XML do NPC deixo por conta de vocês.
Att,
Garou