• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Rolled Dice value

TFS 1.1 Dice Code is the following.
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local value = math.random(1, 6)
    local isInGhostMode = player:isInGhostMode()

    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)

    local spectators = Game.getSpectators(position, false, true, 3, 3)
    for _, pid in ipairs(spectators) do
        player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, pid, position)
    end

    item:transform(5791 + value)
    return true
end

What you're looking for is the defined value

Code:
local value = math.random(1, 6)

Simply put it where you want to use it as that returns what the script rolls randomly every time it executes (Aka, when someone uses a die it generates a number. The number is then represented as value in the script)

If you need to save it for another script I'd set a player storage to value every time a player rolls a dice, that way you can load the result from any script without making value global.
 
TFS 1.1 Dice Code is the following.
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local value = math.random(1, 6)
    local isInGhostMode = player:isInGhostMode()

    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)

    local spectators = Game.getSpectators(position, false, true, 3, 3)
    for _, pid in ipairs(spectators) do
        player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, pid, position)
    end

    item:transform(5791 + value)
    return true
end

What you're looking for is the defined value

Code:
local value = math.random(1, 6)

Simply put it where you want to use it as that returns what the script rolls randomly every time it executes (Aka, when someone uses a die it generates a number. The number is then represented as value in the script)

If you need to save it for another script I'd set a player storage to value every time a player rolls a dice, that way you can load the result from any script without making value global.

yea that is my script for dice. Everything u said i rode and understand now, Thanks.

But how to get number of rolled . For example we go NPC Casino Man and player rolled dice which is inside his backpack. How NPC can get value of this rolled number by player?
 
First save the value as a storage. (in your dice script)

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local position = item:getPosition()
local value = math.random(1, 6)
local stor = xxxx
local isInGhostMode = player:isInGhostMode()

position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)

local spectators = Game.getSpectators(position, false, true, 3, 3)
for _, pid in ipairs(spectators) do
player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, isInGhostMode, pid, position)
end

player:setStorageValue(stor, value)
item:transform(5791 + value)
return true
end

Then in your NPC script, to get the rolled number simply grab the storage.
player:getStorageValue(xxxx)

I highlighted the important parts.
 
Another thing im wondering xd... If on sqm is dice, is is possible to make it not usable. I wanna use this in script when player have to roll and then script get storage value.

I wanna secure it from overwrite value when player roll again cause then is npc turn to roll and after npc roll dice will be usable again.

one turn - one roll !
 
very quick example with useless functions
roll dice script..
Code:
if storage value = 1 then
roll
set storage value, 1
else
return false
end
Make the npc give the storage value, then let the dice script take it away.
And possibly make it check if the dice is on a certain tile as well.. if there is only going to be 1-10 of these npcs.. so you don't have to make a separate script for regular dice.

or create another dice script with the function.. and add an actionID to the dice..
and create a creaturescript to stop players from moving/picking up the dice.
 
Back
Top