Forum Moderators: open

Message Too Old, No Replies

Warcraft 2 Annoyed Click Secret Script

More work?!

         

JAB Creations

2:54 am on Feb 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you've played Warcraft 2 or Warcraft 3 you know by continuously clicking on characters they eventually get annoyed and say funny things. Here on WebmasterWorld a few years back I had some help creating a script that would load a page that would play a SWF sound to emulate that behavior. However the script is static thus not allowing a parameter to choose the personality and I would like this script to work without requiring the presence of frames. Here is the original script...

if (parent.border)
{
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
parent.border.location
= 'home/home-border-top-pissed-peasant-'
+ (clickCount/clickSpacing)
+ '.php';
}
}

The new script should support two parameters, person and the click cycle. There are different people to annoy and some have more material then others. However a nice constant is that a sound function is triggered every fourth click. Once the script reaches the clickCycle it loops/resets back to zero.

The tricky part for me is figuring out how to work with parameters to create dynamically generated calls to a different script that handles sound events. This script only needs to call events. Here is an example list...

soundManager.play('peasant1');
soundManager.play('peasant2');
soundManager.play('peasant3');
soundManager.play('peasant4');
soundManager.play('peasant5');

I can have my site use an HTTP query in the script element as my JavaScript files are compressed by PHP and thus I can simply have PHP set echo the person in the script dynamically. I'm really tired right now so this is what I have right now...

- John

function sitepersonality(person, clicks) {
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
{soundManager.play((person)(clickCount/clickSpacing));}
}
}

eelixduppy

9:53 pm on Feb 26, 2008 (gmt 0)



Don't you mean to have something like the following?

soundManager.play(person+(clickCount%clickSpacing));

Try that to see what you get...

JAB Creations

7:57 pm on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is what I have thus far though clicking triggers no events that I am aware of. I'm not sure what the generated output looks like however.

function sitepersonality() {
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
var person = peasant;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
{
soundManager.play('person+(clickCount%clickSpacing)');
}
}
}

Here is what the code looks like in a static test case...

<span onclick="soundManager.play('peasant1');">sound 1</span>
<br />
<span onclick="soundManager.play('peasant2');">sound 1</span>

- John

eelixduppy

8:00 pm on Feb 27, 2008 (gmt 0)



Try taking away the quotes as I have shown you up above in my last msg:

function sitepersonality() {
var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
var person = peasant;
document.onclick = function()
{
clickCount = ++clickCount % clickCycle // if 22, return to zero
if(clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
{
soundManager.play(person+(clickCount%clickSpacing));
}
}
}

JAB Creations

10:23 pm on Feb 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing happens and there aren't any error messages in Opera 9.5 or Firefox 2. I'm not sure what else to do?

- John

eelixduppy

10:27 pm on Feb 27, 2008 (gmt 0)



replace the playing of the sound with an alert to make sure that it's actually being called.

JAB Creations

1:06 am on Feb 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I get no alerts when clicking numerous times...

alert(person+(clickCount%clickSpacing));

- John

JAB Creations

9:45 am on Feb 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ha! I got it working, check it out. ;) Now that I have this working I'm going to find some more people to annoy...err besides you folks. :-D

- John

var clickCount = 0;
var clickSpacing = 4;
var clickCycle = 22;
window.onclick = clickPage;
function clickPage()
{
var person = 'peasant';
clickCount = ++clickCount % clickCycle // if 22, return to zero
if (clickCount &&!(clickCount % clickSpacing)) // if clickCount is non-zero multiple of clickSpacing
{
alert(person+clickCount/clickSpacing);
soundManager.play(person+clickCount/clickSpacing);}
}