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
local value = math.random(1, 6)
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.
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
player:getStorageValue(xxxx)
if storage value = 1 then
roll
set storage value, 1
else
return false
end