Jump to content
MakeWebGames

Recommended Posts

Posted

hi im having a little problem with a function in my ammo mod where when you go to buy the ammo is charges you for how many you want but only gives you 1 at a time

here is the for the function where you enter how many how many mags you want

function ammo_buy()
{
global $db, $ir,$c,$userid,$h;	

$sql = "SELECT count(pm_mags) FROM players_mags WHERE pm_itmid = {$_GET['WID']} AND pm_userid = {$ir['userid']}";
$rs = mysql_query($sql);
$row = mysql_fetch_array($rs);
$mags = $row[0];

echo"You currently have ".number_format($mags)." out of 25 Magazines for this gun.
";

$magcost=$db->fetch_row($db->query("SELECT itmmagcost FROM items WHERE itmid = {$_GET['WID']}"));

echo"
How many Magazines would you like to buy?
it costs {$magcost['itmmagcost']} a Mag


<form action='ammo.php?action=buyammo&WID=".number_format($_GET['WID'])."' method='post'>
<input type='text' name='mags' value='0'/>

<input type='submit' name='submit' value='Buy Magazines'/>
</form>
<hr>
[url='ammo.php']Go Back[/url]
";
}

and this is where it should take what you enter and give you that many mags but instead only gives you on

function ammo_buyammo()
{
global $db, $ir,$c,$userid,$h;	

$ms=$db->query("SELECT itmmagsize, itmmagcost FROM items WHERE itmid = {$_GET['WID']}");
$r=$db->fetch_row($ms);

$cost = $r['itmmagcost'];
$totalcost = ($_POST['mags'] * $cost);

if($totalcost > $ir['money'])
{
echo"You are trying to buy more than you can afford
";
$h->endpage();
exit;
}
else
{	
$db->query("UPDATE users SET money = money - {$totalcost} WHERE userid = {$ir['userid']}");
$mags = $_POST['mags'];

for($i=1; $i<=$mags; $i++)
{
  $db->query("INSERT INTO players_mags ( pm_userid, pm_itmid, pm_mags)
			VALUES({$ir['userid']}, {$_GET['WID']}, '1')");

  $i=mysql_insert_id($c);

  $db->query("INSERT INTO players_ammo (pa_id, pa_userid, pa_itmid, pa_magid, pa_rounds_left, pa_rounds)
			VALUES('', '{$ir['userid']}', '{$_GET['WID']}', '$i', '{$r['itmmagsize']}', '{$r['itmmagsize']}')");
}	
echo"You bought ".number_format($_POST['mags'])." for \$".number_format($totalcost)."
<hr>
[url='ammo.php']Go Back[/url]
";
}
}

 

any help would be appreciated thanks skal

Posted

hey,

im not sure to be honest but maybe line 28 of the buyammo function might be the problem ?..

$i=mysql_insert_id($c);

because the vairable you are looping is $i so maybe that might throw it off...lol

good luck, looks like a nice mod ;)

Posted

You have more issues here than that.

Why are you formatting the number on entry?

<form action='ammo.php?action=buyammo&WID=".number_format($_GET['WID'])."' method='post'>

You may wish to secure down your $_POST['mags'] that its actually a positive number you dont want players buying -99999999999999 mags :D

Also secure the $_GET['WID']

Puzzles me why your doing the loop. If you have a itmmagsize which is the ammo per mag then its a simple maths calculation amount of mags x amount of ammo = result. No need to loop.

Personally I feel its best not to loop when you dont need to.

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