Jump to content

[SOLVED] Subtract 'cost' from player


cdoyle

Recommended Posts

Hi,

I'm working on another ezRPG page,  this one I'm trying to a travel page.

 

I have in my cities table a field called 'cost'

 

What I want it to do is, depending on which city the player chooses to go to, it subtracts the cost from his onhand gold.

 

I just can't seem to get it to work,  I can hard code into my page a cost and it subtracts that.  But just can't seem to get it to take subtract the amount that I have listed in my Cities table.

 

Here is the code I have so far,

 

<?php
/*************************************/
/*           ezRPG script            */
/*         Written by Chris from WA  */
/*  http://code.google.com/p/ezrpg   */
/*    http://www.bbgamezone.com/     */
/*************************************/

include("lib.php");
define("PAGENAME", "Wanna Go Somewhere?");
$player = check_user($secret_key, $db);

$cityid = $_GET['id'];
$query = $db->execute("select `City_ID`, `City_Name`, `Cost` from `Cities` where `City_ID`=?", array($_GET['City_ID']));
$buscost = $query['Cost'];


if ($_GET['act'] == "go") {
    if ($player->gold < $buscost) {
        include("templates/private_header.php");
        echo "Hey everyone look, this wanna be gansta thinks this bus is free!<p>";
        echo "<a href=\"home.php\">Home</a>\n";
        include("templates/private_footer.php");
        exit;
    }
    
    //if player already in this city
    
    If ($player->City_ID == $cityid) {
        include("templates/private_header.php");
        echo "Are you high?  You're already here moron<p>";
        echo "<a href=\"home.php\">Home</a>\n";
        include("templates/private_footer.php");
        exit;
    } else {
        //update City
        
        $query1 = $db->execute("update `players` set `City_ID`=?, `gold`=? where `id`=?", array($cityid, $player->gold - $buscost, $player->id));
    }
    
    $player = check_user($secret_key, $db);
    include("templates/private_header.php");
    echo "You have arrived at your destination";
    echo "<p><a href=\"home.php\">Home</a>\n";
    include("templates/private_footer.php");
    exit;
}

include("templates/private_header.php");

echo "Welcome to CAC Bus Lines<br>";
echo "Please purchase your ticket and step onto the bus. <br /> The cost of the ticket from your current location is listed below.<p>";

echo "<table width=\"100%\" border=\"1\">\n";
echo "<th width=\"199\" class=\"cellheader\">Destination</th>";
echo "<th width=\"217\" class=\"cellheader\"> Cost</th>";

$querycity2 = $db->execute("SELECT * FROM Cities Where $player->level >= Minimum_Level");
while ($getcity2 = $querycity2->fetchrow()) {
    
echo "<tr>";
    echo "<td width=\"199\"><a href='bus.php?act=go&id={$getcity2['City_ID']}'>{$getcity2['City_Name']}</a></td>\n";
    echo "<td width=\"217\">";
    echo "$getcity2[Cost]";
    echo "</td>\n";
    echo "</tr>\n";
}
echo "</table>\n";

include("templates/private_footer.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/101848-solved-subtract-cost-from-player/
Share on other sites

Check you have the correct value in $buscost

 

I don't think it's working right.

 

$buscost is suppose to get it's value from here

 

$query = $db->execute("select `City_ID`, `City_Name`, `Cost` from `Cities` where `City_ID`=?", array($_GET['id']));

$buscost = $query['Cost'];

 

I noticed if I have no money on hand, it still let's me move from city to city.  It's suppose to give you a warning that you dont' have enough money.

 

 

I tried to echo $buscost, but it doesn't display anything.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.