[REQ] 500 credits for php help

fierce

New Member
Messages
222
Reaction score
0
Points
0
I need some1 that will help me with a php problem i got on my game(site) .
Those that are interested reply this thread or add my msn im fierce@inbox.com .

Thx In Advance

-fierce .
 

fierce

New Member
Messages
222
Reaction score
0
Points
0
Generates land, ranging 3% - 6% of your total current land (but never above 12,000 acres), at a cost of 1% - 6% magic users, 1% - 8% grains, 1% - 5% gold, and 12 points of health (though you gain back 2 points for the taken turns). You cannot cast this spell until you have a total of at least 10,000 acres. - This is what the spell should do.
This is the code I use
Code:
function SpellEmminentDomain ()

{

	global $users, $urace, $lratio, $config;

	if ($lratio >= 3)

	{

$trandland1 = ceil($users[freeland] * .06);
$trandland2 = $trandland1 + 1;
$trandland3 = ceil($trandland2);
$trandland4 = mt_rand(0, $trandland3);
$randland = ceil($trandland4);

		if ($randland < ($users[land] * .03)) { $randland = ceil($users[land] * .03); }

		if ($randland > ($users[land] * .06)) { $randland = ceil($users[land] * .06); }

		$newland=$randland;

		if ($newland > $config[edcap]) {$newland=$config[edcap];}

		$mageloss= (100-($newland/250))/100;

		if ($mageloss < .94) {$mageloss=.94;}

		$foodloss= (100-($newland/150))/100;

		if ($foodloss < .92) {$foodloss=.92;}

		$cashloss= (100-($newland/750))/100;

		if ($cashloss < .95) {$cashloss=.95;}



		$land = $newland;



		$users[land] = $users[land] + $land;

		$users[freeland] = $users[freeland] + $land;

      $users[health] -= 12;

      $users[wizards]=round($users[wizards]*$mageloss);

      $users[food]=round($users[food]*$foodloss);

      $users[cash]=round($users[cash]*$cashloss);



		$cashloss = ceil($cashloss);

		$foodloss = ceil($foodloss);

		$mageloss = ceil($mageloss);

		$cashloss = commas($cashloss);

		$foodloss = commas($foodloss);

		$mageloss = commas($mageloss);





		SpellSucceed($land." acres was made by your Wizards, however the magic that surrounded the area made you lose many wizards, cash and grain in the process!");

		saveUserData($users,"health land freeland cash food wizards");
	}

	else	SpellFail2();
	taketurns(2,attack);
}
This is the result i get =lose of 10% of health which is ok,no mana,no cash,no grain lose ,no land increase .
Edit:
Generates land, ranging 3% - 6% of your total current land (but never above 12,000 acres), at a cost of 1% - 6% magic users, 1% - 8% grains, 1% - 5% gold, and 12 points of health (though you gain back 2 points for the taken turns). You cannot cast this spell until you have a total of at least 10,000 acres. - This is what the spell should do.
This is the code I use
Code:
function SpellEmminentDomain ()

{

    global $users, $urace, $lratio, $config;

    if ($lratio >= 3)

    {

$trandland1 = ceil($users[freeland] * .06);
$trandland2 = $trandland1 + 1;
$trandland3 = ceil($trandland2);
$trandland4 = mt_rand(0, $trandland3);
$randland = ceil($trandland4);

        if ($randland < ($users[land] * .03)) { $randland = ceil($users[land] * .03); }

        if ($randland > ($users[land] * .06)) { $randland = ceil($users[land] * .06); }

        $newland=$randland;

        if ($newland > $config[edcap]) {$newland=$config[edcap];}

        $mageloss= (100-($newland/250))/100;

        if ($mageloss < .94) {$mageloss=.94;}

        $foodloss= (100-($newland/150))/100;

        if ($foodloss < .92) {$foodloss=.92;}

        $cashloss= (100-($newland/750))/100;

        if ($cashloss < .95) {$cashloss=.95;}



        $land = $newland;



        $users[land] = $users[land] + $land;

        $users[freeland] = $users[freeland] + $land;

      $users[health] -= 12;

      $users[wizards]=round($users[wizards]*$mageloss);

      $users[food]=round($users[food]*$foodloss);

      $users[cash]=round($users[cash]*$cashloss);



        $cashloss = ceil($cashloss);

        $foodloss = ceil($foodloss);

        $mageloss = ceil($mageloss);

        $cashloss = commas($cashloss);

        $foodloss = commas($foodloss);

        $mageloss = commas($mageloss);





        SpellSucceed($land." acres was made by your Wizards, however the magic that surrounded the area made you lose many wizards, cash and grain in the process!");

        saveUserData($users,"health land freeland cash food wizards");
    }

    else    SpellFail2();
    taketurns(2,attack);
}
This is the result i get =lose of 10% of health which is ok,no mana,no cash,no grain lose ,no land increase .
EDIT : A friend of mine suggested me to do this :
Check the function "saveUserData" in you main functions include file. Try adding some OR EXIT() statements to make sure various calls are not silentlly failing. Also, var_dump() is very handy. Just be sure to wrap it in a <pre></pre> html block for readability.
Still I don't know how to do this ..if you know I will add you ftp user to my site so you fix that ..
 
Last edited:

cased

New Member
Messages
43
Reaction score
0
Points
0
Are you sure it's this function that's acting up? You are using globals which means anything anywhere could be changing the values after this function is called. Why are you using globals? Call by value functions are much safer. I would suggest you start by testing this function:

$users[land] = $users[land] + $land;

$users[freeland] = $users[freeland] + $land;

$users[health] -= 12;

$users[wizards]=round($users[wizards]*$mageloss);

$users[food]=round($users[food]*$foodloss);

$users[cash]=round($users[cash]*$cashloss);

//Add some echo statements here that will print the values of $users to see
//if they are being set right.


$cashloss = ceil($cashloss);

$foodloss = ceil($foodloss);

$mageloss = ceil($mageloss);

$cashloss = commas($cashloss);

$foodloss = commas($foodloss);

$mageloss = commas($mageloss);

//What is the purpose of this block of code?





SpellSucceed($land." acres was made by your Wizards, however the magic that surrounded the area made you lose many wizards, cash and grain in the process!");

saveUserData($users,"health land freeland cash food wizards");
}

else SpellFail2();
taketurns(2,attack);

Finally, what is it about exit() and vardump() you don't understand? Did you read the entries on php.net?
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
hey, i fixed it earlier today... where's my 500 creds at? :p

just for everyone's general knowledge, the variable $config[edcap] wasn't set, thus ($newland > '') which made $newland = ''; :)

i always ask this, but it seems like you do it alot... did you add this code into the game or was it there from the start? you seem to add code from other versions of this game, so i was just wondering :)

oh, and on a side note, i think you can compress
PHP:
$trandland1 = ceil($users[freeland] * .06);
$trandland2 = $trandland1 + 1;
$trandland3 = ceil($trandland2);
$trandland4 = mt_rand(0, $trandland3);
$randland = ceil($trandland4);

// into

$randland = mt_rand(0, ceil($users[freeland] * .06)+1); //mt_rand should never make a fraction or decimal number
it may seem confusing, but it should have the same effect as the 5 lines above, just in one command :D
 
Last edited:

cased

New Member
Messages
43
Reaction score
0
Points
0
Well I was right about it not being the function's fault anyway.
 

NaHoW

New Member
Messages
244
Reaction score
0
Points
0
Perhaps you can send me an URL of your site where I can see the problem live?
 
Top