Jump to content
MakeWebGames

Hi to All! A Text Based Mafia game - Trigger Happy Mafia!


KashBFD

Recommended Posts

  • Replies 56
  • Created
  • Last Reply

Top Posters In This Topic

1. Use code tags, encase code in [*php][*/php] ~(remove *)

2. "$crap" In my view, should be initiated first as 0 (Referring to $crap != 0) and then deleted from memory once it's played its role in the program (unset())

3. Try having the following IF statement somewhere...

<?php
$time = time();
$get = mysql_query("SELECT `bullets` FROM `site_stats` WHERE `bullets`< $time");
if(mysql_num_rows($get)) {
//Continue with code, add bullets
}

 

Other than step 3 I can't see why it needs a user request to initiate the update. Hmmm, on the other hand, I see you have something like that.

(Psst. Select what you want from the table, tend not to use the wildcard *)

I guess the only question to ask now, is, are the records updating?

Link to comment
Share on other sites

I got a question for whom it may concern. I have been trying my best to get the errors and bugs out of my current set of scripts. However one of many that i cant get my head around is my Bullet Factory script. See it works ok as in holds its stock, produces bullets, money works.. but atm it is set on 2000 bullets every hour, and when the time is up for some reason it wont update the bf's stock until someone is on the bf php page. I later managed to figure the function that is making the update of the bullets possible is ;

$new_time=time()+3600;

$up=mysql_fetch_object(mysql_query("SELECT * FROM site_stats WHERE id='1'"));

$a=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");

while($b=mysql_fetch_object($a)){

$user=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$b->owner'"));

$minus=$user->money - 1000;

if ($user->money <= $minus){

mysql_query("UPDATE bf SET owner='0', producing='0' WHERE id='$b->id'");

$crap=1;

}

 

if ($up->bullets < time() && $b->producing == "Yes" && $crap != "1"){

mysql_query("UPDATE bf SET stock=stock+2000");

mysql_query("UPDATE site_stats SET bullets='$new_time' WHERE id='1'");

mysql_query("UPDATE users SET money='$minus' WHERE username='$b->owner'");

}

}

. I tryed to copy and paste it in my functions.php page that is linked to most my scripts but nothing, so atm i have it placed in the footer.php... but still the issue remains someone has to be playing in order for the bf to refill. I will paste the whole scripts below , is there any suggestions..? I also managed to have a look in php my admin at the db to see wether it updates the times and it does but says 2006. Also im not experianced enough to notice the error..

FUNCTIONS;

<?php session_start();

include_once"includes/db_connect.php"; include_once"includes/functions.php"; logincheck();

$username=$_SESSION['username'];

$query=mysql_query("SELECT * FROM users WHERE username='$username'");

$fetch=mysql_fetch_object($query);

$query_bf=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");

$fetch_bf=mysql_fetch_object($query_bf);

if (strtolower($fetch_bf->owner) == (strtolower($fetch->username))){

require_once"bulletCP.php";

exit();

}

$new_time=time()+3600;

$up=mysql_fetch_object(mysql_query("SELECT * FROM site_stats WHERE id='1'"));

$a=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");

while($b=mysql_fetch_object($a)){

$user=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$b->owner'"));

$minus=$user->money - 1000;

if ($user->money <= $minus){

mysql_query("UPDATE bf SET owner='0', producing='0' WHERE id='$b->id'");

$crap=1;

}

 

if ($up->bullets < time() && $b->producing == "Yes" && $crap != "1"){

mysql_query("UPDATE bf SET stock=stock+2000");

mysql_query("UPDATE site_stats SET bullets='$new_time' WHERE id='1'");

mysql_query("UPDATE users SET money='$minus' WHERE username='$b->owner'");

}

}

 

 

if (strip_tags($_POST['check']) && (strip_tags($_POST['amount']))){

$amount=intval(strip_tags($_POST['amount']));

if ($amount == 0 || !$amount || ereg('[^0-9]',$amount)){

print "You cant buy that amount.";

}elseif ($amount != 0 || $amount || !ereg('[^0-9]',$amount)){

$costs = $fetch_bf->price * $amount;

if ($costs > $fetch->money){

echo "You do not have enough money";

} elseif ($costs <= $fetch->money){

$nmoney=$fetch->money - $costs;

if ($fetch_bf->stock < $amount){

echo "Not that many bullets in the store.";

} elseif ($amount <= $fetch_bf->stock){

$nbullets=$fetch->bullets + $amount;

$nstock = $fetch_bf->stock - $amount;

///IF THERE IS NOOOOO OWNER

if ($fetch_bf->owner == "0"){

mysql_query("UPDATE users SET bullets='$nbullets', money='$nmoney' WHERE username='$username'");

 

mysql_query("UPDATE bf SET stock='$nstock', profit='$costs' WHERE location='$fetch->location'");

echo "Bullets successfully bought.";

////IF THERE IS A OWNER

}elseif ($fetch_bf->owner != "0"){

$fetch_owner=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$fetch_bf->owner'"));

$new_owner=$fetch_owner->money + $costs;

mysql_query("UPDATE users SET bullets='$nbullets', money='$nmoney' WHERE username='$username'");

mysql_query("UPDATE users SET money='$new_owner' WHERE username='$fetch_bf->owner'");

mysql_query("UPDATE bf SET stock='$nstock', profit='$costs' WHERE location='$fetch->location'");

echo "Bullets Successfully Bought.";

}

}}

}

}

?>

and script displaying

<?php if ($fetch_bf->producing == "Yes"){ echo "".maketime($up->bullets)." until Bullets next Stock."; }else{ echo "Not Producing"; } ?>

I was browsing the forum and came across this post.. I must say that this code is exactly the same one as the one in the Way of The Mafia script (the functions page), that script also updates bullet factories every hour and uses the same code to do so. Of course, there is nothing wrong with using code from other scripts if allowed, was just curious..

Link to comment
Share on other sites

Lmao thats prob because they have a copy of my scripts that were stolen and sold on many times over for a period of 3-4 years.. however thanks for replying because ill try placing in the functions now.

Your also stating that the whole of the quoted .php script is placed in the functions?

Link to comment
Share on other sites

Lmao thats prob because they have a copy of my scripts that were stolen and sold on many times over for a period of 3-4 years.. however thanks for replying because ill try placing in the functions now.

Your also stating that the whole of the quoted .php script is placed in the functions?

I think I've come across your script in the past but don't remember that code being in the functions file. Anyway, strange. Good luck with your game. :)

Link to comment
Share on other sites

Its a .php script in the game, Bullet Factory, it produces bullets every certain time, and the players can buy bullets from there, also own them. Every thing else works fine they even produce bulelts, show a time but when the time is up a user is required to view the bf page in order for the stock to update.. i jus checked the db an the bullets in site_stats is updated .. please help.

Link to comment
Share on other sites

  • 2 weeks later...

Right sorry for long reply i just been getting other things fixed and trying to still do it myself with out a cron but i think its the only solution. Anyway there is a in game bullet factory that produces bullets for example every hour.. every hour 2000 bullets will be added to its stock amount.. anyway this all works fine from what i can see .. however when the time is up for the next restock a players needs to go onto the bf.php page in the game for it to update the timers and the stock.. i managed to make a file that if i just type into the domain will make this happen and it is below .... I tryed making it into a cron from the cpanel.. my command was..

/home/thmx10mx/public_html/cron.php

i dont even know if thats right...

 

<?php session_start(); include_once"includes/db_connect.php"; include_once"includes/functions.php"; 
$username=$_SESSION['username'];
$query=mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch=mysql_fetch_object($query);

$query_bf=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");
$fetch_bf=mysql_fetch_object($query_bf);

$new_time=time()+150;

$up=mysql_fetch_object(mysql_query("SELECT * FROM bf"));
$a=mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");
while($b=mysql_fetch_object($a)){
$user=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$b->owner'"));
$minus=$user->money - 1000;

if ($user->money <= $minus){
mysql_query("UPDATE bf SET owner='0', producing='0' WHERE id='$b->id'");
$crap=1;
}



if ($fetch_bf->producing == "Yes" && $up->next_restock < time() && $crap != "1"){

mysql_query("UPDATE bf SET stock=stock+2000");
mysql_query("UPDATE bf SET next_restock='$new_time' WHERE id='1'");
mysql_query("UPDATE users SET money='$minus' WHERE username='$b->owner'");

}

}

?>

 

I really hope someone can help me with some guidance.. its been on the agenda for nearly 2 weeks.. and is really bugging me.. thanks.

Link to comment
Share on other sites

[noparse]<?php
session_start();
include_once "includes/db_connect.php";
include_once "includes/functions.php";
$username = $_SESSION['username'];
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$fetch = mysql_fetch_object($query);
$query_bf = mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");
$fetch_bf = mysql_fetch_object($query_bf);
$new_time = time() + 150;
$up = mysql_fetch_object(mysql_query("SELECT * FROM bf"));
$a = mysql_query("SELECT * FROM bf WHERE location='$fetch->location'");
while ($b = mysql_fetch_object($a))
{
   $user = mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$b->owner'"));
   $minus = $user->money - 1000;
   if ($user->money <= $minus)
   {
       mysql_query("UPDATE bf SET owner='0', producing='0' WHERE id='$b->id'");
       $crap = 1;
   }
   if ($fetch_bf->producing == "Yes" && $up->next_restock < time() && $crap != "1")
   {
       mysql_query("UPDATE bf SET stock=stock+2000");
       mysql_query("UPDATE bf SET next_restock='$new_time' WHERE id='1'");
       mysql_query("UPDATE users SET money='$minus' WHERE username='$b->owner'");
   }
}
?>[/noparse]

Code was killing my eyes. Had to run it through a beautifier.

Now that I can read it. It looks like this is what is updating everything. So, it seems to me, that all you need to do is have the page called, by a cron handler.

I haven't used or setup a cron using cpanel in years so i forgot which order you have to input things. So get me a print screen of your cron page, and I can help you with that. Or i'm sure someone else will help you if they know.

If you have already set it up and it's not working, then... For the cron url try using "curl path/to/file" instead of just "path/to/file". Also make sure you have the numbers in the right places for the cron setup form, because you could have it set for something like 5 hours or 5 days instead of 5 minutes.

Edited by bluegman991
Link to comment
Share on other sites

Alternatively, store the production setting in the database, and do something along the following;

$get = $db->query("SELECT <primary_key> FROM <table> WHERE <production_column>='Yes'");
while($r = $db->fetch_row($get)) {
 $db->query("UPDATE <table> SET <bullet_column>=<bullet_column>+<value> WHERE <primary_key>={$r['<primary_key>']}");
}
unset($r);
mysql_free_result($get);
Link to comment
Share on other sites

  • 3 weeks later...

The game is currently online and has been over to a temp host with a new domain in order for some beta testing with users and players that can help.

You dont have to visit but it would be nice for some advice for now.. i am working on a story line.. just getting the game flow.. big improvements coming very very soon, may even be a diff engine..

http://www.TriggerHappy-Mafia.com

Thanks

Kash

P.S all the testers or players that are playing until the big reset will be given something in return to show the token of appreciation.

e.g. Props, Bullets, Points, Cash if they decide to continue to play...

Link to comment
Share on other sites

  • 1 month later...

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...