• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

TalkAction [TFS 1.3+] Prison System [Free Services Order]

Shadow_

Veteran OT User
Joined
Jun 2, 2018
Messages
1,016
Solutions
31
Reaction score
429
@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
/prison playername,amountOfMaterials
the player should be teleported in the prison around him some rocks that will have regeneration after each successful mine.
[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:

Tofame

Active Member
Joined
Aug 17, 2021
Messages
48
Solutions
1
Reaction score
26
Location
Poland
Haha, obligatory work in order to be released. Will be funny to see player's reaction to be sent there xD.
Looks good, great job and well explained with the comments.
 

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,636
Solutions
7
Reaction score
441
Location
Canada
Awesome work; much better than the system I currently use which jails the player for a set time.
Making the player earn their way out of jail is a cool concept - keep up the great work and cant wait to see the future requested releases ;D
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,488
Lua:
    miningExhaust = 500, --500MS exhaust

    if player:getStorageValue(prison.exhaustStorage) >= os.time() then
        player:sendCancelMessage("You are exhausted.")
        return false
    end
 
    player:setStorageValue(exhaustStorage, os.time() + miningExhaust)

Not tested so any errors please let me know, I can happily fix them.
os.time() only get's seconds, not millseconds. So right now the exhaust is 500 seconds (8.3~ minutes)
To get milliseconds use the included os.mtime() from the Lua functions.
 
OP
OP
Shadow_

Shadow_

Veteran OT User
Joined
Jun 2, 2018
Messages
1,016
Solutions
31
Reaction score
429
Any errors found has been fixed, please let me know if anymore issues found.

Thank you everybody im really happy that you are into those codes i will be dropping in these days, sometimes i take time to release its just because im was super busy with rl life and things are getting re-ordered here ^^
Post automatically merged:

Edit: Exhaust might not be working due to storage value is limited to int 32

player storage is setted to 2147483647 while mtime is 1663359906002

int 32 max is 2.147B
 
Last edited:

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,636
Solutions
7
Reaction score
441
Location
Canada
Hey guys would like to feature my contribution/fix + map update.

-Exhaust wasn't working properly so I modified to work based on seconds and storage value with an addEvent.
-Regeneration Time for rocks were going to quickly (not 5 seconds) so I also fixed this too.
-Changed storage values to match my projects currently used/unused.
-Changed PickID to be dwarven pickaxe
-Temple position is default Thais position
-Rock ID's changed to similar matching rocks "bigger and smaller"
-Please note the matierlID is a scarab coin; should probably change this if you want the system to feel more realistic in a sense.

Code:
--A prison system to punish player.  [Storages Used, 78913,78914] [Action ids used: 8032,8033]
local prison = {
    storage = 39010, -- used for material storage
    exhaustStorage = 39011, -- used for exhaust
    materialId = 2159, -- ore ID recieved from mining
    chance = 20, -- chance to receive materials
    miningExhaust = 2, -- based on seconds
    minedEffect = 50, -- effect on success
    failEffect = CONST_ME_POFF, -- effect on fail
    pickId = 4874, -- dwarven pickaxe
    rockMineId = 3666, -- rock ID to use with pickaxe
    smallRockId = 3668, -- ID to change to when mining successful
    rockMineRegeneration = 5, -- Seconds till it regenerate from the small rock to the mineRock
    position = Position(32359,32239,7), --position of your prison
    templePosition = Position(32369,32241,7), -- currently Thais Temple
    wagonAid = 39011, -- the actionid used for the ore wagon
    MiningRockActionId = 39012, -- the actionid used for rockMineId's inside the mine
}

--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()..".")
    targetPlayer:addItem(prison.pickId)
    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) == prison.miningExhaust then
        --print("Exhausted")
        player:sendCancelMessage("You are exhausted.")
        return true
    end
    --print("player storage is set to "..player:getStorageValue(prison.exhaustStorage).." while exhaust is ".. prison.miningExhaust .."")
    player:setStorageValue(prison.exhaustStorage, prison.miningExhaust)
    addEvent(function()
        player:setStorageValue(prison.exhaustStorage, -1)
        player:sendCancelMessage("Swing!")
    end, prison.miningExhaust * 1000)
  
    local randomChance = math.random(1,100)
    if randomChance > prison.chance then
        target:getPosition():sendMagicEffect(prison.failEffect)
        player:sendCancelMessage("No materials found.")
        return true
    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 * 1000, 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.pickId, 1)
        player:removeItem(prison.materialId, count)
        player:setStorageValue(prison.storage, 0)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been released from prison, lets try not to return again.")
        player:teleportTo(prison.templePosition)
        return true
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You still need to mine "..releaseCount - count.." ore(s) 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)

Map Preview
(This is Thais Sewers next to depot if you use a RL Map and want to mimic my idea.
Attempting to allow players walking by too see the mine/players jailed.)
1663363794498.png
(Map File attached to post)

Please note the teleport in the mine would normally take you to a small room in the temple where the players can't leave with a portal leading back to the mine.. this allows the whiners to talk to people in temple (acting like they are stuck).

An example:
1663364000354.png

You may also want them to practice being a better person while in jail so they dont become repeat offenders.
1663365167781.png
 

Attachments

Last edited:
OP
OP
Shadow_

Shadow_

Veteran OT User
Joined
Jun 2, 2018
Messages
1,016
Solutions
31
Reaction score
429
Hey guys would like to feature my contribution/fix + map update.

-Exhaust wasn't working properly so I modified to work based on seconds and storage value with an addEvent.
-Regeneration Time for rocks were going to quickly (not 5 seconds) so I also fixed this too.
-Changed storage values to match my projects currently used/unused.
-Changed PickID to be dwarven pickaxe
-Temple position is default Thais position
-Rock ID's changed to similar matching rocks "bigger and smaller"
-Please note the matierlID is a scarab coin; should probably change this if you want the system to feel more realistic in a sense.

Code:
--A prison system to punish player.  [Storages Used, 78913,78914] [Action ids used: 8032,8033]
local prison = {
    storage = 39010, -- used for material storage
    exhaustStorage = 39011, -- used for exhaust
    materialId = 2159, -- ore ID recieved from mining
    chance = 20, -- chance to receive materials
    miningExhaust = 2, -- based on seconds
    minedEffect = 50, -- effect on success
    failEffect = CONST_ME_POFF, -- effect on fail
    pickId = 4874, -- dwarven pickaxe
    rockMineId = 3666, -- rock ID to use with pickaxe
    smallRockId = 3668, -- ID to change to when mining successful
    rockMineRegeneration = 5, -- Seconds till it regenerate from the small rock to the mineRock
    position = Position(32359,32239,7), --position of your prison
    templePosition = Position(32369,32241,7), -- currently Thais Temple
    wagonAid = 39011, -- the actionid used for the ore wagon
    MiningRockActionId = 39012, -- the actionid used for rockMineId's inside the mine
}

--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()..".")
    targetPlayer:addItem(prison.pickId)
    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) == prison.miningExhaust then
        --print("Exhausted")
        player:sendCancelMessage("You are exhausted.")
        return true
    end
    --print("player storage is set to "..player:getStorageValue(prison.exhaustStorage).." while exhaust is ".. prison.miningExhaust .."")
    player:setStorageValue(prison.exhaustStorage, prison.miningExhaust)
    addEvent(function()
        player:setStorageValue(prison.exhaustStorage, -1)
        player:sendCancelMessage("Swing!")
    end, prison.miningExhaust * 1000)
 
    local randomChance = math.random(1,100)
    if randomChance > prison.chance then
        target:getPosition():sendMagicEffect(prison.failEffect)
        player:sendCancelMessage("No materials found.")
        return true
    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 * 1000, 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.pickId, 1)
        player:removeItem(prison.materialId, count)
        player:setStorageValue(prison.storage, 0)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been released from prison, lets try not to return again.")
        player:teleportTo(prison.templePosition)
        return true
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You still need to mine "..releaseCount - count.." ore(s) 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)

Map Preview
(This is Thais Sewers next to depot if you use a RL Map and want to mimic my idea.
Attempting to allow players walking by too see the mine/players jailed.)
View attachment 70608
(Map File attached to post)

Please note the teleport in the mine would normally take you to a small room in the temple where the players can't leave with a portal leading back to the mine.. this allows the whiners to talk to people in temple (acting like they are stuck).

An example:
View attachment 70610

You may also want them to practice being a better person while in jail so they dont become repeat offenders.
View attachment 70611
Recommended update
 
Top