• 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!

[tfs 1.2] Summon based in dice roll, with prize for monsters killed

dkangel83

Member
Joined
Mar 31, 2010
Messages
148
Reaction score
18
Location
Brazil
Hiho :) i'd like to know if anyone could share/create script that summon random monster based in dice roll.. with some custom options

i'll create a room and put the basin or whatever inside, A teleport will be put out there so the player can enter in the room and a tp will be inside to player be able to leave whenever he wants to.. so

I tried using this one as base but it gives some console errors and the owner of appear not to care about anymore



Code:
<action actionid="8733" script="diceLever.lua"/>
<action uniqueid="8734" script="diceLever.lua"/>


Code:
<event type="kill" name="diceKill" script="diceKill.lua"/>
<event type="login" name="diceLogin" script="diceKill.lua"/>


Code:
<movevent event="StepIn" actionid="8730" script="diceMove.lua"/>

Code:
function onStartup()
    setGlobalStorageValue(182221, -1)
    return true
end

Code:
<globalevent name="diceStart" type="start" script="diceStart.lua"/>

So with this base..

1 - I need to make tp do not teleport iof someone already inside.

2 - setting up monsters based in number rolled
for 1 it will summon only of x, x ,x ,x
for 2 it will summon only one of y, y, y, y
etc..

3 - only 1 roll per time, monster need to be killed to be able to roll the dice again

4 - For each tier of monsters killed it will give points
monsters from tier 1 will give 1 point
monsters from tier 2 will give 2 points
etc

5 - Dying for any mob the player will be tpd to a room with a reward chest and get a random reward based in points made by killing mobs

dying with 0 points no prize
dying with 1 points change to get x, x, x,
etc

6 - A safe tp that will be there in case player want to leave, so he'll be tped to the reward room to get the reward (d'oh)

7 - If the player logout inside there for some reason he'll lose all points and when login back he'll need to be tpd to his city temple. The monster inside need to die and the room set free for use again..

Thanks in Advance
DeCarvalho​
 
Last edited:
You make a request. You want someone to make script for you and it is forbidden.

If you really want that script you should try to make this step by step, show script with code tags (not spoiler or pastebin) and show errors, im pretty sure someone will answer and help you fix errors.
 
Well @Shadow Dan , thanks for your words but look, im totally noob about.. i used pastebin cuz i cant post entire codes here for this one, its too big and ofc that you know the posts have a limit so for is better to use pastebin instead creating lots of posts.. i dont wanr be warned about anything for making 4 posts. .. im just being logical

This 'system' is for an older version.. and i use 1.2 'another' and i dont know changes in functions/params from that one to new one..

i didnt posted any error cuz i think theres no sense in post an error received by using a really different version system.. ofc trying to using 0.x.x on 1.2 will give errors..

and yes.. i made a request but by mistake i made this post in support.. would like sum1 to move to the right section but dont know anyone to. im sorry about.

back to the topic... i think the main thing here is to adapt the old version to new one with some changes.. its too big to me right now.. im stucked at another request that i've made, im trying to get some clue by looking tons of scripts to try understand the functions to make by myself..

I dont want ppl to look me just like a leecher .. i really do want to learn some.. but well baby steps here :) any help is welcome

Sorry for my bad english and thanks once again
 
Took me only 5min, you can make the rest. Since it's similar to the codes i've alrdy made:
Code:
local config = {
    roomRaidusX = 8,
    roomRadiusY = 6,
    monsters = {
        [1] = {"Rat", "Cave Rat"},
        [2] = {"Dragon", "Dragon Lord"},
        [3] = {"Hero", "Black Knight"},
        [4] = {"Ice Golem", "Frost Dragon"},
        [5] = {"Behemoth", "Demon"},
        [6] = {"Ferumbras", "Orshabaal"}
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local spectator = Game.getSpectators(position, false, false, config.roomRaidusX, config.roomRaidusX, config.roomRadiusY, config.roomRadiusY)
    if #spectator > 1 then
        player:say("You have to kill all the monsters, before roll the dice again.", TALKTYPE_MONSTER_SAY, false, 0, position)
        return true
    end

    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)
    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)

    local value = math.random(6)
    item:transform(5791 + value)
    for i = 1, #config[value] do
        Game.createMonster(config[value][i], position, true, false)
    end

    position:sendMagicEffect(CONST_ME_CRAPS)
    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
    player:setStorageValue(1000, value) -- This will let us know which point value they should gain
    player:setStorageValue(1001, 0) -- Here we count the points
    player:registerEvent("onKillDice")
    player:registerEvent("PrepDeathDice")
    return true
end

local reward = {
    {points = 1, items = {{2152, 10}, {2148, 100}},
    {points = 10, items = {{2160, 1}, {2152, 50}}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for i = 1, #reward do
        if player:getStorageValue(1001) >= reward[i].points then
            player:addItem(reward[i].items[1], reward[i].items[2])
            break
        end
    end

    return true
end

local config = {
    roomCenterPosition = Position(1000, 1000, 7),
    roomRadiusX = 8,
    roomRadiusY = 6
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end

    local spectator = Game.getSpectators(config.roomCenterPosition, false, true, config.roomRaidusX, config.roomRaidusX, config.roomRadiusY, config.roomRadiusY)
    if #spectator ~= 0 then
        player:say("There is somebody already insidie.", TALKTYPE_MONSTER_SAY, false, 0, position)
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return false
    end

    player:teleportTo(config.roomCenterPosition, true)
    config.roomCenterPosition:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    player:setStorageValue(1001, math.max(1, player:getStorageValue(1001)) + player:getStorageValue(1000))
    return true
end

local rewardRoom = Position(100, 100, 7)

function onPrepareDeath(player, killer)
    if player:getStorageValue(1001) == 0 then
        local templePosition = player:getTown():getTemplePosition()
        creature:teleportTo(templePosition)
        templePosition:sendMagicEffect(CONST_ME_TELEPORT)
    else
        creature:teleportTo(rewardRoom)
        rewardRoom:sendMagicEffect(CONST_ME_TELEPORT)
    end

    player:setStorageValue(1000, 0)
    player:setStorageValue(1001, 0)
    player:unregisterEvent("onKillDice")
    player:unregisterEvent("PrepDeathDice")
    return false
end
 
Took me only 5min, you can make the rest. Since it's similar to the codes i've alrdy made:
[...]

Thanks for and i tried by myself to 'configure' it right but w/o success.. even asked a friend to see if he could try help me to put the script in right place but nothing..

Im kind confused 'cos i can see theres onUse, onKill, onStepIn, onPrepareToDeath and well.. is this only 1 script or 3 in 1..
im not sure about but onUse is action, onStepIn is movement, onKill/onPrepareToDeath is creaturescripts.. right?
also i dont get that spectator thing.. im starting to learn and the place that i use to get funcitons information is from luascript.cpp tfs 1.2

i tried to separate the code using the logic of the system in 3 and putting in riht places, setting tags.. but nothing, some errors but dunno if error is connected for not having all components together .. if its supposed to be 1 script i really really dont know how to set up

i tried to setup the dice roll thing using this part, to see if it would summon
Code:
local config = {
    roomRaidusX = 8,
    roomRadiusY = 6,
    monsters = {
        [1] = {"Rat", "Cave Rat"},
        [2] = {"Dragon", "Dragon Lord"},
        [3] = {"Hero", "Black Knight"},
        [4] = {"Ice Golem", "Frost Dragon"},
        [5] = {"Behemoth", "Demon"},
        [6] = {"Ferumbras", "Orshabaal"}
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local spectator = Game.getSpectators(position, false, false, config.roomRaidusX, config.roomRaidusX, config.roomRadiusY, config.roomRadiusY)
    if #spectator > 1 then
        player:say("You have to kill all the monsters, before roll the dice again.", TALKTYPE_MONSTER_SAY, false, 0, position)
        return true
    end

    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)
    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)

    local value = math.random(6)
    item:transform(5792 + value)
    for i = 1, #config[value] do
        Game.createMonster(config[value][i], position, true, false)
    end

    position:sendMagicEffect(CONST_ME_CRAPS)
    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
    player:setStorageValue(1000, value) -- This will let us know which point value they should gain
    player:setStorageValue(1001, 0) -- Here we count the points
    player:registerEvent("onKillDice")
    player:registerEvent("PrepDeathDice")
    return true
end

and a tag in actions

Code:
    <action actionid="8733" script="custom/diceroll.lua"/>

when i roll the dice the console show an error

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/diceroll.lua:onUse
data/actions/scripts/custom/diceroll.lua:23: attempt to concatenate global 'value' (a nil value)
stack traceback:
        [C]: in function '__concat'
        data/actions/scripts/custom/diceroll.lua:23: in function <data/actions/scripts/custom/diceroll.lua:14>

ps the dice always rolls 1
[edit] i changed the line local value = math.random(6) that was right before item:transform(5791 + value) to just before position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player) and now the dice is rolling w/o any error.. but no monster appear[/edit]

well i wont paste all things that i tried, so i deleted everything to start again.. this time asking for some explanation .. i know that you told to me to make the rest but i really dont know how.. i was trying since you posted here ..

could you, pretty pretty please, help me? some guidance will be great :)
 
Last edited:
It's trying to access the variable value on L23, but it's declared on L25 (hence the error). You can remove L22-23.

There is also errors on L27-28. Change config[value] to config.monsters[value].
 
It's trying to access the variable value on L23, but it's declared on L25 (hence the error). You can remove L22-23.

There is also errors on L27-28. Change config[value] to config.monsters[value].

Thanks for the tips

Little before you post it i tried changing a line (i made edit in my last post), but i did what you told.. i made the change in l27-27 also a comment -- in 22/23

everything still the same.. the dice rolls fine but no monster.. and no error in console..
i dont know if theres anything related to me not using entire script.. im just testing the roll/summon thing..

right now the script is

Code:
local config = {
    roomRaidusX = 8,
    roomRadiusY = 6,
    monsters = {
        [1] = {"Rat", "Cave Rat"},
        [2] = {"Dragon", "Dragon Lord"},
        [3] = {"Hero", "Black Knight"},
        [4] = {"Ice Golem", "Frost Dragon"},
        [5] = {"Behemoth", "Demon"},
        [6] = {"Ferumbras", "Orshabaal"}
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local spectator = Game.getSpectators(position, false, false, config.roomRaidusX, config.roomRaidusX, config.roomRadiusY, config.roomRadiusY)
    if #spectator > 1 then
        player:say("You have to kill all the monsters, before roll the dice again.", TALKTYPE_MONSTER_SAY, false, 0, position)
        return true
    end

--    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)
--    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)

    local value = math.random(6)
    item:transform(5791 + value)
    for i = 1, #config.monsters[value] do
        Game.createMonster(config.monsters[value][i], position, true, false)
    end

    position:sendMagicEffect(CONST_ME_CRAPS)
    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
    player:setStorageValue(1000, value) -- This will let us know which point value they should gain
    player:setStorageValue(1001, 0) -- Here we count the points
    player:registerEvent("onKillDice")
    player:registerEvent("PrepDeathDice")
    return true
end

im assuming the radius is based on the place that the dice is, so i dont need to set it, right?
 
how usefull... dont meant to be rude but if ure not going to help do not try get some post .. dont know how here works if can be considered flood but.. really??

if im asking is cuz i dont know at all.. mind to help? yes .. so.. please .. dont help dont bother..

Sorry for being like this but im tired of ppl who thinks that everyone must know everything from scratch..

im in learning.. baby steps.. understand, not? thanks anyway

//Topic

i changed the dice tag.. twas to other/dice.lua and i changed to custom/diceroll.lua and now the dice summon, but 2 monsters instead 2.. and i was thinking..

making this wont make every dice in the server summon a monster? so based on it need i to remove all dices and let just this one?
 
Last edited:
how usefull... dont meant to be rude but if ure not going to help do not try get some post .. dont know how here works if can be considered flood but.. really??

if im asking is cuz i dont know at all.. mind to help? yes .. so.. please .. dont help dont bother..

Sorry for being like this but im tired of ppl who thinks that everyone must know everything from scratch..

im in learning.. baby steps.. understand, not? thanks anyway
I assume it was a place holder for the real content of the post. It seems to of been updated at this point.
 
I assume it was a place holder for the real content of the post. It looms to of been updated at this point.

its a nice point of view.. but what makes be sure about the guy was just walking around is the printer quote about that he needed only 5 minutes and i could make the rest..

Anyway.. i keep trying by myself.. and updating every last post with information about what im doing.. dont know if u have read my post after printer's one but im really confued about whole thing.. and im testing the dice roll cuz is the one that i got some clue..

i do apreciate any help.. criticism and so.. but passing by for 'nothing' what the guy did.. as i said.. im learning way.. and i really dont know how to .. im just assuming things.. and trying.. but if i dont know why not ask for help? at leeast im trying.. im not just standing and waiting for someone to give fully working.. sure would be helpful if someone could tell me how to procced..

im very glad cuz printer gave me the code, i was trying for more than 13hrs by myself .. (i have insomnia) and i still here.. since i dont know everything my base is.. looking scritps with similar functions to use as base for tests.. right before ninjas's tip i made a change who helped me with the error.. but didnt noticed the config.monsters..

i made changes pointed by ninja.. and nothing.. just had an idea about dice using its base script.. after remove the base tag from actions and setting to this one that im using... i got monsters being summoned.. but as i 'said' in last post update..

assuming i made a correct change, what about all dices in server? and well i have a problem with the summon.. it should summon only 1 monster.. random by number rolled.. but its summoning all monsters from that tier..
rolling 1 both rat and cave rat appear.. instead a random of one or another..

//Edit problem with dice was that i was setting the tag as actionid.. now using uniqueid and its okay.. but still summoning all monsters from rolled number.. instead a random of 1
 
Last edited:
What about all dices in the server? Just assign an actionId to the dice, and register that actionId in actions.xml.

The "problem" with the summoning is that a for loop is being used. If you want a random creature from that tier to appear, then use math.random (value should be based on the array length).
 
thanks again and once again just posted little before your post :p
// the problem with dice was that i was setting the tag as actionid.. now using uniqueid and its okay..

tag now
Code:
    <action uniqueid="8733" script="custom/diceroll.lua"/>

about math.random.. i imagined.. just trying to realize how to.. anyway.. i wasnt sure.. with your tip again. i'll try :)

//Edit
Code is like this now

Code:
local config = {
    roomRaidusX = 8,
    roomRadiusY = 6,
    monsters = {
        [1] = {"Rat", "Cave Rat", "Troll"},
        [2] = {"Bug", "Spider", "Cave Rat"},
        [3] = {"Slime", "Troll", "Minotaur"},
        [4] = {"Orc", "Minotaur"},
        [5] = {"Skeleton", "Bear", "Snake"},
        [6] = {"Wolf", "Snake", "Bear"}
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local spectator = Game.getSpectators(position, false, false, config.roomRaidusX, config.roomRaidusX, config.roomRadiusY, config.roomRadiusY)
    if #spectator > 1 then
        player:say("You have to kill all the monsters, before roll the dice again.", TALKTYPE_MONSTER_SAY, false, 0, position)
        return true
    end

--    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)
--    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)

    local value = math.random(6)
    item:transform(5791 + value)
    for i = 1, #config.monsters[value] do
        local rand = math.random(1, #config.monsters[value])
        Game.createMonster(config.monsters[value][rand], position, true, false)     
        player:say(player:getName() .. "You will face the "..config.monsters[value][rand].."! a monster level " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
    end

    position:sendMagicEffect(CONST_ME_CRAPS)
    --player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
    player:setStorageValue(1000, value) -- This will let us know which point value they should gain
    player:setStorageValue(1001, 0) -- Here we count the points
    player:registerEvent("onKillDice")
    player:registerEvent("PrepDeathDice")
    return true
end

Well i still not getting how to make summon only 1, before it was summoning both.. now it is getting a random from tier.. but still summoning all of.. i added more just to test.. random isnt a problem.. problem is to make it create only 1
 
Last edited:
A for loop iterates through an array, and each of the arrays has either an length of 2 or 3. Which means it will create 2-3 monsters when you use the die.

You have two options:
1. Use break to exit the loop.
2. Remove the for loop.
 
Well now i have the roll thing and summoning working..
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local position = item:getPosition()
    local spectator = Game.getSpectators(position, false, false, config.roomRaidusX, config.roomRaidusX, config.roomRadiusY, config.roomRadiusY)
    if #spectator > 1 then
        player:say("You have to kill all the monsters, before roll the dice again.", TALKTYPE_MONSTER_SAY, false, 0, position)
        return true
    end

--    position:sendMagicEffect(CONST_ME_CRAPS, isInGhostMode and player)
--    player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)

    local value = math.random(6)
    item:transform(5791 + value)
    for i = 1, #config.monsters[value] do
        local rand = math.random(1, #config.monsters[value])
        Game.createMonster(config.monsters[value][rand], position, true, false) 
        player:say(player:getName() .. "You will face the " .. config.monsters[value][rand] .. "! a monster level " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
        break
    end

    position:sendMagicEffect(CONST_ME_CRAPS)
    --player:say(player:getName() .. " rolled a " .. value .. ".", TALKTYPE_MONSTER_SAY, false, 0, position)
    player:setStorageValue(1000, value) -- This will let us know which point value they should gain
    player:setStorageValue(1001, 0) -- Here we count the points
    player:registerEvent("onKillDice")
    player:registerEvent("PrepDeathDice")
    return true
end

and i assume that i'll need a lib to make it easy to divive in many scripts so i did

Code:
config = {
    roomCenterPosition = Position(1000, 1000, 7),
    roomRaidusX = 8,
    roomRadiusY = 6,
    monsters = {
        [1] = {"Rat", "Cave Rat", "Troll"},
        [2] = {"Bug", "Spider", "Cave Rat"},
        [3] = {"Slime", "Troll", "Minotaur"},
        [4] = {"Orc", "Minotaur"},
        [5] = {"Skeleton", "Bear", "Snake"},
        [6] = {"Wolf", "Snake", "Bear"}
    }
}

reward = {
    {points = 1, items = {{2152, 10}, {2148, 100}}},
    {points = 10, items = {{2160, 1}, {2152, 50}}}
}

since i saw 2 same config but one having just a line i mixed both.. i think theres no need to have 2 and in this way is better to me to make any edit.. reward too cuz i think its better to have all configurable things in one place.. (better to find in any case)

Im gonna work in

Code:
    player:registerEvent("onKillDice")
    player:registerEvent("PrepDeathDice")

and creature scripts functions.. if im not wrong it will be

Code:
function onKill(player, target)
    if not target:isMonster() then
        return true
    end
    player:setStorageValue(1001, math.max(1, player:getStorageValue(1001)) + player:getStorageValue(1000))
    return true
end

local rewardRoom = Position(287, 172, 9)

function onPrepareDeath(player, killer)
    if player:getStorageValue(1001) == 0 then
        local templePosition = player:getTown():getTemplePosition()
        creature:teleportTo(templePosition)
        templePosition:sendMagicEffect(CONST_ME_TELEPORT)
    else
        creature:teleportTo(rewardRoom)
        rewardRoom:sendMagicEffect(CONST_ME_TELEPORT)
    end

    player:setStorageValue(1000, 0)
    player:setStorageValue(1001, 0)
    player:unregisterEvent("onKillDice")
    player:unregisterEvent("PrepDeathDice")
    return false
end

I noticed the register event for onKillDice and PrepDeathDice in the first part and here i have the unregister event.. so i think i need to register in creaturescripts like

Code:
    <event type="kill" name="onKillDice" script="dicePoints.lua" />
    <event type="preparedeath" name="PrepDeathDice" script="dicePoints.lua" />

im not sure if its right.. but after testing i noticed that in Table: player_storage nothing happen.. theres no storage 1000 nor 1001

// After getting nothing i just used a print to see what happen when i kill a monster..
im not sure if i did right but.. is like this

Code:
function onKill(player, target)
    if not target:isMonster() then
        return true
    end
    print(player:setStorageValue())
    player:setStorageValue(1001, math.max(1, player:getStorageValue(1001)) + player:getStorageValue(1000))
    return true
end

When i kill a monster the console return true.. dont know how to make to console show the point what i get from killing monsters.. system was supposed to give a point based on monster's level..

//I noticed that the system is counting the points but only after the char logout..
i kill a monster and then logout the system will add the points to storage 1000 and 1001 but while online .. nothing .. still trying to get it .. made some tests with different options but nothing..
Wasnt to be like that.. points need to be added after killing and set to 0 after char getting the reward by leaving using a safe portal or dying.. or set to 0 if logout inside the room.
4pDMkqZ.gif
 
Last edited:
Back
Top Bottom