Need Help Creating a Roll System

avalya

New Member
Reaction score
37
Okey, so on my latest project, which happens to fall into the category of a 5 to 10 player instance map (much like the Molten Core map that probably some of you have played), now I've stumbled across the rolling system.

Basically when a boss dies (or a trash mob for that matter, they have a low chance to drop items as well) I want a message to pop up on everyone's screen; _Item_ has dropped! You have 30 seconds to roll on it.
If a player types roll within the timespan, a message will be shown that displays the number he rolled (integer between 1 and 100), and the highest one at the end of the in-this-case-called timer, wins the item.

Then I thought of making a command that you can type in when items have been dropped (gonna check that with a boolean), probably something like -item, or -is (itemstats) that will show the stats of the item (Agility, Damage, Spell Power, Critical Chance, Dodge Chance and so on) along with the item name on top, along with a 'Recommended for: _Hero_, _Hero_ and _Hero_.'

The tricky part is probably the rolling part and identifying the item that has dropped, the rest I can figure out myself, but that's what I need help with (figured I could post the entire idea here, just to give you some information).

Thanks in advance for anyone who take their time to respond with helping answers, and +rep to them!
 

millz-

New Member
Reaction score
25
To be honest, making such a system would be far more easier making it in JASS at the least. While coding in JASS, you can simply make a function that takes in the item as an argument, then generate the timer spanned for the particular item parsed in. Then if a player types -roll or something while this timer is running, show to all players the rolled integer and store it in an array or something. When this timer expires, give the item to the player who rolled the highest integer. Dealing with same numbers could be a problem though, depending on how you want it to be. Well, if you have no idea how to do it with JASS, it could be a pain to do with GUI, but I am not sure.

Maybe at the part of your trigger where dropped item is created, store the created item into a variable, the stats of the items into another variable, and create a countdown timer.

Are you asking for answers or guidelines to create such a system?



Edit: To effectively create this system, you should at least have some sort of item indexing system already in your map.
 

avalya

New Member
Reaction score
37
More like guidelines, I can comprehend JASS but I cannot code it, from my point of view, it'd be possible to do in GUI, since I can preset the stats on every item easily and then show that text to the player, the problem is the rolling part.
 

HydraRancher

Truth begins in lies
Reaction score
197
More like guidelines, I can comprehend JASS but I cannot code it, from my point of view, it'd be possible to do in GUI, since I can preset the stats on every item easily and then show that text to the player, the problem is the rolling part.

I would be very hard to make MII in GUI. (Multiple Item Instancable)
 

avalya

New Member
Reaction score
37
Fortunately, I've got a lot of time. :)

Would I be able to create 10 (max players) triggers that turn on whenever an item drops that, when a player types -roll, it gives a random number between 1 and 100, then stores that number in an array and when the time expires, it takes the highest real (can use real numbers for it, just displayed as integers when rolling to have a VERY small chance to roll the same)?
 

Exfyre

hmm...
Reaction score
60
I took a few hours to write it in JASS. All you gotta do is make a trigger called Roll and convert it to custom text (Edit->convert), and then paste this code into it. Read the comments in the code if you want to edit anything. The attached map has an example of something you may want to do.

JASS:
//To find the time left on the current roll:
//in GUI, Action->Custom Script->
//set udg_VARNAME = Roll_getTimeLeft()          Note that VARNAME should be a real variable,
//                                              where VARNAME is the name of the variable in GUI
//
//set udg_VARNAME = Roll_getTimer()             Note that VARNAME should be a timer variable.^
//                                              Useful for creating countdown timers
//
//You may edit the section labeled "CONFIGURABLES" below.  Edit everything else at your own risk
scope Roll initializer init
globals
    //CONFIGURABLES
    private constant integer MAXPLAYERS = 10  //number of user players
    private constant string MESSAGE = "-roll"  //this is the text users type to roll
    private constant string ROLLNEXT = "You may now roll for the item: "  //This text is displayed before the item name
    private constant string WINTEXT = " has won the item: " //This text is displayed after the player name and before the item name
    private constant string ROLLTEXT = " has rolled "  //player name + ROLLTEXT + roll num.
    private constant real TIME = 30  //number of seconds to roll  must be a whole number (not fraction or decimal)
    //ENDCONFIG
    
    
    private integer array rollval[MAXPLAYERS]
    private boolean array hasrolled[MAXPLAYERS]
    private item array items
    private real timeleft = TIME
    private integer numrolled = 0
    private integer index = 0
    private timer periodic = CreateTimer()
    private timer absolute = CreateTimer()
    private trigger text = CreateTrigger()
    private item currentitem
    private integer maxplayers = 0
endglobals

public function getTimeLeft takes nothing returns real
    return timeleft
endfunction

public function getTimer takes nothing returns timer
    return absolute
endfunction

private function get takes nothing returns item
    set index = index - 1
    if index == 0 then
        call DisableTrigger(text)
        call PauseTimer(periodic)
        call PauseTimer(absolute)
    else
        call BJDebugMsg(ROLLNEXT + GetItemName(items[index+1]))
    endif
    return items[index+1]
endfunction

private function countdown takes nothing returns nothing
    local integer i = 0
    local integer winner = 0
    set timeleft = timeleft - 1
    //call BJDebugMsg(I2S(R2I(timeleft)))       //Take away slash marks at the beginning to show amount of time left
    if numrolled == maxplayers or timeleft == 0 then
        set timeleft = TIME
        loop
            exitwhen i == MAXPLAYERS
            set hasrolled<i> = false
            if rollval<i> &gt; rollval[winner] then
                set winner = i
            elseif rollval<i> == rollval[winner] then
                if GetRandomInt(1,2) == 1 then
                    set winner = i
                endif
            endif
            set i = i + 1
        endloop
        set numrolled = 0
        call BJDebugMsg(GetPlayerName(Player(winner)) + WINTEXT + GetItemName(currentitem) )
        call SetItemPlayer(currentitem, Player(winner), false)
        set currentitem = get()
    endif
endfunction

private function add takes item i returns nothing
    set index = index + 1
    set items[index] = i
    if index == 1 then
        set currentitem = items[index]
        call BJDebugMsg(ROLLNEXT + GetItemName(currentitem))
        call EnableTrigger(text)
        call TimerStart(periodic, 1, true, function countdown)
        call TimerStart(absolute, TIME, false, null)
    endif
endfunction

private function act takes nothing returns nothing
    local item i = GetManipulatedItem()
    local unit u = GetTriggerUnit()
    local boolean canadd = true
    local integer ii = 0
    //call TriggerSleepAction(.12)
    if index != 0 then
    loop
        exitwhen ii == index
        set ii = ii + 1
        if items[ii] == i then
            set canadd = false
        endif
    endloop
    endif
    if GetPlayerId(GetItemPlayer(i)) &gt; MAXPLAYERS and GetItemPlayer(i) != GetOwningPlayer(u) then
        call UnitRemoveItem(u, i)
        call SetItemPlayer(i, Player(MAXPLAYERS+1), false)
        if canadd == true then
            call add(i)
        endif
    endif
endfunction

private function roll takes nothing returns nothing
    local integer p = GetPlayerId(GetTriggerPlayer())
    if hasrolled[p] == false and index &gt; 0 then
        set numrolled = numrolled + 1
        set rollval[p] = GetRandomInt(1, 100)
        call BJDebugMsg(GetPlayerName(Player(p)) + ROLLTEXT + I2S(rollval[p]))
        set hasrolled[p] = true
    endif
endfunction

private function assign takes nothing returns nothing
    call SetItemPlayer(GetSoldItem(), GetOwningPlayer(GetBuyingUnit()), false)
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local trigger tt = CreateTrigger()
    local integer i = 0
    call TriggerAddAction(t, function act)
    call TriggerAddAction(text, function roll)
    call TriggerRegisterAnyUnitEventBJ(tt, EVENT_PLAYER_UNIT_SELL_ITEM)
    call TriggerAddAction(tt, function assign)
    loop
        exitwhen i == MAXPLAYERS
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            set maxplayers = maxplayers + 1
        endif
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
        call TriggerRegisterPlayerChatEvent(text, Player(i), MESSAGE, true)
        set i = i + 1
    endloop
endfunction

endscope</i></i></i>
 

Attachments

  • Roll.w3x
    21.3 KB · Views: 75

avalya

New Member
Reaction score
37
Wow thanks, gonna try it out now, +rep!

Edit: it works, but whenever I roll on a second item, my roll is not reset (I win it automatically), also, will it wait until the time is up and then give the item to the hero?
 

Exfyre

hmm...
Reaction score
60
oh. guess i didnt catch that. I'll update the code in like 2 seconds.

EDIT: updated the code (not the map tho). just copy the code in my post into the map if you want to test
 

avalya

New Member
Reaction score
37
So, by the way, is everything needed for it in that JASS code, meaning I don't have to use any GUI to complement it?
 

Exfyre

hmm...
Reaction score
60
you would only need GUI if you want to do something like display the remaining time for the roll in a timer window (given in the example code in the map), but it should work perfectly by itself.
 

avalya

New Member
Reaction score
37
So, this works for every item that is picked up from the ground? Will it trigger from buying items? Will the items stack up while rolling -- so that one item is only rolled at a time, and when it is won, roll on the next one?
 

avalya

New Member
Reaction score
37
Okey, that's nice, could you re-upload the map, since I can't use vJass, only normal Jass. :p
 

Exfyre

hmm...
Reaction score
60
done, and i found out that it does trigger when the unit buys an item, so I'm recoding now to try to find a way around it.
 

avalya

New Member
Reaction score
37
Okey, thought so since acquiring an item counts as both buying and picking things up. It's very nice of you taking your time. :)
 

Exfyre

hmm...
Reaction score
60
i was able to find a workaround, and I've updated the map and the new code. Goin to bed now lol >.> midnight, I'll check thread in the mornin
 

avalya

New Member
Reaction score
37
Just found out the the text is going crazy after rolling on more than one item, it stops saying the 'You can now roll on: ____' when the item is picked up, but instead says it after the roll.
 

Exfyre

hmm...
Reaction score
60
just got home, looking into that now..

EDIT: It seems to work fine for me. I will reupload the map to make sure you have the same one.

EDIT: Yes, it seems I had forgotten to upload the correct map, so it is now up.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top