S
Shadow_
Guest
@peteralto asked me for this system please read instructions inside the code in-order to build it correctly.
Prison System explanation:
On prisoning a player the player will be required to mine a specific amount of the material stated, that amount is stated in the command
[Rocks created through map should have AID 8032]
Not tested so any errors please let me know, I can happily fix them.
Changes Log:
1- Fixed typo in talkaction
2- Pickaxe added to player on entrance and removed on exit.
3- changed os.time to os.mtime as @Xikini told me thats the correct way to work with time in milliseconds
4- fixed error on miningExhaust had to link to the prison table
Prison System explanation:
On prisoning a player the player will be required to mine a specific amount of the material stated, that amount is stated in the command
the player should be teleported in the prison around him some rocks that will have regeneration after each successful mine./prison playername,amountOfMaterials
[Rocks created through map should have AID 8032]
Lua:
--A prison system to punish player. [Storages Used, 78913,78914] [Action ids used: 8032,8033]
local prison = {
storage = 78913,
position =Position(1000,1000,7), --position of your prison
MiningRockActionId = 8032, --set that actionid to the rocks)
chance = 10, -- chance to receive materials
materialId = 2159, --Item should be giving by mining
minedEffect = 50, --effect on mining success
failEffect = CONST_ME_POFF, --effect on fail
miningExhaust = 500, --500MS exhaust
exhaustStorage = 78914, --Where i will use os.time() to create exhaustion
rockMineId = rockMineId, -- here is the rock mine itemID
pickId = pickId,
smallRockId = smallRockId, --Please Enter the rock that should appear when the rock mine is mined successfully
rockMineRegeneration = 5000, -- 5000/1000 = 5Seconds till it regenerate from the small rock to the mineRock
templePosition = Position(1000,1000,7)
wagonAid = 8033,
}
--You would send them to prison for talkactions, setting a penalty X (storage). (/prison nick, 600)
local prisonTalkaction = TalkAction("/prison")
function prisonTalkaction.onSay(player, words, param)
if player:getGroup():getAccess() and param ~= "" then
local split = param:split(",")
local targetPlayer = Player(split[1])
if not targetPlayer then
player:sendCancelMessage('Player is offline or name is incorrect.')
return false
end
targetPlayer:setStorageValue(prison.storage, tonumber(split[2]))
targetPlayer:teleportTo(prison.position)
targetPlayer:sendTextMessage(MESSAGE_INFO_DESCR, "You have been jailed by "..player:getName()..".")
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have jailed "..targetPlayer:getName()..".")
return false
end
end
prisonTalkaction:separator(" ")
prisonTalkaction:register()
--They would be teleported to a prison, in this location there would be a mine with some rock piles, which would receive an actionID.
--The player must mine these rocks to collect a certain item, with an X% chance of finding that item.
local prisonPick = Action()
function prisonPick.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not Tile(toPosition):getItemById(prison.rockMineId) then
return false
end
if not target:getActionId() == prison.MiningRockActionId then
return false
end
if player:getStorageValue(prison.exhaustStorage) >= os.mtime() then
player:sendCancelMessage("You are exhausted.")
return false
end
player:setStorageValue(prison.exhaustStorage, os.mtime() + prison.miningExhaust)
local randomChance = math.random(1,100)
if randomChance > prison.chance then
target:getPosition():sendMagicEffect(prison.failEffect)
return false
end
target:getPosition():sendMagicEffect(prison.minedEffect)
player:addItem(prison.materialId, 1)
local pos = target:getPosition()
target:remove(1)
local smallRock = Game.createItem(prison.smallRockId, 1, pos)
addEvent(function(pos)
local smallRock = Tile(pos):getItemById(prison.smallRockId)
if smallRock then
smallRock:remove(1)
end
local mineRock = Game.createItem(prison.rockMineId, 1, pos)
mineRock:setActionId(prison.MiningRockActionId)
end,prison.rockMineRegeneration, pos)
return true
end
prisonPick:id(prison.pickId)
prisonPick:register()
--When collecting the item he must take it to a wagon, with another actionID, which will count these items.
-- releaseCount = player:getStorageValue(prison.storage)
local wagon = Action()
function wagon.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local releaseCount = player:getStorageValue(prison.storage)
local count = player:getItemCount(prison.materialId)
if count >= releaseCount then
player:removeItem(prison.materialId, count)
player:setStorageValue(prison.storage, 0)
player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been released from prision.")
player:teleportTo(prison.templePosition)
return true
end
player:sendTextMessage(MESSAGE_INFO_DESCR, "You still need "..releaseCount - count.." to be released")
player:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
wagon:aid(prison.wagonAid)
wagon:register()
--Reaching an X value the player would be released (thrown to the temple)
Not tested so any errors please let me know, I can happily fix them.
Changes Log:
1- Fixed typo in talkaction
2- Pickaxe added to player on entrance and removed on exit.
3- changed os.time to os.mtime as @Xikini told me thats the correct way to work with time in milliseconds
4- fixed error on miningExhaust had to link to the prison table
Last edited by a moderator: