Advertisement:

Author Topic: Stat Battle / RPG Mod  (Read 62539 times)

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Stat Battle / RPG Mod
« on: September 04, 2008, 11:56:08 AM »
I need some help writing a Mod. Basically I want the following:

-A button like the quote button called "attack" that, when clicked, will run a file (attack.php most likely) that will input your stats and the chosen member's stats into a formula that determines whether your attack hit, missed, watever, and then after that it posts the results of the attack in the thread as an admin and updates the attacked person's HP stat to reflect any damage he may have taken.

I'm not exactly good at this, but I figure it would have to edit the files that show the quote button to add this button, and I'd need to make the file attack.php and put it in Sources.

I assume the Attack.php file would look like a much MUCH better version of this general idea:


-Find who you are.
-Find who you "attacked."
-Find your stats "A" and "S" and set them to variables $A and  $S (They are in the Themes table, and are called CP3 and CP5.)
-Find your opponents stats "HP" "D" and "R" and set them to variables $HP, $D and  $R (They are in the Themes table, and are called CP1, CP4 and CP6.)
-Set $N1 and $N2 (random numbers between 1 and 10)

The "battle" part

-$A1=$N1+$S.
-$D1=$R+$N2.
-$A2=$A1+$A.
-$D2=$D1+$D.


-If $A1>$D2, then update $HP stat: $HP - ($Ax2). And Print "(You) smashed (opponent) for $Ax2 damage!" As a post in the topic where you attacked him

-Else if $A2>$D2, then update $HP stat: $HP - $A. And Print "(You) hit (opponent) for $A damage!" As a post in the topic where you attacked him.

-Else if $A2<$D2, then update $HP stat: $HP - ($A-$D ). A-D can't be lower than 0. Then subtract another 1 from their HP. And Print "(You) attacked (Opponent), but they blocked, only taking ($A-$D)+1 damage!" As a post in the topic where he attacked him.

-If $A2<$D1, then Print "(You) attacked (Opponent), but they dodged it!" As a post in the topic where he attacked him.


Also, when a member has 0 HP, they get put into a group called Defeated.

And lastly, permissions for the Attack button that allow me to set which groups can use the attack button.
I know this looks daunting, but I really would love the help, as I am unable to figure out PHP enough to do it by myself.
« Last Edit: May 22, 2012, 03:07:17 PM by Daisuke_aurora »

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #1 on: September 04, 2008, 04:27:28 PM »
It looks interesting. I whish I had some time to code this. If you want, I can move this to the Mod Requests board.
Former SMF Core Developer | My Mods | SimplePortal

Offline matasanos

  • Jr. Member
  • **
  • Posts: 267
    • Lords-Beer.net
Re: Stat Battle Mod
« Reply #2 on: September 04, 2008, 04:39:25 PM »
yes...i am interested!!
« Last Edit: September 04, 2008, 04:57:04 PM by matasanos »

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #3 on: September 05, 2008, 08:39:08 AM »
It looks interesting. I whish I had some time to code this. If you want, I can move this to the Mod Requests board.

Sure, thank you.

I'd love to get this done, simply because I've seen so many people who want to make RP boards that use stats like this. I already had help and made items that affect the stats, a system for using them (basically the coding above but done IRL by an Admin) and am working on some other things to make the system full automated. Maybe one day soon it'll be one big Mod called Stats or something.

yes...i am interested!!

Then come on over to the Dojo  and sign up.
« Last Edit: September 05, 2008, 08:41:11 AM by Daisuke_aurora »

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #4 on: September 08, 2008, 10:35:49 AM »
Anybody else interested in helping me? I partially coded it, but as of now it has to have numeric input, and it only does the formula, not the posting, HP adjusting, or membergroup changing.

Quote
$A = 8;
$D = 5;
$S = 8;
$R = 7;
$N1 = mt_rand(1, 10);
$N2 = mt_rand(1, 10);
$A1 = $N1 + $S;
$A2 = $A1 + $A;
$D1 = $N2 + $R;
$D2 = $D1 + $D;


//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;
}
//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 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!';
}
else
//Did they block?
If ($A2 = $D2)
{
                        echo 'Your opponent blocked, taking only ' .($DA + 1). ' damage!';
}

It's currently set to run in a phpbox in my portal on my homepage, so we can use it to determine the results, but it needs work obviously...
« Last Edit: September 08, 2008, 01:57:48 PM by Daisuke_aurora »

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #5 on: September 09, 2008, 11:04:15 AM »
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;
}
With
Quote
//Defense v.s. attack?
If ($A - $D > 0)
{
                        $DA = $A-$D;
}
Else
{
                        $DA = 0;
}
It should work the same, right?

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #6 on: September 11, 2008, 10:53:16 AM »
Yes, that would do that.
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #7 on: September 11, 2008, 11:03:35 AM »
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!';
}
}
?>

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.

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #8 on: September 11, 2008, 02:01:05 PM »
Find:

Code: [Select]
$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},");

Replace:

Code: [Select]
$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);
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #9 on: September 11, 2008, 02:31:09 PM »
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.

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #10 on: September 11, 2008, 02:37:03 PM »
You want a button on every post?
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #11 on: September 11, 2008, 02:49:03 PM »
Yes, just like the quote button.

Also, i'm getting an error in this item I made:

Quote
<?php
/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2007-01-18 19:26:55 +1100 (Thu, 18 Jan 2007)                          $ *
* $Id:: IncreaseAtk.php 79 2007-01-18 08:26:55Z Daisuke                         $ *
* Software by:                Daisuke (http://www.daisukesdojo.heliohost.org/)    *
* Copyright 2005-2007 by:     Daisuke (http://www.daisukesdojo.heliohost.org/)    *
* Support, News, Updates at:  http://www.daisukesdojo.heliohost.org/              *
*                                                                                 *
* Forum software by:          Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version of the license can always be found at                        *
* http://www.simplemachines.org.                                                  *
**********************************************************************************/

if (!defined('SMF'))
   die('Hacking attempt...');

class item_Potion extends itemTemplate
{
   function getItemDetails()
   {
      $this->authorName = 'Daisuke';
      $this->authorWeb = 'http://www.daisukesdojo.heliohost.org/';
      $this->authorEmail = 'Daisuke_aurora@hotmail.com';

      $this->name = 'Potion!';
      $this->desc = 'Restores 30 HP!';
      $this->price = 500;

      $this->require_input = false;
      $this->can_use_item = true;
      $this->addInput_editable = true;
   }
   
   // See 'AddToPostCount.php' for info on how this works
   function getAddInput()
   {
      global $user_info;
      if ($item_info[1] == 0) $item_info[1] = 1;
      return 'Amount to increase Current HP by: <input type="text" name="info1" value="' . $item_info[1] . '" />';
   }

   function onUse()
   {
      global $db_prefix, $ID_MEMBER, $item_info;

      $request = db_query("
      SELECT value
      FROM {$db_prefix}themes   
      WHERE variable = 'CP1'      
      AND ID_MEMBER = $ID_MEMBER   
   LIMIT 1", __FILE__, __LINE__);
list ($HP) = mysql_fetch_row($request);
mysql_free_result($request);


      $request = db_query("
      SELECT value
      FROM {$db_prefix}themes   
      WHERE variable = 'CP9'      
      AND ID_MEMBER = $ID_MEMBER   
   LIMIT 1", __FILE__, __LINE__);
list ($MAX) = mysql_fetch_row($request);
mysql_free_result($request);

If ($HP + 30 > $MAX)
   


      db_query("
         UPDATE {$db_prefix}themes
         SET value = $MAX
         WHERE variable = 'CP1' AND ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);      return 'Successfully increased your Attack by ' . $item_info[1] . '!';
   }
else
If ($HP + 30 <= $MAX)
{
      db_query("
         UPDATE {$db_prefix}themes
         SET value = value + {$item_info[1]}
         WHERE variable = 'CP1' AND ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);      return 'Successfully increased your Attack by ' . $item_info[1] . '!';
   }
}

?>

Basically, it's supposed to get your Current HP and Max HP, make sure that Current + 30 isn't over your max (If it is, it sets your current to your Max) or add 30 to your current. It says there's an error on line 90, unexpected Else?

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #12 on: September 11, 2008, 03:01:07 PM »
About the first issue:

Save your codes  as Attack.php.

../index.php

Find:

Code: [Select]
'announce' => array('Post.php', 'AnnounceTopic'),
Replace:

Code: [Select]
'attack' => array('Attack.php', 'Attack'),
../Themes/your_theme/Display.template.php

Find:

Code: [Select]
// Show online and offline buttons?
Replace:

Code: [Select]
echo '<a href="' . $scripturl . '?action=attack;attacked=' . $message['member']['id'] . ';sesc=', $context['session_id'], '">[Attack]</a>';

// Show online and offline buttons?

Find:

Code: [Select]
   checkSession('get');
Replace:

Code: [Select]
   checkSession('get');

$attacked_id = !empty($_REQUEST['attacked']) ? (int) $_REQUEST['attacked'] : 0;

Then get the info as you did for the others. Just use $attacked_id instead of $ID_MEMBER.

For second;

You should try the SMF Shop support topic.
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #13 on: September 11, 2008, 03:02:41 PM »
Is there one here? I tried the SMF Shop forum at daniel15.com, but no one there is ever on.

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #14 on: September 11, 2008, 03:10:01 PM »
It's here.
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #15 on: September 11, 2008, 03:19:12 PM »
Okay, a few issues:

1. My forum now has huge letters and all the pictures are X's.

2. There is no attack button in any of the posts; going to the action attack action does nothing (I assume because there was no button, the opponents stats aren't there to use.)

3. I WAS supposed to put the checksession code in Attack.php right?

4. Was i supposed to completely erase the announce action?

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #16 on: September 11, 2008, 03:27:37 PM »
1) Make sure you applied the edits correctly.

2) There should be in posts, in the profile area of a message, unless you add it in the wrong line.

3) Yes.

4) First edit should be "add after", I missed it. So announce stays there, but you add attack after that.
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #17 on: September 11, 2008, 03:39:00 PM »
I think this i swhy I have big text:

Quote
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 5
File: /home/daisuke/public_html/forum/Sources/Attack.php
Line: 27

The message I got when I attacked someone.

Quote
<?php

if (!defined('SMF'))
   die('Hacking attempt...');

checkSession('get');
   $attacked_id = !empty($_REQUEST['attacked']) ? (int) $_REQUEST['attacked'] : 0;

function Attack()
{
      global $db_prefix, $ID_MEMBER;

$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);

$request = db_query("
      SELECT value
      FROM {$db_prefix}themes   
      WHERE variable = 'CP4'      
      AND ID_MEMBER = $attacked_id   
   LIMIT 1", __FILE__, __LINE__);
list ($D) = mysql_fetch_row($request);
mysql_free_result($request);

$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);


$request = db_query("
      SELECT value
      FROM {$db_prefix}themes   
      WHERE variable = 'CP8'      
      AND ID_MEMBER = $attacked_id   
   LIMIT 1", __FILE__, __LINE__);
list ($R) = mysql_fetch_row($request);
mysql_free_result($request);


$request = db_query("
      SELECT value
      FROM {$db_prefix}themes   
      WHERE variable = 'CP9'      
      AND ID_MEMBER = $attacked_id   
   LIMIT 1", __FILE__, __LINE__);
list ($HP) = mysql_fetch_row($request);
mysql_free_result($request);

$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!';
}
}
?>

My current Attack.php

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,526
  • Young and Foolish
    • SimplePortal
Re: Stat Battle Mod
« Reply #18 on: September 11, 2008, 03:41:24 PM »
You should put these

Code: [Select]
checkSession('get');
   $attacked_id = !empty($_REQUEST['attacked']) ? (int) $_REQUEST['attacked'] : 0;

codes after these

Code: [Select]
      global $db_prefix, $ID_MEMBER;
Former SMF Core Developer | My Mods | SimplePortal

Offline Daisuke_aurora

  • Jr. Member
  • **
  • Posts: 168
  • Gender: Male
  • Move like water, to wash your opponents away...
    • Daisuke's Dojo
Re: Stat Battle Mod
« Reply #19 on: September 11, 2008, 03:43:13 PM »
I got this error when I did that:

Quote
Unable to load the 'main' template.