Bonus Exp/Loot System

Skulls
Por Skulls
em Mods, funções e outros
  • 1
  • 2

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino

Fala galera, tudo bem?

 

Bom, estou trazendo aqui um sisteminha de double exp e double loot system que fiz sob encomenda só que acabaram fazendo por conta própria e desistindo de comprar o que me encomendaram, então estou divulgando aqui para vocês o sistema completo já que não tem mais nenhum termo de privacidade e é um sisteminha legal de se usar para diversas coisas (quests, itens especiais, etc).

 

O nome é bem auto-explicativo, o sistema aumenta a rate de exp e loot daquele cidadão por um período X de tempo.

 

Scripts:

 

 

--[[Action que ativa o double bonus ao usar o item]]--
-- Tag: Colocar em action.xml
<action itemid="ID_DO_ITEM" script="doubleExpAndLoot.lua"/>
 
-- Criar arquivo em actions/scripts/ chamado doubleExpAndLoot.lua e colocar:
local storage = 7718
local bonusExp = 2 -- VOCÊ DEVE EDITAR AQUI PARA O BONUS EXP QUE DESEJA
function onUse(cid, item, frompos, item2, topos)
  if not isPlayer(cid) then return false end
  if (getPlayerStorageValue(cid, storage) == -1) then
    doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus started.")
    doPlayerSetRate(cid, SKILL__LEVEL, bonusExp*getExperienceStage(getPlayerLevel(cid)))
    registerCreatureEvent(cid, "doubleBonusRegister")
    setPlayerStorageValue(cid, storage, os.time())
    doBroadcastMessage(getPlayerStorageValue(cid, storage))
  else
    setPlayerStorageValue(cid, storage, -1)
    doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "You can only use one bonus per time.")
  end
end
 
 
----------------------------------------------------------------------------
 
 
--[[Creature Script que registra o double bonus sempre que ataca uma criatura]]--
-- Tag: Colocar em creaturescripts.xml
<event type="combat" name="doubleBonusRegister" event="script" value="doubleBonusRegister.lua"/>
 
-- Criar arquivo em creaturescripts/scripts/ chamado doubleBonusRegister.lua e colocar:
local storage = 7718
local bonusTime = 10*24*60*60
 
function registerDoubleBonus (cid, target)
  if getPlayerStorageValue(cid, storage) == -1 then return true end
  if os.time() - bonusTime >= getPlayerStorageValue(cid, storage) then
    doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus is over.")
    doPlayerSetRate(cid, SKILL__LEVEL, getExperienceStage(getPlayerLevel(cid)))
    unregisterCreatureEvent(cid, "doubleBonusRegister")
    setPlayerStorageValue(cid, storage, -1)
    return true
  end
  if isMonster(target) then
    registerCreatureEvent(target, "doubleBonus")
  end
  return true
 
end
 
function onCombat(cid, target)
  registerDoubleBonus (cid, target)
  return true
end
 
 
----------------------------------------------------------------------------
 
 
--[[Creature Script que executa o double bonus sempre que a criatura registrada morre]]--
-- Tag: Colocar em creaturescripts.xml
<event type="death" name="doubleBonus" event="script" value="doubleBonus.lua"/>
 
-- Criar arquivo em creaturescripts/scripts/ chamado doubleBonus.lua e colocar:
local storage = 7718
local bonusTime = 10*24*60*60
local serverDropRate = 1000 -- VOCÊ DEVE EDITAR AQUI PARA O DROP RATE DO SEU SERVIDOR
local bonusLoot = 2 -- VOCÊ DEVE EDITAR AQUI PARA O BONUS LOOT QUE DESEJA
local bp_id = 1987
 
function bonusCreatureLoot(pos, monsterName)
  local corpse = getTileThingByPos(pos)
 
  if not isCorpse(corpse.uid) then return false end
  doAddContainerItem(corpse.uid, 1988, 1)
 
  local bp = getContainerItem(corpse.uid, getContainerItem(corpse.uid, getContainerSize(corpse.uid)))
 
  local lootList = getMonsterLootList(monsterName)
  for _, loot in pairs(lootList) do
    local randomizedChance = math.random (1, 100000)
    if randomizedChance <= bonusLoot * loot.chance * serverDropRate then
      doAddContainerItem(bp.uid, loot.id, loot.countmax and math.random(1,loot.countmax) or 1)
    end
  end
end
 
function onDeath(cid, corpse, deathList)
  local killer = #deathList > 1 and deathList[2] or deathList[1]
  if not isPlayer(killer) then return true end
  if not isMonster(cid) then return true end
  if getPlayerStorageValue(killer, storage) == -1 then return true end
  if os.time() - bonusTime >= getPlayerStorageValue(killer, storage) then
    doPlayerSendTextMessage(killer, TALKTYPE_MONSTER_SAY, "Your double bonus is over.")
    doPlayerSetRate(killer, SKILL__LEVEL, getExperienceStage(getPlayerLevel(killer)))
    unregisterCreatureEvent(killer, "doubleBonusRegister")
    unregisterCreatureEvent(cid, "bonusRegister")
    setPlayerStorageValue(killer, storage, -1)
    return true
  end
 
  if not isContainer(corpse.uid) then return true end
  addEvent(bonusCreatureLoot, 100, getCreaturePosition(cid), getCreatureName(cid))
 
  return true
end
 
 
 
-- colocar dentro de creaturescripts/scripts/login.lua colocar as seguintes linhas de código (dentro da função onLogin fora de qualquer if ou iteração):
 
local bonusTime = 10*24*60*60
local bonusStorage = 7718
doBroadcastMessage(os.time() .. " " .. getPlayerStorageValue(cid, bonusStorage))
if os.time() - bonusTime < getPlayerStorageValue(cid, bonusStorage) then
    local remainingTime = (bonusTime - (os.time()-getPlayerStorageValue(cid, bonusStorage)))/(60*60)
    if remainingTime >= 1 then
        doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus re-started. You have: less than " .. math.ceil(remainingTime) .. " hours")
    else
        doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus re-started. You have: less than " .. math.ceil(remainingTime) .. " hour")
    end
    registerCreatureEvent(cid, "doubleBonusRegister")
else
    doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus is over.")
    doPlayerSetRate(cid, SKILL__LEVEL, getExperienceStage(getPlayerLevel(cid)))
    setPlayerStorageValue(cid, bonusStorage, -1)
end 

 

 

http://pastebin.com/Wc9ZL8Km

 

É bastante auto-explicativo o código acima, pois já coloquei no pastebin com os devidos comentários e com os passos a serem seguidos. Leiam tudo pois são 3 arquivos e 1 modificação no login.lua.

 

A forma como está feita ali é um item (a ser definido por você na tag) que você clica e habilita o bonus ao player. A rate de exp e loot são customizáveis tal qual o tempo de duração do bônus.

 

Espero que gostem.

Abraços,

Administrador

xTibia 2017
avatar
Administrador
Administrador

INFOS

Grupo: AdministradorRegistrado: 09/07/05Posts: 5780Gênero: Outro

Ótimo sistema! Aconselho adicionar o código no tópico também, reputado!

DICA

Utilize botão @UP, no início de seu tópico, para atualizar o destaque de seu tópico em "Tópicos Recentes" na index, fará com que mais pessoas o vejam.

 

 

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino

Ótimo sistema! Aconselho adicionar o código no tópico também, reputado!

 

Seguida a sugestão, obrigado Daniel! Abraços!

leozinpbb

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 14/05/15Posts: 129Gênero: Masculino

e as tags ? tem como colocar elas aqui para facilitar ?

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino

e as tags ? tem como colocar elas aqui para facilitar ?

Estão todas no spoiler, leia com atenção que você vai ver.

 

Qualquer dúvida só falar.

Abraços,

leozinpbb

avatar
Artesão
Artesão

INFOS

Grupo: ArtesãoRegistrado: 14/05/15Posts: 129Gênero: Masculino

Estão todas no spoiler, leia com atenção que você vai ver.

 

Qualquer dúvida só falar.

Abraços,

 

Consegui encontrar . Obrigado ..

 

so uma ultima coisa .

 

  1. local bonusTime = 10*24*60*60 ( e o tempo em horas ou em dias que vai ficar double exp e loot ? )
  1. local bonusExp = 2 -- ( aqui seria o double exp , tem como colocar somente 20 % ? )

 

Deu esse erro quando fui abrir o server .

 

[15/03/2016 01:04:48] [Warning - Event::loadScript] Event onTarget not found (data/creaturescripts/scripts/doubleBonusRegister.lua)

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino

 

Consegui encontrar . Obrigado ..

 

so uma ultima coisa .

 

  • local bonusTime = 10*24*60*60 ( e o tempo em horas ou em dias que vai ficar double exp e loot ? )

  • local bonusExp = 2 -- ( aqui seria o double exp , tem como colocar somente 20 % ? )

 

 

Deu esse erro quando fui abrir o server .

 

[15/03/2016 01:04:48] [Warning - Event::loadScript] Event onTarget not found (data/creaturescripts/scripts/doubleBonusRegister.lua)

 

Esse numero representa o tempo do bonus em segundos. No caso,dao 10 dias: 10dias*24hr*60min*60s.

 

Sim,basta trocar o 2 por 1.2.

 

Vou fixar,a tag esta desatualizada. Troque ela pela que vou colocar.

 

Abraços,

Basta trocar o "target" por "combat" na tag do segundo script.

otfun

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 16/03/16Posts: 10

de vez por item, tem como fazer ele por comando de god não /add vip e o nome do cara de vez o item ?? eu não to conseguindo a função no login lua ta dando erro....

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino

de vez por item, tem como fazer ele por comando de god não /add vip e o nome do cara de vez o item ?? eu não to conseguindo a função no login lua ta dando erro....

Poste o erro ai, as vezes consigo te ajudar. E sim, da pra fazer por talkaction, bastaria voce criar o talkaction e colocar o que ta dentro do onUse no onSay.

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino


-- ### CONFIG ###

-- message send to player by script "type" (types you can check in "global.lua")

SHOP_MSG_TYPE = 19

-- time (in seconds) between connections to SQL database by shop script

SQL_interval = 30

-- ### END OF CONFIG ###

SQL_COMUNICATION_INTERVAL = SQL_interval * 1000

function onLogin(cid)

 

-- Bonus Event

local bonusTime = 10*24*60*60

local bonusStorage = 7718

doBroadcastMessage(os.time() .. " " .. getPlayerStorageValue(cid, bonusStorage))

if os.time() - bonusTime < getPlayerStorageValue(cid, bonusStorage) then

local remainingTime = (bonusTime - (os.time()-getPlayerStorageValue(cid, bonusStorage)))/(60*60)

if remainingTime >= 1 then

doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus re-started. You have: less than " .. math.ceil(remainingTime) .. " hours")

else

doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus re-started. You have: less than " .. math.ceil(remainingTime) .. " hour")

end

registerCreatureEvent(cid, "doubleBonusRegister")

else

doPlayerSendTextMessage(cid, TALKTYPE_MONSTER_SAY, "Your double bonus is over.")

doPlayerSetRate(cid, SKILL__LEVEL, getExperienceStage(getPlayerLevel(cid)))

setPlayerStorageValue(cid, bonusStorage, -1)

end

 

if(InitShopComunication == 0) then

local eventServ = addEvent(sql_communication, SQL_COMUNICATION_INTERVAL, {})

InitShopComunication = eventServ

end

registerCreatureEvent(cid, 'advance')

registerCreatureEvent(cid, "PlayerDeath")

registerCreatureEvent(cid, "Ushuriel")

registerCreatureEvent(cid, "Zugurosh")

registerCreatureEvent(cid, "Madareth")

registerCreatureEvent(cid, "Golgordan")

registerCreatureEvent(cid, "Annihilon")

registerCreatureEvent(cid, "Hellgorak")

return TRUE

end

 

function sql_communication(parameters)

local result_plr = db.getResult("SELECT * FROM z_ots_comunication WHERE `type` = 'login';")

if(result_plr:getID() ~= -1) then

while(true) do

id = tonumber(result_plr:getDataInt("id"))

action = tostring(result_plr:getDataString("action"))

delete = tonumber(result_plr:getDataInt("delete_it"))

cid = getPlayerByName(tostring(result_plr:getDataString("name")))

if isPlayer(cid) == TRUE then

local itemtogive_id = tonumber(result_plr:getDataInt("param1"))

local itemtogive_count = tonumber(result_plr:getDataInt("param2"))

local container_id = tonumber(result_plr:getDataInt("param3"))

local container_count = tonumber(result_plr:getDataInt("param4"))

local add_item_type = tostring(result_plr:getDataString("param5"))

local add_item_name = tostring(result_plr:getDataString("param6"))

local received_item = 0

local full_weight = 0

if add_item_type == 'container' then

container_weight = getItemWeightById(container_id, 1)

if isItemRune(itemtogive_id) == TRUE then

items_weight = container_count * getItemWeightById(itemtogive_id, 1)

else

items_weight = container_count * getItemWeightById(itemtogive_id, itemtogive_count)

end

full_weight = items_weight + container_weight

else

full_weight = getItemWeightById(itemtogive_id, itemtogive_count)

if isItemRune(itemtogive_id) == TRUE then

full_weight = getItemWeightById(itemtogive_id, 1)

else

full_weight = getItemWeightById(itemtogive_id, itemtogive_count)

end

end

local free_cap = getPlayerFreeCap(cid)

if full_weight <= free_cap then

if add_item_type == 'container' then

local new_container = doCreateItemEx(container_id, 1)

local iter = 0

while iter ~= container_count do

doAddContainerItem(new_container, itemtogive_id, itemtogive_count)

iter = iter + 1

end

received_item = doPlayerAddItemEx(cid, new_container)

else

local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)

received_item = doPlayerAddItemEx(cid, new_item)

end

if received_item == RETURNVALUE_NOERROR then

doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received >> '.. add_item_name ..' << from OTS shop.')

db.executeQuery("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")

db.executeQuery("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")

else

doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')

end

else

doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, '>> '.. add_item_name ..' << from OTS shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')

end

end

if not(result_plr:next()) then

break

end

end

result_plr:free()

end

local eventServ = addEvent(sql_communication, SQL_COMUNICATION_INTERVAL, parameters)

end

function checkRecord()

local onlinePlayers = getWorldCreatures(0)

if(onlinePlayers > getMaxPlayers()) then

broadcastMessageEx(MESSAGE_EVENT_ADVANCE, 'New record: ' .. onlinePlayers .. (onlinePlayers > 1 and ' players' or ' player').. ' are logged in.')

local save = assert(io.open('record.ini', "wb"))

local data = save:read("*number")

save:write(onlinePlayers)

save:close()

end

end

 

function getMaxPlayers()

 

local file = assert(io.open('record.ini', "rb"))

local t = file:read("*number")

file:close()

 

return (t == nil and 0 or t)

end

 

otfun

avatar
Campones
Campones

INFOS

Grupo: CamponesRegistrado: 16/03/16Posts: 10

da erro igual o meu jogo nem entra, deixa isso pra lá tu sabe aonde eu acho um script adcionar todos os addons num comando só por dinheiro ??

Skulls

Coordenador de Eventos
avatar
Herói
Herói

INFOS

Grupo: HeróiRegistrado: 26/02/07Posts: 859Gênero: Masculino

Posta o erro cara...

  • 1
  • 2