The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Spooky ghost counter and rank?

Go down

Solved Spooky ghost counter and rank?

Post by Guest on Sat Nov 08, 2014 10:58 pm

Hey there! Mr. Green

I'd have a request... a hard one I think?
So, there was that Spooky Ghost halloween decoration, that made a ghost appear randomly. (http://help.forumotion.com/t136449-decorate-your-forum-for-halloween) It's written if you clicked on the ghost, it banished. Would it be possible to make a counter that counts how many times you clicked on a ghost? I mean, it would count how many ghosts you have seen.

I'd like to create an event on my forum, and the people who have the highest number of found ghosts(clicked on the most)  would win something.
So apart from adding a counter, I'm curious if adding a rankboard for it would be possible? o.o

So ye, that's it. I hope my explanations weren't too confusing. I know it's a lot to ask for, but I'm just curious, and maybe someone already has an existing code for it? Lol
Thanks in advance for any kind of headsups! <3


Last edited by Fédra on Tue Nov 11, 2014 7:01 pm; edited 3 times in total

Guest
Guest


Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Ange Tuteur on Sun Nov 09, 2014 4:40 am

Hello Fédra,

Something like this ? It'll alert the number of Ghosts banished when you click it.


Code:
$(function() {
  // Happy Halloween from Forumotion !
  var ghost = document.createElement('IMG'), actif = false;
  ghost.src = 'http://i39.servimg.com/u/f39/18/21/60/73/ghost10.png';
  ghost.setAttribute('style','position:fixed;top:0%;left:0%;z-index:99999;display:none;');
  document.body.appendChild(ghost);
  
  ghost.onclick = function() {
    var storage = window.localStorage;
    ghost.style.display = 'none';
    if (storage.ghostClicks) storage.ghostClicks = Number(storage.ghostClicks) + 1;
    else if (storage) storage.ghostClicks = 1;
    alert('Ghosts Banished : ' + storage.ghostClicks);
  };
  window.setInterval('_spook_ghost()', 1000);
  _spook_ghost = function() {
    if (random(5) === 4 && actif === false) {
      actif = true;
      ghost.style.left = random(76) + '%';
      ghost.style.top = random(76) + '%';
      ghost.style.width = '48px';
      ghost.style.opacity = '1';
      ghost.style.display = '';
      _animation_ghost = window.setInterval(function() {
        if (Number(ghost.style.opacity) <= 0) {
          ghost.style.display = 'none';
          window.clearInterval(_animation_ghost);
          return actif = false;
        }
        ghost.style.width = Number(ghost.style.width.replace(/px/,'')) + 10 + 'px';
        ghost.style.opacity = Number(ghost.style.opacity) - 0.01;
      },1);
    }
  };
  function random(val) { return Math.floor(Math.random() * val) };
});

Just an example of course. To have a rank I believe you would need your own database. I do have an Idea with a profile field though.
avatar
Ange Tuteur
Forumaster

Male Posts : 13193
Reputation : 2904
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Guest on Sun Nov 09, 2014 5:06 pm

Woah! You're very good at it! Didn't expect such a fast, working reply! Very Happy It's very very very VERY cool!! Thank you sooo much! ùù
I think it's okay this way, the members can printscreen the popup message and post it, so if a rankboard is too much trouble it's perfect in this way too!!  I'm utterly grateful! ùù


edit: One last question. Can I set it to work "In all the pages", or I should leave it to only "In all the pages"? Lol
edit2: and one more sorry. Very Happy Will they appear by themselves randomly from time to time or only when the page is refreshed? 
edit3: could guests be eliminated from this?  So could a restriction be made to make only members able to play? I'm sorry, I know I ask for too much. 

Guest
Guest


Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by armypoilce on Sun Nov 09, 2014 5:52 pm

Nice

armypoilce
New Member

Posts : 3
Reputation : 1
Language : England

http://kiefs-clan.forumotion.co.uk/forum

Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Ange Tuteur on Mon Nov 10, 2014 6:05 am

1. Yes, it can be set in all the pages
2. They have a 1 in 5 chance to appear, no refresh necessary. ( I can edit the chance for appearing if you want )

3. try this, I added a condition to the top :
Code:
$(function() {
  if (_userdata.user_id === -1) return; // excludes guests
  
  // Happy Halloween from Forumotion !
  var ghost = document.createElement('IMG'), actif = false;
  ghost.src = 'http://i39.servimg.com/u/f39/18/21/60/73/ghost10.png';
  ghost.setAttribute('style','position:fixed;top:0%;left:0%;z-index:99999;display:none;');
  document.body.appendChild(ghost);
  
  ghost.onclick = function() {
    var storage = window.localStorage;
    ghost.style.display = 'none';
    if (storage.ghostClicks) storage.ghostClicks = Number(storage.ghostClicks) + 1;
    else if (storage) storage.ghostClicks = 1;
    alert('Ghosts Banished : ' + storage.ghostClicks);
  };
  window.setInterval('_spook_ghost()', 1000);
  _spook_ghost = function() {
    if (random(5) === 4 && actif === false) {
      actif = true;
      ghost.style.left = random(76) + '%';
      ghost.style.top = random(76) + '%';
      ghost.style.width = '48px';
      ghost.style.opacity = '1';
      ghost.style.display = '';
      _animation_ghost = window.setInterval(function() {
        if (Number(ghost.style.opacity) <= 0) {
          ghost.style.display = 'none';
          window.clearInterval(_animation_ghost);
          return actif = false;
        }
        ghost.style.width = Number(ghost.style.width.replace(/px/,'')) + 10 + 'px';
        ghost.style.opacity = Number(ghost.style.opacity) - 0.01;
      },1);
    }
  };
  function random(val) { return Math.floor(Math.random() * val) };
});
avatar
Ange Tuteur
Forumaster

Male Posts : 13193
Reputation : 2904
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Guest on Mon Nov 10, 2014 7:09 pm

Oo, it's just perfect now! Thank you so very much!!! ùù
Solved.~~~
Edit: a member of my forum asked if it counts for IP or account? o.o Because he caught a ghost from another PC with the same account, but it doesn't seem to be recorded? o.o

Edit: last request, I swear!  Could you make less ghosts appear? Cuz now there are too many of them. Like half of the current amount would be fine. Very Happy

Guest
Guest


Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Ange Tuteur on Tue Nov 11, 2014 6:46 am

The ghost clicks are saved to the browser the member is using, if you want I could devise a way that uses a profile field.

Of course, replace the script with this :
Code:
$(function() {
  var chance = 10;
  
  if (_userdata.user_id === -1) return; // excludes guests
  
  // Happy Halloween from Forumotion !
  var ghost = document.createElement('IMG'), actif = false;
  ghost.src = 'http://i39.servimg.com/u/f39/18/21/60/73/ghost10.png';
  ghost.setAttribute('style','position:fixed;top:0%;left:0%;z-index:99999;display:none;');
  document.body.appendChild(ghost);
  
  ghost.onclick = function() {
    var storage = window.localStorage;
    ghost.style.display = 'none';
    if (storage.ghostClicks) storage.ghostClicks = Number(storage.ghostClicks) + 1;
    else if (storage) storage.ghostClicks = 1;
    alert('Ghosts Banished : ' + storage.ghostClicks);
  };
  window.setInterval('_spook_ghost()', 1000);
  _spook_ghost = function() {
    if (random(chance) === 0 && actif === false) {
      actif = true;
      ghost.style.left = random(76) + '%';
      ghost.style.top = random(76) + '%';
      ghost.style.width = '48px';
      ghost.style.opacity = '1';
      ghost.style.display = '';
      _animation_ghost = window.setInterval(function() {
        if (Number(ghost.style.opacity) <= 0) {
          ghost.style.display = 'none';
          window.clearInterval(_animation_ghost);
          return actif = false;
        }
        ghost.style.width = Number(ghost.style.width.replace(/px/,'')) + 10 + 'px';
        ghost.style.opacity = Number(ghost.style.opacity) - 0.01;
      },1);
    }
  };
  function random(val) { return Math.floor(Math.random() * val) };
});

I added a variable to the top :
Code:
var chance = 10;

This determines the chance for the ghost to appear. It used to be 1 in 5, now it is 1 in 10. Adjust the number to change the rate at which the ghost appears.
avatar
Ange Tuteur
Forumaster

Male Posts : 13193
Reputation : 2904
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Guest on Tue Nov 11, 2014 2:54 pm

Oo, thank you very much! Mr. Green
I informed them the clicks are saved to the browser, thank you! Lol

Guest
Guest


Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Ange Tuteur on Tue Nov 11, 2014 4:31 pm

You're welcome. Smile

As long as they do not clear their browser cache their clicks will remain. Wink

This is solved for you now ?
avatar
Ange Tuteur
Forumaster

Male Posts : 13193
Reputation : 2904
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by Guest on Tue Nov 11, 2014 7:00 pm

Lol
Oh, yes, I forgot, it's solved! Thanks a lot!!! Mr. Green

Guest
Guest


Back to top Go down

Solved Re: Spooky ghost counter and rank?

Post by APE on Wed Nov 12, 2014 3:41 am

Topic solved and archived



avatar
APE
Manager
Manager

Male Posts : 11845
Reputation : 1169
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum