Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with negative problems

    I have quite afew prolems with people putting negative numbers in the fields and it messes with my game, for example when they buy negative mercinates it floods the market with mercinarys and it they get gold they do not deserve...

    here is the code please tell me to make it so they cannot put a negative number

    PHP Code:
    <?
    include "vsys.php";
    if (
    $cgi['buy_merc']){
        
    $merc=getCommonInfo();
        
        if (
    $cgi['mercs_attack']){
            if (
    $cgi['mercs_attack']>$merc->attackSpecCount)$cgi['mercs_attack']=$merc->attackSpecCount;
            
    $gold=$cgi['mercs_attack']*$conf["mercenaries"]["atack"]["prise"];
            
    $user=getUserDetails($_SESSION['isLogined']," gold ");
            if (
    $user->gold>$gold){
                
    updateMercenary(" attackSpecCount=attackSpecCount-{$cgi['mercs_attack']} ");
                
    updateUser($_SESSION['isLogined'], " trainedAttackMerc=trainedAttackMerc+{$cgi['mercs_attack']} , gold=gold-$gold ");
            }else{
                
    $strErr="You do not have enough money";
            }
        }
        if (
    $cgi['mercs_defend']){
            if (
    $cgi['mercs_defend']>$merc->defSpecCount)$cgi['mercs_defend']=$merc->defSpecCount;
            
    $gold=$cgi['mercs_defend']*$conf["mercenaries"]["defence"]["prise"];
            
    $user=getUserDetails($_SESSION['isLogined']," gold ");
            if (
    $user->gold>$gold){
                
    updateMercenary(" defSpecCount =defSpecCount -{$cgi['mercs_defend']} ");
                
    updateUser($_SESSION['isLogined'], " trainedDefMerc=trainedDefMerc+{$cgi['mercs_defend']}  , gold=gold-$gold ");
            }else{
                
    $strErr="You do not have enough money";
            }
        }
        if (
    $cgi['mercs_general']){
            if (
    $cgi['mercs_general']>$merc->untrainedCount)$cgi['mercs_general']=$merc->untrainedCount;
            
    $gold=$cgi['mercs_general']*$conf["mercenaries"]["untrained"]["prise"];
            
    $user=getUserDetails($_SESSION['isLogined']," gold ");
            if (
    $user->gold>$gold){
                
    updateMercenary(" untrainedCount =untrainedCount -{$cgi['mercs_general']} ");
                
    updateUser($_SESSION['isLogined'], " untrainedMerc=untrainedMerc+{$cgi['mercs_general']} , gold=gold-$gold ");
            }else{
                
    $strErr="You do not have enough money";
            }
        }
        
    header("Location: mercs.php?strErr=$strErr");
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0037)http://www.kingsofchaos.com/mercs.php -->
    <HTML><HEAD><TITLE>Combat Warriors! :: Massively Multiplayer Online Role Playing Game</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><!-- ZoneLabs Privacy Insertion -->
    <SCRIPT language=javascript src="js/js"></SCRIPT>
    <LINK href="css/common.css" type=text/css rel=stylesheet><LINK 
    href="css/main.css" type=text/css rel=stylesheet>
    <META 
    content="kingsofchaos, chaos, elves, humans, dwarves, orcs, rpg, mmorpg, role playing, game, online game, text based game, armory, mercenaries, spy, attack, army, battle, recruit, spies, spy skill, weapons, messaging, sabotage, recon, intelligence, pnp, mud, games, stockade, free, browser game" 
    name=keywords>
    <META 
    content="Combat Warriors is a Massively Multiplayer Online Role Playing Game. Players can choose one of four races: Orcs, Humans,  Elves and Dwarves and build armies, recruit friends as officers, buy weapons, and spy and attack on each other." 
    name=description>
    <META content="Kings of Chaos" name=author>
    <SCRIPT language=javascript type=text/javascript>
            <!--
            function checkCR(evt) {
            var evt = (evt) ? evt : ((event) ? event : null);
            var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
            if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
            }
            document.onkeypress = checkCR;
            //-->
            </SCRIPT>

    <META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
    <BODY text=#ffffff bgColor=#000000 leftMargin=0 topMargin=0 marginheight="0" 
    marginwidth="0">
    <?
    include "top.php";
    ?>

    <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
      <TBODY>
      <TR>
        <TD class=menu_cell style="PADDING-LEFT: 15px" vAlign=top width=140>
    <?
        
    include ("left.php");
    ?>

        </TD>
          <TD style="PADDING-RIGHT: 15px; PADDING-LEFT: 15px; PADDING-TOP: 12px" 
        vAlign=top align=left> <? if ($cgi['strErr']){ echo "<center><font color=red>{$cgi['strErr']}</font></center>"; } ?><BR>
          <H3>Mercenaries</H3>
            <TABLE class=table_lines cellSpacing=0 cellPadding=6 width="380" 
                border=0>
              <TBODY>
                <TR> 
                  <TH colSpan=2>Personnel</TH>
                </TR>
                <TR> 
                  <TD><B>Trained Attack Soldiers</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedAttackSold?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Trained Attack Mercenaries</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedAttackMerc)   ?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Trained Defense Soldiers</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedDefSold)?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Trained Defense Mercenaries</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedDefMerc?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Untrained Soldiers</B></TD>
                  <TD align=right>
                    <? numecho ($user->untrainedSold?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Untrained Mercenaries</B></TD>
                  <TD align=right>
                    <? numecho ($user->untrainedMerc?>
                  </TD>
                </TR>
                <TR> 
                  <TD class=subh><B>Spies</B></TD>
                  <TD class=subh align=right>
                    <? numecho ($user->spies?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Total Fighting Force</B></TD>
                  <TD align=right>
                    <? numecho (getTotalFightingForce($user))?>
                  </TD>
                </TR>
              </TBODY>
            </TABLE>
            <P>
            <?
            $merc
    =getCommonInfo();
            
    ?>
          <FORM action=mercs.php method=post>
          <TABLE class=table_lines cellSpacing=0 cellPadding=6 width="100%" 
    border=0>
            <TBODY>
            <TR>
              <TH align=middle colSpan=4>Buy Mercenaries</TH></TR>
            <TR>
              <TH class=subh align=left>Mercenary Type</TH>
              <TH class=subh align=right>Cost Per Unit</TH>
              <TH class=subh align=right>Quantity Available</TH>
              <TH class=subh align=middle>Quantity to Buy</TH></TR>
            <TR>
              <TD>Attack Specialist</TD>
              <TD align=right><? numecho ($conf["mercenaries"]["atack"]["prise"]) ?> Gold</TD>
              <TD align=right><? numecho ($merc->attackSpecCount);?></TD>
              <TD align=middle><INPUT size=3 value=0 name=mercs_attack></TD></TR>
            <TR>
              <TD>Defense Specialist</TD>
                    <TD align=right>
                      <? numecho ($conf["mercenaries"]["defence"]["prise"]) ?>
                      Gold</TD>
                    <TD align=right>
                      <? numecho ($merc->defSpecCount );?>
                    </TD>
              <TD align=middle><INPUT size=3 value=0 name=mercs_defend></TD></TR>
            <TR>
              <TD>Untrained</TD>
                    <TD align=right>
                      <? numecho ($conf["mercenaries"]["untrained"]["prise"]) ?>
                      Gold</TD>
                    <TD align=right>
                      <? numecho ($merc->untrainedCount );?>
                    </TD>
              <TD align=middle><INPUT size=3 value=0 name=mercs_general></TD></TR>
            <TR>
              <TD align=middle colSpan=4><INPUT type=submit value=Buy> 
            </TD></TR></TBODY></TABLE><INPUT type=hidden 
          value=93aa2b6a02603399396203313b45827e name=hash> 
          <INPUT type=hidden value=1 name=buy_merc></FORM>
          <?
      
    include ("bottom.php");
    ?>    
          </TD></TR></TBODY></TABLE>
    </BODY></HTML>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $str str_replace("-","",$str); 
    Simplist way I can think of at this time.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I would use PHP absolute function:
    http://php.about.com/od/phpfunctions...lute_value.htm

    The number will always be positive.

  • #4
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down

    Quote Originally Posted by Nightfire View Post
    PHP Code:
    $str str_replace("-","",$str); 
    Simplist way I can think of at this time.
    hey, i have exactly the same problem, i have added the
    PHP Code:
    $str str_replace("-","",$str); 
    code into my mercs.php source code but it still allows the negative users to enter a negative number.

    here is MY source code, hopefully this helps:

    Code:
    <?
    include "vsys.php";
    if ($cgi['buy_merc']){
    	$merc=getCommonInfo();
    	
    	if ($cgi['mercs_attack']){
    		if ($cgi['mercs_attack']>$merc->attackSpecCount)$cgi['mercs_attack']=$merc->attackSpecCount;
    		$gold=$cgi['mercs_attack']*$conf["mercenaries"]["atack"]["prise"];
    		$user=getUserDetails($_SESSION['isLogined']," gold ");
    		if ($user->gold>$gold){
    			updateMercenary(" attackSpecCount=attackSpecCount-{$cgi['mercs_attack']} ");
    			updateUser($_SESSION['isLogined'], " trainedAttackMerc=trainedAttackMerc+{$cgi['mercs_attack']} , gold=gold-$gold ");
    		}else{
    			$str = str_replace("-","",$str);
    			$strErr="You do not have enough money";
    		}
    	}
    	if ($cgi['mercs_defend']){
    		if ($cgi['mercs_defend']>$merc->defSpecCount)$cgi['mercs_defend']=$merc->defSpecCount;
    		$gold=$cgi['mercs_defend']*$conf["mercenaries"]["defence"]["prise"];
    		$user=getUserDetails($_SESSION['isLogined']," gold ");
    		if ($user->gold>$gold){
    			updateMercenary(" defSpecCount =defSpecCount -{$cgi['mercs_defend']} ");
    			updateUser($_SESSION['isLogined'], " trainedDefMerc=trainedDefMerc+{$cgi['mercs_defend']}  , gold=gold-$gold ");
    		}else{
    			$str = str_replace("-","",$str);
    			$strErr="You do not have enough money";
    			
    		}
    	}
    	if ($cgi['mercs_general']){
    		if ($cgi['mercs_general']>$merc->untrainedCount)$cgi['mercs_general']=$merc->untrainedCount;
    		$gold=$cgi['mercs_general']*$conf["mercenaries"]["untrained"]["prise"];
    		$user=getUserDetails($_SESSION['isLogined']," gold ");
    		if ($user->gold>$gold){
    			updateMercenary(" untrainedCount =untrainedCount -{$cgi['mercs_general']} ");
    			updateUser($_SESSION['isLogined'], " untrainedMerc=untrainedMerc+{$cgi['mercs_general']} , gold=gold-$gold ");
    		}else{
    			$str = str_replace("-","",$str);
    			$strErr="You do not have enough money";
    		}
    	}
    	header("Location: mercs.php?strErr=$strErr");
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0037)http://www.kingsofchaos.com/mercs.php -->
    <HTML><HEAD><TITLE>Crusaders of War :: Massively Multiplayer Online Role Playing Game</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><!-- ZoneLabs Privacy Insertion -->
    <SCRIPT language=javascript src="js/js"></SCRIPT>
    <LINK href="css/common.css" type=text/css rel=stylesheet><LINK 
    href="css/Elves.css" type=text/css rel=stylesheet>
    <META 
    content="crusadersofwar, war, elves, humans, dwarves, orcs, rpg, mmorpg, role playing, game, online game, text based game, armory, mercenaries, spy, attack, army, battle, recruit, spies, spy skill, weapons, messaging, sabotage, recon, intelligence, pnp, mud, games, stockade, free, browser game" 
    name=keywords>
    <META 
    content="Crusaders of War is a Massively Multiplayer Online Role Playing Game. Players can choose one of four races: Orcs, Humans,  Elves or Dwarves.  Command and army, compete against friends, recruit officers, buy weapons, and spy and attack on each other." 
    name=description>
    <META content="Crusaders of War" name=author>
    <SCRIPT language=javascript type=text/javascript>
    		<!--
    		function checkCR(evt) {
    		var evt = (evt) ? evt : ((event) ? event : null);
    		var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    		if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
    		}
    		document.onkeypress = checkCR;
    		//-->
    		</SCRIPT>
    
    <META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
    <BODY text=#ffffff bgColor=#000000 leftMargin=0 topMargin=0 marginheight="0" 
    marginwidth="0">
    <?
    include "top.php";
    ?>
    
    <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
      <TBODY>
      <TR>
        <TD class=menu_cell style="PADDING-LEFT: 15px" vAlign=top width=140>
    <?
    	include ("left.php");
    ?>
    
    	</TD>
          <TD style="PADDING-RIGHT: 15px; PADDING-LEFT: 15px; PADDING-TOP: 12px" 
        vAlign=top align=left> <? if ($cgi['strErr']){ echo "<center><font color=red>{$cgi['strErr']}</font></center>"; } ?><BR>
          <H3>Mercenaries</H3>
            <TABLE class=table_lines cellSpacing=0 cellPadding=6 width="380" 
                border=0>
              <TBODY>
                <TR> 
                  <TH colSpan=2>Personnel</TH>
                </TR>
                <TR> 
                  <TD><B>Trained Attack Soldiers</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedAttackSold) ?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Trained Attack Mercenaries</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedAttackMerc)   ?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Trained Defense Soldiers</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedDefSold)?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Trained Defense Mercenaries</B></TD>
                  <TD align=right>
                    <? numecho ($user->trainedDefMerc) ?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Untrained Soldiers</B></TD>
                  <TD align=right>
                    <? numecho ($user->untrainedSold) ?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Untrained Mercenaries</B></TD>
                  <TD align=right>
                    <? numecho ($user->untrainedMerc) ?>
                  </TD>
                </TR>
                <TR> 
                  <TD class=subh><B>Spies</B></TD>
                  <TD class=subh align=right>
                    <? numecho ($user->spies) ?>
                  </TD>
                </TR>
                <TR> 
                  <TD><B>Total Fighting Force</B></TD>
                  <TD align=right>
                    <? numecho (getTotalFightingForce($user))?>
                  </TD>
                </TR>
              </TBODY>
            </TABLE>
            <P>
    		<?
    		$merc=getCommonInfo();
    		?>
          <FORM action=mercs.php method=post>
          <TABLE class=table_lines cellSpacing=0 cellPadding=6 width="100%" 
    border=0>
            <TBODY>
            <TR>
              <TH align=middle colSpan=4>Buy Mercenaries</TH></TR>
            <TR>
              <TH class=subh align=left>Mercenary Type</TH>
              <TH class=subh align=right>Cost Per Unit</TH>
              <TH class=subh align=right>Quantity Available</TH>
              <TH class=subh align=middle>Quantity to Buy</TH></TR>
            <TR>
              <TD>Attack Specialist</TD>
              <TD align=right><? numecho ($conf["mercenaries"]["atack"]["prise"]) ?> Gold</TD>
              <TD align=right><? numecho ($merc->attackSpecCount);?></TD>
              <TD align=middle><INPUT size=3 value=0 name=mercs_attack></TD></TR>
            <TR>
              <TD>Defense Specialist</TD>
                    <TD align=right>
                      <? numecho ($conf["mercenaries"]["defence"]["prise"]) ?>
                      Gold</TD>
                    <TD align=right>
                      <? numecho ($merc->defSpecCount );?>
                    </TD>
              <TD align=middle><INPUT size=3 value=0 name=mercs_defend></TD></TR>
            <TR>
              <TD>Untrained</TD>
                    <TD align=right>
                      <? numecho ($conf["mercenaries"]["untrained"]["prise"]) ?>
                      Gold</TD>
                    <TD align=right>
                      <? numecho ($merc->untrainedCount );?>
                    </TD>
              <TD align=middle><INPUT size=3 value=0 name=mercs_general></TD></TR>
            <TR>
              <TD align=middle colSpan=4><INPUT type=submit value=Buy> 
            </TD></TR></TBODY></TABLE><INPUT type=hidden 
          value=93aa2b6a02603399396203313b45827e name=hash> 
    	  <INPUT type=hidden value=1 name=buy_merc></FORM>
    	  
          <?
      include ("bottom.php");
    ?>	
    	  </TD></TR></TBODY></TABLE>
    </BODY></HTML>
    Thanks

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by mlseim View Post
    I would use PHP absolute function:
    http://php.about.com/od/phpfunctions...lute_value.htm

    The number will always be positive.
    take note to the last line :P
    The number will always be positive.

  • #6
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    take note to the last line :P
    The number will always be positive.
    okay, so where do i put that...
    PHP Code:
    <?php
    abs 
    (-6) ;
    //returns a value of 6

    abs (12.4) ;
    //returns a value of 12.4

    abs (-456.2) ;
    // returns a value of 456.2
    ?>
    Last edited by PolloX; 05-29-2007 at 08:16 PM.

  • #7
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    One reason the str_replace thing didn't work for you is that it was an example - you need to actually customize it to your site, by replacing $str with whatever variable it is that you want to be positive.

    for the absolute value, if $var is the name of the variable you want to be positive, do this after the user puts his value in for it:

    $var = abs($var);

    (replacing $var with your variable name of course)

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #8
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    omg this is soo confusing, im a noob at php... please be patient with me... thnks

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by rafiki View Post
    take note to the last line :P
    The number will always be positive.
    That's actually wrong. It should say that the number will be always non-negative.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    are you positive?

  • #11
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quite.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •