oshrigames
Active Member
Hello again
TFS 1.2, Protocol 10.98
ive been working on a Mining / Harvest / etc.. systems.
thanks to Ramirow and many others who help along the way, most of it already finished ♥
but i come to another issue i can't solve by myself (even tho i tried).
ive been working on a specific spawn system of a Crystals, Plants, and basically anything that ill ever gonna need. (with minor changes)
i want to have lets say, 3 types of Crystals spawn at random locations inside the mine (to counter future bots and players who camp the locations).
so ive remembered a similar systrem by oen432, ([TFS 1.X] Cursed Chests).
i've modified and remove most of it but i encounter few issues.
the issues:
1) once i mine of the the crystals, it spawn only at that location and that type. (mining.lua "function doCreateStone" is the issue?)
2) the crystal however sometimes spawn under stuff which prevents players to use "ice pick" on it.
seems like i broke oen432's "isBadTile" function.
either make the "item" (crystal) spawn on top of everything or on a ground where nothing on it.
and minior issue i get that error for some reason :x
heres the codes and if you have any question or need more info let me know.
(i know it can be cleaned even more, i just try to make it work first)
crystal_spawner.lua
crystal_type.lua
Mining.lua
once everything is finished i'll put it to the public, the modified Mining, Smith, Harvest and Alchemy (14+ Custom potions included).
with credit to everyone who gave a hand and wirte the core of the systems. ♥
TFS 1.2, Protocol 10.98
ive been working on a Mining / Harvest / etc.. systems.
thanks to Ramirow and many others who help along the way, most of it already finished ♥
but i come to another issue i can't solve by myself (even tho i tried).
ive been working on a specific spawn system of a Crystals, Plants, and basically anything that ill ever gonna need. (with minor changes)
i want to have lets say, 3 types of Crystals spawn at random locations inside the mine (to counter future bots and players who camp the locations).
so ive remembered a similar systrem by oen432, ([TFS 1.X] Cursed Chests).
i've modified and remove most of it but i encounter few issues.
the issues:
1) once i mine of the the crystals, it spawn only at that location and that type. (mining.lua "function doCreateStone" is the issue?)
2) the crystal however sometimes spawn under stuff which prevents players to use "ice pick" on it.
seems like i broke oen432's "isBadTile" function.
either make the "item" (crystal) spawn on top of everything or on a ground where nothing on it.
and minior issue i get that error for some reason :x
Code:
[Warning - Event::checkScript] Event onUse not found. scripts/custom/crystal_type.lua
heres the codes and if you have any question or need more info let me know.
(i know it can be cleaned even more, i just try to make it work first)
crystal_spawner.lua
Lua:
CRYSTAL_AID = 9001
CRYTAL_SPAWNS = {
[1] = {
pos = Position(988, 965, 7),
size = 2,
crystals = {1}
},
[2] = {
pos = Position(1021, 1070, 10),
size = 25,
crystals = {1}
}
}
-- [1 - test], [2 - Mine ]
function onThink(cid, interval, lastExecution)
for spawnId, data in ipairs(CRYTAL_SPAWNS) do
if not data.spawned then
local from = Position(data.pos.x - data.size, data.pos.y - data.size, data.pos.z)
local to = Position(data.pos.x + data.size, data.pos.y + data.size, data.pos.z)
local crystalId = math.random(1, #data.crystals)
local spawnPos = Position(math.random(from.x, to.x), math.random(from.y, to.y), data.pos.z)
local tile = Tile(spawnPos)
local spawnTest = 0
while spawnTest < 100 do
if isBadTile(tile) then
spawnPos = Position(math.random(from.x, to.x), math.random(from.y, to.y), data.pos.z)
tile = Tile(spawnPos)
spawnTest = spawnTest + 1
else
break
end
end
if spawnTest < 100 then
local rarity = nil
for i = #CRYSTAL_TIERS, 1, -1 do
rarity = CRYSTAL_TIERS[i]
if math.random(1, 100) <= rarity.chance then
break
end
end
if rarity ~= nil then
local crystal = Game.createItem(rarity.item, 1, spawnPos)
spawnPos:sendMagicEffect(CONST_ME_ENERGYHIT)
crystal:setActionId(CRYSTAL_AID)
local crystalData = {}
crystalData.pos = spawnPos
crystalData.spawnId = spawnId
crystalData.active = 0
crystalData.rarity = rarity
CRYSTAL_DATA[#CRYSTAL_DATA + 1] = crystalData
data.spawned = true
end
end
end
end
return true
end
crystal_type.lua
Lua:
local CRYSTAL_SPAWN_VERSION = "1.0.0"
print(">> Loaded Crystal Mine Spawn v" .. CRYSTAL_SPAWN_VERSION)
CRYSTAL_TIER_SMALL = 1
CRYSTAL_TIER_MEDIUM = 2
CRYSTAL_TIER_LARGE = 3
CRYSTAL_TIERS = {
{
tier = CRYSTAL_TIER_SMALL,
chance = 90,
text = " [Small Crystal Lv. 1+]", -- IGNORE
item = 17999,
reqLevel = 1 -- IGNORE
},
{
tier = CRYSTAL_TIER_MEDIUM,
chance = 40,
text = "Medium Crystal [Lv.50+]", -- IGNORE
item = 17597,
reqLevel = 1 -- IGNORE
},
{
tier = CRYSTAL_TIER_LARGE,
chance = 10,
text = "Large Crystal [Lv.70+]", -- IGNORE
item = 17867,
reqLevel = 1 -- IGNORE
}
}
CRYSTAL_DATA = {}
function isBadTile(tile)
return (tile == nil or tile:getGround() == nil or tile:hasProperty(TILESTATE_NONE) or tile:hasProperty(TILESTATE_FLOORCHANGE_EAST) or
isItem(tile:getThing()) and not isMoveable(tile:getThing()) or
tile:getTopCreature() or
tile:hasFlag(TILESTATE_PROTECTIONZONE))
end
Mining.lua
Lua:
-- Mining Skill
-- For TFS version 1.1
local name = "Mining" -- Name of the Custom Skill
local storage = 15034 -- Storage used to store Custom Skill Levels
local minutes = 1 -- Minutes to recreate the stone
function doCreateStone(pos, itemid) -- Recreates the stone after given time
local tile = Tile(pos)
if tile:getTopCreature() then
pos:sendMagicEffect(CONST_ME_POFF)
return addEvent(doCreateStone, minutes * 60 * 1000, pos, itemid)
else
Game.createItem(itemid, 1, pos)
pos:sendMagicEffect(CONST_ME_ENERGYHIT)
end
end
local stones = { -- Contains all stones and their data
[17999] = {
itemid = 17999,
stonetype = 'Blue Crystal Shard',
stonetype2 = 'Royal ingot',
item = 18413, --Blue Crystal Shard
item2 = 18337, -- Royal ingot
level = {min = 1, max = 20}, --1 Mining kill the chance would be '20%'.
bonusLevel = 20, -- chance to mine tiem2 ie: strange Royal ingot
bonusChance = 1, -- chance to get extra item2 ie: strange Royal ingot
roundChance = {min = 1, max = 1}, -- 'min' stands for the base amount of rubies you will get. 'max' stands for the maximun amount of rubies you will get. These values are base ones, remember that higher skill will increase the rewards. Also note that these values are counted for bonus rewards too.
chance = 1, --What this value does is increasing your chance of success. In this case, it divides your MINING SKILL by 2 and adds the result to your success rate! Easy as that, in this example, using the value of 2. Having 4 Mining Skill will add 2% (4 / 2) to our success rate, which was 30% at it's base (Expressed as I said, in level.max). That gives us a total of 32% rate of success. With a Mining Skill of 100 we will have 80% success rate. (30% base + 50% for skill(100 / 2))
round = 15, --This value works somehow like 'chance' but adds to the amount of rubies you will receive. 8 means that every 8 Skill Levels you will increase the rubies gained by 1. (8 / 8) Having 64 Mining Skill will give you 1 - 2 rubies (Base reward set in 'roundChance') + 8 additional rubies.
xp = 1, -- exp per succseful hit
xp2 = 2 -- exp per succseful hit for item2
},
[17597] = {
itemid = 17597,
stonetype = 'Blue Crystal Shard',
stonetype2 = 'Royal ingot',
item = 18413, --Blue Crystal Shard
item2 = 18337, -- Royal ingot
level = {min = 50, max = 20}, --1 Mining kill the chance would be '20%'.
bonusLevel = 20, -- chance to mine tiem2 ie: strange Royal ingot
bonusChance = 1, -- chance to get extra item2 ie: strange Royal ingot
roundChance = {min = 1, max = 2}, -- 'min' stands for the base amount of rubies you will get. 'max' stands for the maximun amount of rubies you will get. These values are base ones, remember that higher skill will increase the rewards. Also note that these values are counted for bonus rewards too.
chance = 1, --What this value does is increasing your chance of success. In this case, it divides your MINING SKILL by 2 and adds the result to your success rate! Easy as that, in this example, using the value of 2. Having 4 Mining Skill will add 2% (4 / 2) to our success rate, which was 30% at it's base (Expressed as I said, in level.max). That gives us a total of 32% rate of success. With a Mining Skill of 100 we will have 80% success rate. (30% base + 50% for skill(100 / 2))
round = 15, --This value works somehow like 'chance' but adds to the amount of rubies you will receive. 8 means that every 8 Skill Levels you will increase the rubies gained by 1. (8 / 8) Having 64 Mining Skill will give you 1 - 2 rubies (Base reward set in 'roundChance') + 8 additional rubies.
xp = 1, -- exp per succseful hit
xp2 = 2 -- exp per succseful hit for item2
},
[17867] = {
itemid = 17867,
stonetype = 'Blue Crystal Shard',
stonetype2 = 'Royal ingot',
item = 18413, --Blue Crystal Shard
item2 = 18337, -- Royal ingot
level = {min = 70, max = 20}, --1 Mining kill the chance would be '20%'.
bonusLevel = 20, -- chance to mine tiem2 ie: strange Royal ingot
bonusChance = 1, -- chance to get extra item2 ie: strange Royal ingot
roundChance = {min = 1, max = 3}, -- 'min' stands for the base amount of rubies you will get. 'max' stands for the maximun amount of rubies you will get. These values are base ones, remember that higher skill will increase the rewards. Also note that these values are counted for bonus rewards too.
chance = 2, --What this value does is increasing your chance of success. In this case, it divides your MINING SKILL by 2 and adds the result to your success rate! Easy as that, in this example, using the value of 2. Having 4 Mining Skill will add 2% (4 / 2) to our success rate, which was 30% at it's base (Expressed as I said, in level.max). That gives us a total of 32% rate of success. With a Mining Skill of 100 we will have 80% success rate. (30% base + 50% for skill(100 / 2))
round = 15, --This value works somehow like 'chance' but adds to the amount of rubies you will receive. 8 means that every 8 Skill Levels you will increase the rubies gained by 1. (8 / 8) Having 64 Mining Skill will give you 1 - 2 rubies (Base reward set in 'roundChance') + 8 additional rubies.
xp = 1, -- exp per succseful hit
xp2 = 2 -- exp per succseful hit for item2
}
}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = type(cid) == 'number' and Player(cid) or cid
local miningSkill = player:getCustomSkill(storage)
if stones[target.itemid] then
local miningLevel = stones[target.itemid].level
if miningSkill >= miningLevel.min then
local chance = math.floor((math.random(1, 100)) - (miningSkill / stones[target.itemid].chance))
if chance <= miningLevel.max then
local roundChance = stones[target.itemid].roundChance
local amount = math.floor((math.random(roundChance.min, roundChance.max)) + (miningSkill / stones[target.itemid].round))
if miningSkill >= stones[target.itemid].bonusLevel and math.random(1,100) <= stones[target.itemid].bonusChance then
local loop2 = stones[target.itemid].xp2
player:addItem(stones[target.itemid].item2, amount)
toPosition:sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
for i = loop2, 1, -1 do
player:addCustomSkillTry(name, storage)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You mined " .. amount .. " " .. stones[target.itemid].stonetype2 .. ".")
else
local loop = stones[target.itemid].xp
player:addItem(stones[target.itemid].item, amount)
toPosition:sendMagicEffect(CONST_ME_FIREWORK_BLUE)
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
for i = loop, 1, -1 do
player:addCustomSkillTry(name, storage)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You mined " .. amount .. " " .. stones[target.itemid].stonetype .. ".")
end
else
local failure = math.random(1,100)
if failure <= 50 then
toPosition:sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You failed and the rock was destroyed.")
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You couldn't mine anything.")
toPosition:sendMagicEffect(CONST_ME_HITAREA)
end
end
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a " .. name .. " level of " .. miningLevel.min .. " to mine this stone.")
end
end
return true
end
once everything is finished i'll put it to the public, the modified Mining, Smith, Harvest and Alchemy (14+ Custom potions included).
with credit to everyone who gave a hand and wirte the core of the systems. ♥
Last edited: