Stat Battle / RPG Mod

Started by Daisuke_aurora, September 04, 2008, 11:56:08 AM

Previous topic - Next topic

Daisuke_aurora

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.

[SiNaN]

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

matasanos

#2
yes...i am interested!!

Daisuke_aurora

#3
Quote from: [SiNaN] 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.

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.

Quote from: matasanos on September 04, 2008, 04:39:25 PM
yes...i am interested!!

Then come on over to the Dojo  and sign up.

Daisuke_aurora

#4
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...

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;
}
With
Quote
//Defense v.s. attack?
If ($A - $D > 0)
{
                        $DA = $A-$D;
}
Else
{
                        $DA = 0;
}
It should work the same, right?

[SiNaN]

Former SMF Core Developer | My Mods | SimplePortal

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

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:

$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:

$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

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.

[SiNaN]

You want a button on every post?
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

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 = '[email protected]';

      $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?

[SiNaN]

About the first issue:

Save your codes  as Attack.php.

../index.php

Find:

'announce' => array('Post.php', 'AnnounceTopic'),

Replace:

'attack' => array('Attack.php', 'Attack'),

../Themes/your_theme/Display.template.php

Find:

// Show online and offline buttons?

Replace:

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

// Show online and offline buttons?


Find:

   checkSession('get');

Replace:

   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

Daisuke_aurora

Is there one here? I tried the SMF Shop forum at daniel15.com, but no one there is ever on.

[SiNaN]

Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

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?

[SiNaN]

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

Daisuke_aurora

I think this i swhy I have big text:

QuoteYou 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

[SiNaN]

You should put these

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


codes after these

      global $db_prefix, $ID_MEMBER;
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

I got this error when I did that:

QuoteUnable to load the 'main' template.

Advertisement: