Jump to content
MakeWebGames

Giving rewards for staying in the same gang every 50 days


Recommended Posts

Posted

I'm gonna give players rewards for being in the same gang every 50 days. How would you do that? I could do it quite easily with an if-test in the users-update in the daily cron, but if I want to give them an event about it as well? How would you do it?

Thanks!

Posted

Create a function in global funcs like

Function gangCheck()

{

If({$ir['gdays']} == 50)

{

Event_add($userid, "Text here",$c);

}

}

And then add into globals. You'll also need to make sure there gdays hits zero when leaving a gang!

P.S. on phone so sorry or non use of code tags or anything like that and make sure you edit the code properly to make sure it work as this was just me showing you a way to do it!

Posted
Nah, because the user should get the reward even though he/she doesn't log on that day.

Edit: But thanks for the suggestion :)

Create cron to run everyday, increment gdays by 1 or something.

Posted

Just add...

$us = $db->query("SELECT * FROM users");
$fus = $db->fetch_row($fs);
If($fus['gdays'] == 50)
{
event_add($fus['userid'], "Text Here",$c);
}

 

Into cron_day.php?

Posted

Thanks again! Already have a field counting the number of days, so that's ok. I could do as you're suggesting Razor, but I was hoping there's something more efficient.

Posted (edited)

this is how i would do it

$res = $db->query("SELECT * FROM `grpgusers` WHERE `gdays` > 0");
$row = $db->fetch_row($res);

$gangdays = array(
'50',
'100',
'150'
);	

$gdays = $row['gdays'];

if($row['gdays'] == in_array($gdays,$gangdays)) {
echo 'True';
    	event_add($row['userid'], "You have reached ".$row['gdays']." days in a gang well done"); 
} 
else {
echo 'false';
}

 

just remove the echo statements and the else statement used it for testing :)

also you could remove $gdays = $row['gdays']; and change

if($row['gdays'] == in_array($gdays,$gangdays)) {

to

if($row['gdays'] == in_array($row['gdays'],$gangdays)) {

 

i have a bad habit of creating variables when not needed xD

Edited by Newbie
Posted
this is how i would do it
$res = $db->query("SELECT * FROM `grpgusers` WHERE `gdays` > 0");
$row = $db->fetch_row($res);

$gangdays = array(
   '50',
   '100',
   '150'
);    

$gdays = $row['gdays'];

if($row['gdays'] == in_array($gdays,$gangdays)) {
   echo 'True';
        event_add($row['userid'], "You have reached ".$row['gdays']." days in a gang well done"); 
} 
else {
   echo 'false';
}

just remove the echo statements and the else statement used it for testing :)

also you could remove $gdays = $row['gdays']; and change

if($row['gdays'] == in_array($gdays,$gangdays)) {

to

if($row['gdays'] == in_array($row['gdays'],$gangdays)) {

i have a bad habit of creating variables when not needed xD

If it's every 50 days why not just use

if($row['gdays'] %50 == 0)
Posted
i did not know how to do that :P

My code checks that the variable is divisible by 50. Unless I've missed something obvious here that would be every 50 days providing the variable goes up by 1 every day.

Posted
i must admit you way does seem better :P but i can only post what i know :P coming to think of it i don't think iv ever used the % operator before

Good time to learn your arithmetic operators! http://www.php.net/manual/en/language.operators.arithmetic.php

[TABLE=class: doctable table, width: 1029]

[TR]

[TH=bgcolor: #BBBBDD]Example[/TH]

[TH=bgcolor: #BBBBDD]Name[/TH]

[TH=bgcolor: #BBBBDD]Result[/TH]

[/TR]

[TR]

[TD]-$a[/TD]

[TD]Negation[/TD]

[TD]Opposite of $a.[/TD]

[/TR]

[TR=bgcolor: #E3E3F1]

[TD]$a + $b[/TD]

[TD]Addition[/TD]

[TD]Sum of $a and $b.[/TD]

[/TR]

[TR]

[TD]$a - $b[/TD]

[TD]Subtraction[/TD]

[TD]Difference of $a and $b.[/TD]

[/TR]

[TR=bgcolor: #E3E3F1]

[TD]$a * $b[/TD]

[TD]Multiplication[/TD]

[TD]Product of $a and $b.[/TD]

[/TR]

[TR]

[TD]$a / $b[/TD]

[TD]Division[/TD]

[TD]Quotient of $a and $b.[/TD]

[/TR]

[TR=bgcolor: #E3E3F1]

[TD]$a % $b[/TD]

[TD]Modulus[/TD]

[TD]Remainder of $a divided by $b.[/TD]

[/TR]

[/TABLE]

Posted

I ended up doing this:

 

// rewarding players who have been in the same gang every 50 days
$q = $db->query("
SELECT *
FROM `users`
WHERE `daysingang`%50=0
AND `daysingang`!=0
");
while($r = $db->fetch_row($q)){
event_add(
	$r['userid'],
	"You've been in your gang another 50 days! Congratulations. You've received $100,000 and 20 crystals.",
	NULL
);
$db->query("
	UPDATE `users`
	SET `money`=`money`+100000, `crystals`=`crystals`+20
	WHERE `userid`=" . $r['userid'] . "
");
}

 

:)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...