Customizing SMF > SMF Coding Discussion
Stat Battle / RPG Mod
Daisuke_aurora:
Bump.
And I replaced
--- Quote ---//Defense v.s. attack?
If ($A - $D > 0)
{
$DA = $A-$D;
}
//Defense v.s. attack?
If ($A - $D < 0)
{
$DA = 0;
}
//Defense v.s. attack?
If ($A - $D = 0)
{
$DA = 0;
}
--- End quote ---
With
--- Quote ---//Defense v.s. attack?
If ($A - $D > 0)
{
$DA = $A-$D;
}
Else
{
$DA = 0;
}
--- End quote ---
It should work the same, right?
[SiNaN]:
Yes, that would do that.
Daisuke_aurora:
Okay, then onto the next problem:
How do I pull information from the Database? I have this as the current Attack.php, but it won't work, I believe I messed up the part where it gets the stats from the DB:
--- Quote ---<?php
if (!defined('SMF'))
die('Hacking attempt...');
function Attack()
{
global $db_prefix, $ID_MEMBER;
checkSession('get');
$A = db_query("
SELECT value FROM {$db_prefix}themes
WHERE variable = 'CP3' && ID_MEMBER = {$ID_MEMBER},");
$D = 5;
$S = db_query("
SELECT value FROM {$db_prefix}themes
WHERE variable = 'CP7' && ID_MEMBER = {$ID_MEMBER},");
$R = 7;
$HP = 50;
$N1 = mt_rand(1, 10);
$N2 = mt_rand(1, 10);
$A1 = $N1 + $S;
$A2 = $A1 + $A;
$D1 = $N2 + $R;
$D2 = $D1 + $D;
//Is A-D positive?
If ($A - $D > 0)
{
$DA = $A-$D;
}
//If it's not...
Else
{
$DA = 0;
}
//Did we power-hit?
If ($A1 > $D2)
{
echo 'You smashed your opponent for ' .($A + $A). ' damage!';
}
else
//Did we hit?
If ($A2 > $D2)
{
echo 'You hit your opponent for ' .($A). ' damage!';
}
else
//Did they dodge?
If ($A2 <= $D1)
{
echo 'Your opponent dodged and took no damage!';
}
else
//Did they block?
If ($A2 <= $D2)
{
echo 'Your opponent blocked, taking only ' .($DA + 1). ' damage!';
}
}
?>
--- End quote ---
Also, I took the "check session" and "If not SMF, die" things from another script because I figured they'd need to be put in eventually.
[SiNaN]:
Find:
--- Code: ---$A = db_query("
SELECT value FROM {$db_prefix}themes
WHERE variable = 'CP3' && ID_MEMBER = {$ID_MEMBER},");
$D = 5;
$S = db_query("
SELECT value FROM {$db_prefix}themes
WHERE variable = 'CP7' && ID_MEMBER = {$ID_MEMBER},");
--- End code ---
Replace:
--- Code: ---$request = db_query("
SELECT value
FROM {$db_prefix}themes
WHERE variable = 'CP3'
AND ID_MEMBER = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
list ($A) = mysql_fetch_row($request);
mysql_free_result($request);
$D = 5;
$request = db_query("
SELECT value
FROM {$db_prefix}themes
WHERE variable = 'CP7'
AND ID_MEMBER = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);
list ($S) = mysql_fetch_row($request);
mysql_free_result($request);
--- End code ---
Daisuke_aurora:
You're awesome Sinan. Works perfectly. I have more I need help with, but I can't really do it piece by piece; I've posted it here somewhere, but I need a button next to "quote" called "attack" that'll run this script when clicked, but take the "attacked" member's D, R.S and HP from the DB and put it into the equation. And I'm sure this part is alot harder than just asking how to do requests for the user's info.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version