76
Post New Requests Here / Re: IDEA: Chaturbate Game in Javascript
« on: May 11, 2016, 12:36 PM »Not a response on your inquiry, but general food for thought on such requests. It might be better for a more targeted inquiry, and definitely good to mark your link with NSFW. That is just because it is a mixed audience, and it's good to be mindful of that, more than anything wrong with the fact that you're asking, or the subject matter of it.
This might also be a reason that you might not get the replies that you want, as the usual suspects might not fall into the categories of wanting the tracking on their machine as they work on such a project.
Just an FYI. Best of luck with your efforts!-wraith808 (May 11, 2016, 12:26 PM)
Good call, thank you for that. I've been banging away at some Javascript and as it turns out, if people would like to test their scripts, they can do so in a non-NSFW enviironment here: https://yyanx.github.io/CB-TestBed/
I'm still learning the ins-and-outs of Javascript and boy, I didn't realize how much code you have to compact in order for things to work correctly.
EDIT: Here is my code so far:
Spoiler
//Variables
var setupComplete = false;
var setupTime = 2 * 60 * 1000;
var playCost = 50;
var voteCost = 10;
var voteTime = 5 * 60 * 1000;
var tipTotal = 0;
var winnerFlag = false;
var currentTip = 0; var cbWinner = 'No one yet!'; var lastPrize = 'Nothing';
var players = [{cbuser:cb.room_slug, message: 'Initial Card Setup', index: 1, votes: 0}];
var currentlyPlaying = [cb.room_slug];
//Initialize CAH
function init()
{
//Initial Notice
//Let users know the game has started
cb.chatNotice('Chaturbate Against Humanity has begun!', '', 'gold','red', 'bold', 'lightblue');
//Init Black Card
setBlack();
//Set Broadcaster Card
players[0]['message'] = whiteCard();
//Room Enter
//Inform new users of the current App playing
cb.onEnter(function(user) {
cb.chatNotice('Welcome ' + user['user'] + '! We are playing Chaturbate Against Humanity! The rules are as follows:' );
});
//Timed Setup
//Users are given X minutes to add a white card
//cb.setTimeout(Setup, setupTime);
//When User Tips
cb.onTip(userTipped);
//When User Chats
cb.onMessage(OnMessage);
};
//Set Black Card
//Set the room topic to the CAH Black Card
function setBlack()
{
//Change Room Subject
cb.changeRoomSubject('[Black Card] #CAH');
};
//Handle Tip
function userTipped(tip)
{
//Wait for Players
if (players.length < 2
)
{
//Check for new tip
//White Card Tip
if (tip['amount'] >= playCost
)
{
//Add White Card
//Run addUserCard
addUserCard(tip['from_user']);
}
else
{
//NO
}; //end of IF [White Card Tip]
}
else
{
//Enough Players
//User Already Played?
if (cbjs.arrayContains(currentlyPlaying, tip['from_user'])
)
{
//YES
//Apologize
cb.sendNotice('Sorry, you are already playing the card: ' + getCard(tip['from_user']) + '. You cannot play more than one card.' , tip['from_user']);
}
else
{
//NO
//Add card to the new payer
//Add New Card
addUserCard(tip['from_user']);
}; //end of IF [User Already Played?]
}; //end of IF [Wait for Players]
//DEBUG - # Users In Play
cb.log(players.length.toString());
//DEBUG - List All Players
//Loop Through Players
for (var i=0;i<players.length;i++
)
{
//Display Players
cb.log('cbuser: ' + players[i].cbuser + ' message: ' + players[i].message + ' index: ' + players[i].index + ' votes: ' + players[i].votes);
}; //end of FOR [Loop Through Players]
};
//Add White Card
function whiteCard()
{
//Get Random White Card
return 'Random Card';
};
//drawPanel
function drawPanel(tipTotal)
{
//TRUE
if (winnerFlag
)
{
//YES
//Determine the game's winner
}
else
{
//NO
//Just redraw the panel
}; //end of IF [TRUE]
//Code
cb.onDrawPanel(function(user) {
return {
'template': '3_rows_of_labels',
'row1_label': 'Tip Received / Goal :',
'row1_value': tipTotal,
'row2_label': 'Winner:',
'row2_value': cbWinner,
'row3_label': 'Prize Won:',
'row3_value': lastPrize
};
});
};
//Get Reward
//Give the user a reward for having the best card.
function getReward()
{
//TRUE
if (cbWinner == cb.room_slug
)
{
//YES
//Looks like the model won this time
}
else
{
//NO
//Reward the user for winning!
}; //end of IF [TRUE]
};
//Get User Card
function getCard(user)
{
//Loop Through Players
for (var i=0;i<players.length;i++
)
{
//Find the User
if (players[i].cbuser == user
)
{
//YES
//Return the Card
return players[i].message;
}
else
{
//NO
}; //end of IF [Find the User]
}; //end of FOR [Loop Through Players]
};
//On Message
function OnMessage(msg)
{
//HODOR
msg.m = 'HODOR';
};
//Add User Card
function addUserCard(user)
{
//Code
var userMessage = whiteCard();
var card = {cbuser: user, message: userMessage, index: players.length + 1, votes: 0};
players.push(card);
currentlyPlaying.push(user);
cb.sendNotice('Your white card is: ' + userMessage, user);
};
//Start Chaturbate Against Humanity
//Let's get on with it already!
init();
var setupComplete = false;
var setupTime = 2 * 60 * 1000;
var playCost = 50;
var voteCost = 10;
var voteTime = 5 * 60 * 1000;
var tipTotal = 0;
var winnerFlag = false;
var currentTip = 0; var cbWinner = 'No one yet!'; var lastPrize = 'Nothing';
var players = [{cbuser:cb.room_slug, message: 'Initial Card Setup', index: 1, votes: 0}];
var currentlyPlaying = [cb.room_slug];
//Initialize CAH
function init()
{
//Initial Notice
//Let users know the game has started
cb.chatNotice('Chaturbate Against Humanity has begun!', '', 'gold','red', 'bold', 'lightblue');
//Init Black Card
setBlack();
//Set Broadcaster Card
players[0]['message'] = whiteCard();
//Room Enter
//Inform new users of the current App playing
cb.onEnter(function(user) {
cb.chatNotice('Welcome ' + user['user'] + '! We are playing Chaturbate Against Humanity! The rules are as follows:' );
});
//Timed Setup
//Users are given X minutes to add a white card
//cb.setTimeout(Setup, setupTime);
//When User Tips
cb.onTip(userTipped);
//When User Chats
cb.onMessage(OnMessage);
};
//Set Black Card
//Set the room topic to the CAH Black Card
function setBlack()
{
//Change Room Subject
cb.changeRoomSubject('[Black Card] #CAH');
};
//Handle Tip
function userTipped(tip)
{
//Wait for Players
if (players.length < 2
)
{
//Check for new tip
//White Card Tip
if (tip['amount'] >= playCost
)
{
//Add White Card
//Run addUserCard
addUserCard(tip['from_user']);
}
else
{
//NO
}; //end of IF [White Card Tip]
}
else
{
//Enough Players
//User Already Played?
if (cbjs.arrayContains(currentlyPlaying, tip['from_user'])
)
{
//YES
//Apologize
cb.sendNotice('Sorry, you are already playing the card: ' + getCard(tip['from_user']) + '. You cannot play more than one card.' , tip['from_user']);
}
else
{
//NO
//Add card to the new payer
//Add New Card
addUserCard(tip['from_user']);
}; //end of IF [User Already Played?]
}; //end of IF [Wait for Players]
//DEBUG - # Users In Play
cb.log(players.length.toString());
//DEBUG - List All Players
//Loop Through Players
for (var i=0;i<players.length;i++
)
{
//Display Players
cb.log('cbuser: ' + players[i].cbuser + ' message: ' + players[i].message + ' index: ' + players[i].index + ' votes: ' + players[i].votes);
}; //end of FOR [Loop Through Players]
};
//Add White Card
function whiteCard()
{
//Get Random White Card
return 'Random Card';
};
//drawPanel
function drawPanel(tipTotal)
{
//TRUE
if (winnerFlag
)
{
//YES
//Determine the game's winner
}
else
{
//NO
//Just redraw the panel
}; //end of IF [TRUE]
//Code
cb.onDrawPanel(function(user) {
return {
'template': '3_rows_of_labels',
'row1_label': 'Tip Received / Goal :',
'row1_value': tipTotal,
'row2_label': 'Winner:',
'row2_value': cbWinner,
'row3_label': 'Prize Won:',
'row3_value': lastPrize
};
});
};
//Get Reward
//Give the user a reward for having the best card.
function getReward()
{
//TRUE
if (cbWinner == cb.room_slug
)
{
//YES
//Looks like the model won this time
}
else
{
//NO
//Reward the user for winning!
}; //end of IF [TRUE]
};
//Get User Card
function getCard(user)
{
//Loop Through Players
for (var i=0;i<players.length;i++
)
{
//Find the User
if (players[i].cbuser == user
)
{
//YES
//Return the Card
return players[i].message;
}
else
{
//NO
}; //end of IF [Find the User]
}; //end of FOR [Loop Through Players]
};
//On Message
function OnMessage(msg)
{
//HODOR
msg.m = 'HODOR';
};
//Add User Card
function addUserCard(user)
{
//Code
var userMessage = whiteCard();
var card = {cbuser: user, message: userMessage, index: players.length + 1, votes: 0};
players.push(card);
currentlyPlaying.push(user);
cb.sendNotice('Your white card is: ' + userMessage, user);
};
//Start Chaturbate Against Humanity
//Let's get on with it already!
init();