Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active June 17, 2021 16:19
Show Gist options
  • Save dsetzer/fb042a13622945f40ad200540c6443fd to your computer and use it in GitHub Desktop.
Save dsetzer/fb042a13622945f40ad200540c6443fd to your computer and use it in GitHub Desktop.
Script wrapper allowing most bustadice (promise based API) scripts to be used on bustabit (event based API). Reason why I say most scripts is because there are a few differences which have no equivalent like seed change functions.
var config = {
baseBet: { type: 'balance', label: 'Base Bet', value: 100 },
payout: { type: 'multiplier', label: 'Payout', value: 2 },
maxBet: { type: 'balance', label: 'Max Bet', value: 100000 }
};
// Note: if the bustadice script contains a config or options like above,
// then it will need to be separated and placed at the very top still and
// the rest of the script is placed in the designated area below.
class Script {
constructor(context){
this.context = context;
this.log = log;
this.stop = stop;
this.skip = async function(){
return new Promise((r) => {
context.once('GAME_ENDED', () => { r({context.history.first().bust, this.balance}); });
});
}
this.bet = async function(value, target){
return new Promise((r) => {
context.once('GAME_STARTING', ()=>{ context.bet(value, target); });
context.once('GAME_ENDED', ()=>{ r({value, target, context.history.first().bust, this.balance}); });
});
};
this.clearLog = () => {};
this.resetStatistics = () => {};
this.newSeedPair = () => {};
this.setClientSeed = () => {};
}
get balance(){ return this.context.userInfo.balance; }
get username() { return this.context.userInfo.uname; }
async start(){
return new Promise(async (stop) => {
// -- PLACE BUSTADICE SCRIPT BELOW THIS LINE -- //
// Example (basic martingale script)
let currentBet = config.baseBet.value;
for(;;){
this.log(`Next bet ${Math.round(currentBet/100)} bits.`);
const result = await this.bet(Math.round(currentBet/100)*100, config.payout.value);
if(result.multiplier < result.target){
this.log(`We lost ${currentBet/100} bits.`);
currentBet *= (config.payout.value/(config.payout.value-1));
}else{
this.log(`We won ${(currentBet*(config.payout.value-1))/100} bits profit.`);
currentBet = config.baseBet.value;
}
if(currentBet >= config.maxBet.value){
this.log(`Reached max bet. Stopping..`);
this.stop();
}
}
// -- PLACE BUSTADICE SCRIPT ABOVE THIS LINE -- //
});
}
}
var script = new Script(engine);
script.start().then(()=> { log(`stopped`); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment