PDA

View Full Version : Can you help me with this code?


00king00
04-18-2007, 09:05 PM
Hi all

I think something wrong with this script file (vsys.php)

The Sentry Skill upgrade won't work if the player press (upgrade Sentry Skill )

I attached the file to your review

if anyone got hint or tip please let me know

function Trainupgrade($user,$type)
{
if($type=='spy'){
$pris=pow(2,$user->currentSpySkill)*12000;
if($pris <= ($user->gold+$user->bank)){
if($pris>$user->gold){
$bank=$pris-$user->gold;
$pris=$user->gold;
}
$q = @mysql_query("update `UserDetails` set currentSpySkill=currentSpySkill+'1', gold=gold-'$pris', bank=bank-'$bank' where ID='$user->ID' ");
}else return 'NO GOLD LEFT!!!';}
if($type=='spy'){
$pris=pow(2,$user->currentSentrySkill)*12000;
if($pris <= ($user->gold+$user->bank)){
if($pris>$user->gold){
$bank=$pris-$user->gold;
$pris=$user->gold;
}
$q = @mysql_query("update `UserDetails` set currentSentrySkill=currentSentrySkill+'1', gold=gold-'$pris', bank=bank-'$bank' where ID='$user->ID' ");
}else return 'NO GOLD LEFT!!!';}
if($type=='bank'){
$pris=pow(2,$user->bankSkill)*100000;
if($pris <= ($user->gold+$user->bank)){
if($pris>$user->gold){
$bank=$pris-$user->gold;
$pris=$user->gold;

Fumigator
04-18-2007, 11:46 PM
Interesting.

Fou-Lu
04-19-2007, 03:57 AM
Because the upgrade is dealing with only the spy type?

if($type=='spy'){
$pris=pow(2,$user->currentSentrySkill)*12000;
if($pris <= ($user->gold+$user->bank)){
if($pris>$user->gold){
$bank=$pris-$user->gold;
$pris=$user->gold;
}
$q = @mysql_query("update `UserDetails` set currentSentrySkill=currentSentrySkill+'1', gold=gold-'$pris', bank=bank-'$bank' where ID='$user->ID' ");
}else return 'NO GOLD LEFT!!!';}

No sentryskill type called. But thats ok, their spy upgrade will cost 2* as much and the get the additional bonus of the sentySkill :).

BTW, capitalizing your objects makes for easier readability, its by no means a necessity, but it does help. Personally, I upper case all of my object calls.
Look at using a switch statement to only control the uniqueness of each call, such as the individual types and pris (prices?). Otherwise, the code appears identical.

00king00
04-19-2007, 05:13 PM
Hi mate!

I read your reply regarding my script error with file (vsys.php)

Do you mean I can solve this problem easy?

What shall I change?

Thanx

Fumigator
04-19-2007, 05:34 PM
Change this:


$pris=pow(2,$user->currentSentrySkill)*12000;


To this:


$pris=pow(3,$user5->currentSentrySkill)*12040;

00king00
04-19-2007, 05:37 PM
Ok thanx mate I will try it and I will let u know

:-)

00king00
04-19-2007, 05:47 PM
Hi mate

I tried it, the old message which is ( No gold left) disappear, but the opition dosn't work!

Before, even if the player have gold he can't upgarde the Sentry Skill, but know, no more error message but can't get the upper upgrade!

Thanx

00king00
04-20-2007, 12:37 AM
about the script..the function should work like this:

when the player press (upgrade Sentry Skill) It should upgarde to the next level of Sentry Skill after deduction the sum of money from the gold he/she got

Every upgrade works fine excpet the (upgrade Sentry Skill), it dosn't move! And if the player press the upgrade button the error message appers in the page (No Gold Left) but he got enogh gold to buy the next level of Sentry Skill !

Thats all mate!

I am thinking ( after I asked alot and searched lol) that the error maybe comes from two php file:
1- (vsys.php)
2- (train.php)

coz these both files got the word and function of (upgrade Sentry Skill ) but I don't know how to change it to the correct way!

if you want me to attach these two files here I will, but at least I want someone to know what I am talking about

regards and sorry,

argothian
04-20-2007, 01:36 AM
In the code you first posted the if to check for spy upgrade or sentry upgrade is the same, you need to change the second if for sentry instead of spies (I reformatted it so it would be easier to read):

if($type=='spy'){
$pris=pow(2,$user->currentSpySkill)*12000;
if($pris <= ($user->gold+$user->bank)){
if($pris>$user->gold){
$bank=$pris-$user->gold;
$pris=$user->gold;
}
$q = @mysql_query("update `UserDetails` set currentSpySkill=currentSpySkill+'1', gold=gold-'$pris', bank=bank-'$bank' where ID='$user->ID' ");
} else
return 'NO GOLD LEFT!!!';
}
//This is the second if statement
//if($type=='spy'){
if($type=='sentry'){
$pris=pow(2,$user->currentSentrySkill)*12000;
if($pris <= ($user->gold+$user->bank)){
if($pris>$user->gold){
$bank=$pris-$user->gold;
$pris=$user->gold;
}
$q = @mysql_query("update `UserDetails` set currentSentrySkill=currentSentrySkill+'1', gold=gold-'$pris', bank=bank-'$bank' where ID='$user->ID' ");
} else
return 'NO GOLD LEFT!!!';
}

00king00
04-20-2007, 04:26 PM
Thanx mate for this code

BUT :-((

Its dosn't work!

I change the whole code and the error ( NO Gold Left) remain the same when upgarding the sentry skill!

Sorry!

argothian
04-20-2007, 10:06 PM
Are you sure that your formulas are working properly? Change the 'NO GOLD MESSAGE' to also include the amount of gold the player has and how much it should cost to upgrade:

return 'Not enough gold! You have ' . ($user->gold+$user->bank) . ' gold but it costs ' . $pris . ' gold!';