Getting advanced betting options ("all" and "half")

Hey everybody.

i’d mess a little bit with the betting script of the stable 3.0.0 version of the bot.
What i wanted to have was a non numbered betting amount like “all” or “half” of the users points.

i think it would be only a simple edit of the original script and now i ask you guys, if this would work :smiley:

here’s the edited section of the betting system:

/**
 * @function bet
 * @info Used to place a bet on a option.
 *
 * @param {string} sender
 * @param {int} amount
 * @param {string} option
 */
function vote(sender, amount, option) {
    if (bet.status === false || bet.opened === false) {
        // $.say($.whisperPrefix(sender) + 'There\'s no bet opened.');
        return;
    }
    if (amount == "all" || amount == "half") {
        if (amount == "all") {
            amount = $.getUserPoints(sender);
            if (bet.maximum !== 0 && amount > bet.maximum) {
                amount = bet.maximum;
            }
        } else {
            amount = Math.floor($.getUserPoints(sender)/2);
            if (bet.maximum !== 0 && amount > bet.maximum) {
                amount = bet.maximum;
            }
        }
    }
    if (isNaN(parseInt(amount)) || option.length === 0) {
        message(sender, $.lang.get('bettingsystem.bet.usage'));
        return;
    } else if (amount < 1) {
        message(sender, $.lang.get('bettingsystem.bet.error.neg', $.pointNameMultiple));
        return;
    } else if (bet.minimum > amount) {
        message(sender, $.lang.get('bettingsystem.bet.error.min', bet.minimum));
        return;
    } else if (bet.maximum < amount && bet.maximum !== 0) {
        message(sender, $.lang.get('bettingsystem.bet.error.max', bet.maximum));
        return;
    } else if ($.getUserPoints(sender) < amount) {
        message(sender, $.lang.get('bettingsystem.bet.error.points', $.pointNameMultiple));
        return;
    } else if (bets[sender] !== undefined) {
        message(sender, $.lang.get('bettingsystem.bet.betplaced', $.getPointsString(bets[sender].amount), bets[sender].option))
        return;
    } else if (bet.options[option] === undefined) {
        message(sender, $.lang.get('bettingsystem.bet.null'));
        return;
    }
    bet.entries++;
    bet.total += parseInt(amount);
    bet.options[option].bets++;
    bet.options[option].total += parseInt(amount);
    bets[sender] = {
        option: option,
        amount: amount
    };
    $.inidb.decr('points', sender, amount);
    $.inidb.incr('bettingVotes', option.replace(/\s/, '%space_option%'), 1);
}

So, what it should do:

  • check for the betting amount “all” or “half”
    • if amount is “all”, check if the user have more points then the maximum betting value. if he have more points, automatically set the betting maximum as “all”. (i.e. “800”)
    • if the amont is “half”, get the points aswell and cut the value in half and additionally round it down to void decimal amounts. (i.e. the half of 63 would be 31.5 … betting amount -> 31)

If these checks are done, the script should work through the normal else if’s…

So, guys… what do you think? :slight_smile:
I didn’t tested this snippet until now.

Edited:
Hey guys,

i’ve edited the code above and it seems to be working now. Had to change the if’s a bit…
But with this modified function viewer can bet “all” or “half” their points (until the bet.max is reached (if set))…