Page 2 of 3

Re: PHP/Msql Timers

Posted: Sun Dec 27, 2009 3:00 am
by Perry
Torniquet wrote:
Chris wrote:What if the buff is for defence right. And say it only lasts an hour, but the player is offline for 4. In those 4 hours he gets attacked, and gets extra defence when he shouldn't have?

I guess on the battle script you could check to see if he has any buffs that need to be removed before attacking. But after a while, with so many different types of buffs that will just turn into a mess through the whole site.

Cron would be the best way to do this.
i dont think you could do this through cron tbh (unless you can set a cron to run x amount of time after some1 is buffed).
I don't know much about this but you could maybe have a cron check to see if buffs should be removed at whatever interval.

Re: PHP/Msql Timers

Posted: Sun Dec 27, 2009 10:46 am
by Chris
Perry wrote:
Torniquet wrote:
Chris wrote:What if the buff is for defence right. And say it only lasts an hour, but the player is offline for 4. In those 4 hours he gets attacked, and gets extra defence when he shouldn't have?

I guess on the battle script you could check to see if he has any buffs that need to be removed before attacking. But after a while, with so many different types of buffs that will just turn into a mess through the whole site.

Cron would be the best way to do this.
i dont think you could do this through cron tbh (unless you can set a cron to run x amount of time after some1 is buffed).
I don't know much about this but you could maybe have a cron check to see if buffs should be removed at whatever interval.
Exactly.

Re: PHP/Msql Timers

Posted: Sun Dec 27, 2009 11:31 am
by Torniquet
ye but that would mean there is no set length for a buff...

if you have the cron run every 10 mins... you could get 9 extra mins on the buff time... or you could get 1 minute extra.

you would have to have it run every minute

correct me if i am missin summert

Re: PHP/Msql Timers

Posted: Sun Dec 27, 2009 12:27 pm
by hallsofvallhalla
you could still do it the way I said. It would be very little calculation on the server. If someone attacks someone while they are offline it checks buffs where PID = that players ID, then calculates the time like I mentioned before.

Re: PHP/Msql Timers

Posted: Fri Jan 01, 2010 6:04 pm
by Torniquet
ok with your code halls... it displays seconds.milliseconds...


i can remove the milliseconds npz.

how do i make it so its minutes:seconds.

thnx

Re: PHP/Msql Timers

Posted: Fri Jan 01, 2010 7:17 pm
by hallsofvallhalla

Code: Select all

if (milisec<=0){
    milisec=9
    seconds-=1
}
if (seconds<=-1){
    milisec=0
    seconds+=1
}
else
    milisec-=1
    document.counter.d2.value=seconds+"."+milisec
    setTimeout("display()",100)
} 
add minutes to this equation. if seconds<=60

Re: PHP/Msql Timers

Posted: Fri Jan 01, 2010 8:36 pm
by Torniquet
i dont wanna sound like a complete cunt about this...

but any chance of accually givin abit mroe than 'just add this'

not everyone knows how to use ajax... i have tried doing it, i got it to display the minutes:seconds... but asoon as it hit 0.. it stopped counting.

i appreciate u sharing this code nall... but seriously u have to give some thought to those who dont know what they are doin.

Re: PHP/Msql Timers

Posted: Fri Jan 01, 2010 9:40 pm
by hallsofvallhalla
no problem, its actually javascript, no ajax involved
I am doing this where I can't test it but it should be close

You need to use a modulus operator

Code: Select all

<script language="javascript">
var bufftime = <?php echo $finaltime;?>;
var milisec=0;
var minutes = 0;
var seconds=bufftime;
if (seconds > 60)
{
minutes =seconds / 60;
seconds = seconds % 60;  
}
document.counter.d2.value='30'

function display(){
if (milisec<=0){
    milisec=9
    seconds-=1
}
if (seconds<=-1){
    milisec=0
    seconds+=1
}
if (seconds<=0){
    seconds=60
   minutes-=1
}
else
    milisec-=1
    document.counter.d2.value=minutes+"."+seconds+"."+milisec
    setTimeout("display()",100)
}
display()




</script>
hope that helps and works

Re: PHP/Msql Timers

Posted: Fri Jan 01, 2010 10:48 pm
by Torniquet
Appreciate it halls. appologies on the above, but it frustrates me when people do that kind of thing.

it works... kinda lol.

but i have managed to alter it, because it was displaying minutes with decimals in :s

Code: Select all

var bufftimeEXP = <?php echo $EXPtime;?>;
var milisecEXP=0;
var minutesEXP = 0;
var secondsEXP=bufftimeEXP;

if (secondsEXP > 60)
{
minutesEXP = parseInt(secondsEXP / 60);
secondsEXP = secondsEXP % 60; 
}

function displayEXP(){

if (minutesEXP < 1){
	if(secondsEXP <=20){
		document.counter.experience.style.color='red';
	}
}
if (milisecEXP<=0){
    milisecEXP=9
    secondsEXP-=1
}
if (secondsEXP<=-1){
    milisecEXP=0
    secondsEXP+=1
}
if (secondsEXP<=0){
    secondsEXP=60
   minutesEXP-=1
}
if (secondsEXP < 60 &&  minutesEXP <= -1){
	secondsEXP = 0;
	minutesEXP = 0;
	milisecEXP = 0;
}
else
    milisecEXP-=1
	if (secondsEXP < 10){
		displaysecondsEXP = "0"+secondsEXP
	} else if (secondsEXP > 9) {
		displaysecondsEXP = secondsEXP
	}
    document.counter.experience.value=minutesEXP+":"+displaysecondsEXP
    setTimeout("displayEXP()",100)
}
displayEXP()
whether what i have added in there (the parseInt part) which has caused the next problem, i dont know. but i cant seem to fix it lol.

when it hits 0:0 it goes to -1:60 and counts down again... then -2, -3 the list goes on lol. i have tried moving the if statements around, and no joy. i have tried killing off the timeout... no joy. i have become confused lol

also. a minor thing.... then the seconds reach less then 10, how to i add a 0 infront of the 9,8,7,6 etc and then have it removed when its a double figure?

ok i seem to have fixed the whole running into minus minutes problem. i added


if (secondsEXP < 60 && minutesEXP <= -1){
secondsEXP = 0;
minutesEXP = 0;
milisecEXP = 0;
}
which seems to have done the job. just a case of the missing 0 now -.-

edit again.

i have fixed the missing 0 ^^

damn im getting good @ this lol.

added this into the else conditional

if (secondsEXP < 10){
displaysecondsEXP = "0"+secondsEXP
} else if (secondsEXP > 9) {
displaysecondsEXP = secondsEXP
}

i am sure there are better ways of going about all this. but i dont care lol... i got it working. thts all i give a hoot about

Re: PHP/Msql Timers

Posted: Sat Jan 02, 2010 12:26 am
by hallsofvallhalla
and now you know why I never posted a completed code. You learned so much this way and have solved the problem :)