Skip to content

Instantly share code, notes, and snippets.

@Poeticalto
Last active March 19, 2018 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Poeticalto/70da07daa89f66658e0872514aa10ae8 to your computer and use it in GitHub Desktop.
Save Poeticalto/70da07daa89f66658e0872514aa10ae8 to your computer and use it in GitHub Desktop.
A proof of concept script to show how caps can be calculated in no-script games using sound events
// ==UserScript==
// @name TagPro No Script Cap Detector
// @author Poeticalto
// @include http://tagpro-*.koalabeast.com*
// @description A proof of concept script to show how caps can be calculated in no-script games using sound events
// @grant GM_getValue
// @grant GM_setValue
// @version 0.02
// ==/UserScript==
if (window.location.pathname.match(/^\/groups\/[a-z]{8}$/)) { //This part is used to get the player's team so it doesn't need to be checked in game.
tagpro.ready(function(){
var tpUserId = 'none';
group = tagpro.group = Object.assign(tagpro.group, {//slight modification of Ko's GroPro group object tracker to keep track of teams
self: undefined,
players: {}
});
tagpro.group.socket.on('you', function(p){
group.self = p;
});
var socket = group.socket;
socket.on('member', function(member) {
group.players[member.id] = Object.assign(group.players[member.id] || {}, member);
});
});
window.onbeforeunload = function(){//updates vars before leaving page
if (typeof group.self != "undefined" && typeof group.players != "undefined" && typeof group != "undefined"){ //idk what this is but I wrote it and it works
GM_setValue("userTeam",group.players[group.self].team);
}
else if (typeof group.self == "undefined"){//If tpUserId isn't set, set Team to none (prevents cap updates)
GM_setValue("userTeam","none");
}
};
}
(function(window) {
'use strict';
if(!window.tagpro) {//comp game is detected when the tagpro object does not exist
var userTeam = GM_getValue("userTeam",3);//1 is red, 2 is blue, 3 is green
console.log('Comp game detected, activating Cap Detector Script');
var updateRedCaps = 0;
var updateBlueCaps = 0;
var firstSound = true; // used to detect the start of the game
document.getElementById("cheering").addEventListener('play',function(){
// The following three lines are test code that replaces sound effects
document.getElementById("cheering").pause();
document.getElementById("cheering").currentTime = 0;
document.getElementById('alertlong').play();
// This can be used for any standard tagpro sound, since they are all loaded into the document
if (firstSound == true){ //the first cheering sound starts the game, so don't increment cap counter
console.log('Start of comp game detected');
firstSound = false;
// Do userscript stuff for when the game starts
}
else if (userTeam == 1){ // adds cap to Red team
updateRedCaps += 1;
capUpdate();
}
else if (userTeam == 2){ // adds cap to Blue team
updateBlueCaps += 1;
capUpdate();
}
},false);
document.getElementById("sigh").addEventListener('play',function(){
if (userTeam == 1){
updateBlueCaps += 1;
capUpdate();
}
else if (userTeam == 2){
updateRedCaps += 1;
capUpdate();
}
},false);
// Note: play event does not activate if game sounds are muted
// However, play event does activate is volume is set to 0 (but no mute)
function capUpdate(){ // this is a generic score update function, modify it however you want
console.log('Cap detected, score is now '+updateRedCaps+'-'+updateBlueCaps);
}
}
})(unsafeWindow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment