Jump to content
MakeWebGames

house tax cron job


Newbie
 Share

Recommended Posts

yeh the event function is there in globals already checked that its proberly me just putting it in wrong place lol

 

//House Tax Update
$uq=$db->query("SELECT * FROM users");
$Row=0;
while($r=$db->fetch_row($uq))
{
$will = $r['maxwill'];
$hq=$db->query("SELECT * FROM houses WHERE hWILL='{$will}'");
if($db->num_rows($hq) == 0)
{ }
$r2=$db->fetch_row($hq);
if($r['bankmoney'] < $r2['hTAX'])
{ $money=$r['money'];
$db->query("UPDATE users SET money=money+'{$r2['hSPRICE']}', will=100, maxwill=100 WHERE userid={$r['userid']}");
event_add($r['userid'],"You failed to pay the tax, so you have lost the house.",$c);
} else {
$db->query("UPDATE users SET bankmoney=bankmoney-'{$r2['hTAX']}' WHERE userid='{$r['userid']}'");
}
$Rows++;
}
?>
Totally there were <?php print($Rows); ?> rows which were executed.
Link to comment
Share on other sites

hSPRICE is the price it give's back to the user for tax. Not the full amount.

Meaning it is the sell price? My mistake ... I don't have my houses mod changed, only have the original table which is why this caught my eye. Hey ... I'm learning too. Sorry about that ... gave it a shot.

Link to comment
Share on other sites

yeh i made it so users dont get the full amount back iv seen on some games that users sell there house before reset and gain intrest from it so by only giving them half the money back it wont work

 

my house structure is

hID

hNAME

hPRICE

hWILL

hPIC

hPOINTS

hTAX

hSPRICE

 

<?php
include "config.php";
global $_CONFIG;
if($_GET['code'] != $_CONFIG['code']) { die(""); }
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
$set=array();
$settq=$db->query("SELECT * FROM settings");
while($r=$db->fetch_row($settq))
{
$set[$r['conf_name']]=$r['conf_value'];
}
//House Tax Update
$uq=$db->query("SELECT * FROM users");
$Row=0;
while($r=$db->fetch_row($uq))
{
$will = $r['maxwill'];
$hq=$db->query("SELECT * FROM houses WHERE hWILL='{$will}'");
if($db->num_rows($hq) == 0)
{ }
$r2=$db->fetch_row($hq);
if($r['bankmoney'] < $r2['hTAX'])
{ $money=$r['money'];
$db->query("UPDATE users SET money=money+'{$r2['hSPRICE']}', will=100, maxwill=100 WHERE userid={$r['userid']}");
event_add($r['userid'],"You failed to pay the tax, so you have lost the house.",$c);
} else {
$db->query("UPDATE users SET bankmoney=bankmoney-'{$r2['hTAX']}' WHERE userid='{$r['userid']}'");
}
$Rows++;
}
?>
Totally there were <?php print($Rows); ?> rows which were executed.

 

this is all the crontax.php

Link to comment
Share on other sites

<?php
include_once('config.php');
global $_CONFIG;
if($_GET['code'] != $_CONFIG['code'])
{
   echo 'Script execution failed';
   exit;
}
define("MONO_ON", 1);
require_once("class/class_db_{$_CONFIG['driver']}.php");
$db = new database;
$db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']);
$db->connect();

$c       = $db->connection_id;
$set     = array();
$settq   = $db->query("SELECT * FROM settings");
while($r = $db->fetch_row($settq))
{
   $set[$r['conf_name']] = $r['conf_value'];
}

/*
   All stuff above this comment has been pretty much left "as is"
   with minor edit. I have no idea why the settings are called,
   but considering I have no testing server, I don't want it to
   not run because I missed it out
*/


// Pull records where maxwill > 100. Since 100 is default, no tax can be applied at that point, right?
$sql   = "SELECT u.`userid`, u.`bankmoney`, h.* FROM `users` u LEFT JOIN `houses` h ON h.`hWILL` = u.`maxwill` WHERE u.`maxwill` > 100 ORDER BY u.`userid` ASC";
$run   = mysql_query($sql);

// Count results
$count = mysql_num_rows($run);

// If there are results, start the cron
if($count > 0)
{
   // Loop through all the results.
   while ($res = mysql_fetch_array($run, MYSQL_ASSOC))
   {
       // If they don't have enough money in their bank to pay the tax, take the house
       if($res['bankmoney'] < $res['hTAX'])
       {
           // Set their money as the hSPRICE and remove their house (maxwill = 100 && will = 100);
           $sql = "UPDATE `users` SET `money` = `money` + '{$res['hSPRICE']}', `maxwill` = 100, `will` = 100 WHERE `userid` = '{$res['userid']}' LIMIT 1";
           // Execute $sql
           mysql_query($sql);
           // Include global_func.php to allow the event_add()
           include_once('global_func.php');
           // Send event to the user
           event_add($res['userid'], "You failed to pay your property tax, so you have been evicted from your property.", $c);
       }
       else
       {
           // They have the money to pay the property tax, so take it.
           $sql = "UPDATE `users` SET `bankmoney` = `bankmoney` - '{$res['hTAX']}' WHERE `userid` = '{$res['userid']}' LIMIT 1";
           // Execute $sql
           mysql_query($sql);
       }
   }
}
// return count of results returned
echo number_format($count) . ' records ran';

 

Should work. Untested.

thanks works perfectly now :)

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...