News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Stat Battle / RPG Mod

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

Previous topic - Next topic

Marcus Forsberg

Okay.
I seams to be working great, but it only says "Your opponent dodged and took no damage!" every time I attack, so I don't know how it removes HP and all of that. :P

Also, I thought that if your users just keep fighting and fighting each topic will be filled up whit messages, which will Be pretty annoying.

Daisuke_aurora

The script has been updated to say your name and their name in place of you  and your opponent.

If your stats are too much lower than your opponents, than yes, you'll never hurt them  ;).

Users can only use the attack buttons in threads called PvP threads, and the prupose behind the button is merely to tell the user whether they made a successful attack or not. The users at my site are Role-Players, so by using the attack function to determine whether they hit their opponent or not, they can then write out their action.

Example: Player A uses the attack button, and it says he hits. He writes a post like this:

"Player A draws his trusty pistol and cocks the hammer, firing a shot at the mysterious man in front of him. The bullet tears into his foe's shoulder."

His opponent can respond then by hitting the attack button and seeing what happens, then Posting a response in kind with that.

This goes back and forth until one person gives up or dies, and then the Admin can go back and delete the posts that simply state what hit and missed later, making it much easier to re-read for our other members. And I made a profile called "The Referee" and set his ID to the poster ID so he's the one who makes the posts, so that we can just go back and delete all his posts to clear out the forums.

I can send you the Stat Items I made for the Shop and some basic instructions on how to run it if you'd be interested.

Marcus Forsberg

Quote from: Daisuke_aurora on September 29, 2008, 03:22:51 PM
I can send you the Stat Items I made for the Shop and some basic instructions on how to run it if you'd be interested.

Yes, I'm interested :)

[SiNaN]

Well, then before running those queries, check if the $HP is empty or not. And also, you can send 'type' with url and do them all with just one function.

For example:

For physical => http://yoursite.com/index.php?action=attack;attacked=3;arena=1;country=6;type=physical
For magical => http://yoursite.com/index.php?action=attack;attacked=3;arena=1;country=6;type=magical

Then at the start of your Attack function:

if(!empty($_REQUEST['type']) && in_array($_REQUEST['type'], array('physical', 'magical')))
  $type = $_REQUEST['type'];
else
  fatal_error('Undefined type');

Then you will calculate variables according to that:

if($type == 'magical')
  $variables = a;
else
  $variables = b;

I really don't know how can I help you anymore. If you have specific coding questions, I can answer them if I can.

And Nascar; you can easily limit to a single board and call it the Battle Area.
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

Here you go, I attached the 12 items I have right now with a brief Read Me of what they do.

I'll write up a full explanation on the StatBattle system and how it works, what to do to set it up etc. and post it tomorrow.

Thanks for all your help, SiNaN! The only question I have is how to make it go to an error screen (like the "die(hacking attempt)" one and have it say "you can't attack for whatever reason" instead of actually posting it on the board.

[SiNaN]

That was an easy question really. :)

In the if, instead of doing

$msg = 'You cannot attack';

do

fatal_error('You cannot attack!', false);
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

Dude, you really are awesome at this!

If I ever make this into a complete Mod for the Mod site, I'm giving you top billing for the credit:

By SiNaN / Daisuke.

Thanks yet again, and if I ever need anything else I'l post. Thanks!

[SiNaN]

You're welcome. Glad that I could help you.
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

Update for Nascar:

Please download the attached file, it has an updated version of Potion, Full Heal, and Elixir as well as a Pheonix Down to revive dead players.

The update makes it so dead players cannot use a potion to revive themselves (kind of cheating lol.)

matasanos

uhmm!!!

this sound more and more exciting !!!
when we will have a complete mod?? or a stable version? moreless..

Daisuke_aurora

#50
The current version os Satble, but there's no mod for it yet lol.

At the moment, the following things are done:

-Stat system
-Stat items
-Auto-Adjusting HP and MP.
-Attack buttons

But there's still a few things I'll need to do before it's really ready to be done:

-Make the function move "dead" people into a non-post based group called "Dead."
-Make a permission so that "Dead" members cannot attack at all.
-Make a restriction somehow so that people cannot attack the same person repeatedly and kill them before an Admin can step in. (They'd get punished obviously, but it'd still suck to have to go back and fix it.)
-Making an edit to some files so that when a member gains enough posts to "level up" by reaching the next highest post group, he'll also get some stat items at random. (Should be easy to code, but I've no idea what files I'd need to edit...)
-Making a few other things just to make things smoother...

Marcus Forsberg

This sound really interesting. I'll test everything in a few hours.

And I just thought, couldn't you adjust the mod so that it adds its own profile fields when installed, so that Custom Profile Fields mod doesn't need to be used at all?

Daisuke_aurora

Probably, but since it isn't yet a mod so much as it is 2 edits and 1 file, I'll have to see about adding that it when it's done.

Also, the Custom Profile Fields mod doesn't work on 1.1.6, so I'll probably just end up integrating that mod's edits into my own mod (As long as thats okay with the mod's maker.)

[SiNaN]

Custom Profile Field uses this system.
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

#54
Nice, thanks again!

Update:

I added some more checks to the codes (making sure you cannot attack dead people, people with no stats, yourself, if you have no stats, if you're dead) and also I added a chunk that checks to see if your attack killed the enemy, and if it did, to give you posts equal to 1/10th of their posts as a reward. (The stat system uses levels, and posts are the system's EXP. So, you get EXP for killing someone now.)\

Update again:

I'm working on adding Status effects to the Stat battle system, so that players can be poisoned, blind, silenced, etc. Also working on items to heal said status effects or cause them.

Daisuke_aurora

#55
Okay, now I need help again  :P.

<?php

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

//The Physical attack function.
function Physical()
{
global $db_prefix$sourcedir$ID_MEMBER;

//Find out who attacked who, and where.
$attacked_id = !empty($_REQUEST['attacked']) ? (int) $_REQUEST['attacked'] : 0;
$attacked_topic = !empty($_REQUEST['arena']) ? (int) $_REQUEST['arena'] : 0;
$attacked_board = !empty($_REQUEST['country']) ? (int) $_REQUEST['country'] : 0;

//Get the attacker's Atk value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP3'
&& ID_MEMBER = 
$ID_MEMBER   
LIMIT 1"
__FILE____LINE__);
list ($A) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the defender's Def value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP4'
&& ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($D) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the attacker's Spd value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes
WHERE variable = 'CP7'
&& ID_MEMBER = 
$ID_MEMBER
LIMIT 1"
__FILE____LINE__);
list ($S) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the defender's R. Spd value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP8'
&& ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($R) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the Defender's HP value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP9'
&& ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($HP) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the attacker's HP value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP9'
&& ID_MEMBER = 
$ID_MEMBER   
LIMIT 1"
__FILE____LINE__);
list ($youHP) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the attacker's name.
$request db_query("
SELECT realname
FROM 
{$db_prefix}members   
WHERE ID_MEMBER = 
$ID_MEMBER   
LIMIT 1"
__FILE____LINE__);
list ($you) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the defender's name.
$request db_query("
SELECT realname
FROM 
{$db_prefix}members   
WHERE ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($them) = mysql_fetch_row($request);
mysql_free_result($request);

//The actual Stat Battle formula.
$N1 mt_rand(110);
$N2 mt_rand(110);
$A1 $N1 $S;
$A2 $A1 $A;
$D1 $N2 $R;
$D2 $D1 $D;

//Can you even hurt anyone?
if(empty($A))
 
{
fatal_error('You have no attack value! Did you really think you could win by attacking for 0?'false);
$HP2 0;
}

//Are you suicidal?
elseif($attacked_id == $ID_MEMBER)
 
{
fatal_error('You cannot attack yourself!'false);
$HP2 0;
}

//Are you killing dead people?
elseif(empty($HP))
{
fatal_error('Either they are dead or have no stats! You cannot attack them!'false);
$HP2 0;
}

//Are you a dead?
elseif(empty($youHP))
{
fatal_error('You cannot attack someone if you are dead!'false);
$HP2 0;
}
//Are you beating the Ref?
elseif($attacked_id == 42)
{
fatal_error('You cannot attack the Referee!'false);
$HP2 0;
}
//Did you Smash them?
elseif ($A1 $D2)
{
$damage $A $A;
$HP2 $HP $damage $HP $damage 0;
$msg '' .($you). ' smashed ' .($them). ' for ' .($damage). ' damage!';
}

//Did you hit them?
elseif ($A2 $D2)
{
$HP2 $HP $A $HP $A 0;
$msg '' .($you). ' attacked ' .($them). ' for ' .($A). ' damage!';
}

//Did they dodge your attack?
elseif ($A2 <= $D1)
{
$msg '' .($them). ' dodged an attack by ' .($you). ' and took no damage!';
}

//Did they block your attack?
elseif ($A2 <= $D2)
{
$DA $A $D $A-$D 0;
$damage $DA 1;
$HP2 $HP $damage $HP $damage 0;
$msg '' .($them). ' blocked an attack by ' .($you). ', taking only ' .($damage). ' damage!';
}

//Do the damage.
db_query("
UPDATE 
{$db_prefix}themes
SET value = 
{$HP2}
WHERE variable = 'CP9' && ID_MEMBER = 
{$attacked_id}"__FILE____LINE__);

//Did you Kill them?
if (empty($HP2))
{
//Get their EXP.
$request db_query("
SELECT posts
FROM 
{$db_prefix}members   
WHERE ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($Exp) = mysql_fetch_row($request);
mysql_free_result($request);

$Exp2 $Exp/10;

round($Exp2);

//Give the winner some EXP.
db_query("
UPDATE 
{$db_prefix}members
SET posts = posts + 
{$Exp2}
WHERE ID_MEMBER = 
{$ID_MEMBER}"__FILE____LINE__);

//Did they recieve a Random Item drop?
$lucky mt_rand(30,80);
if($lucky 40 && $lucky 60 && $lucky != 49 && $lucky != 51 && $lucky != 52 && $lucky != 58)
{
db_query("
INSERT INTO 
{$db_prefix}shop_inventory
(ownerid, itemid, amtpaid)
VALUES (
{$ID_MEMBER},
{$lucky},
0)"
, __FILE____LINE__);

$request db_query("
SELECT name
FROM 
{$db_prefix}shop_items   
WHERE id = 
$lucky   
LIMIT 1"
__FILE____LINE__);
list ($item) = mysql_fetch_row($request);
mysql_free_result($request);

$msg2 '' .($msg). ' ' .($you). ' killed ' .($them). '! Congratulations, ' .($you). '! You got ' .($Exp2). ' EXP, and an item dropped! You recieved 1 ' .($item). '!';
}
else
{
$msg2 '' .($msg). ' ' .($you). ' killed ' .($them). '! Congratulations, ' .($you). '! You got ' .($Exp2). ' EXP!';
}
$msgOptions = array(
'id' => 0,
'subject' => 'Physical Attack!',
'body' => $msg2,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => $attacked_topic,
'board' => $attacked_board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => 42,
'update_post_count' => 1,
);
}
//If they're still alive...
Else
{
$msgOptions = array(
'id' => 0,
'subject' => 'Physical Attack!',
'body' => $msg,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => $attacked_topic,
'board' => $attacked_board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => 42,
'update_post_count' => 1,
);
}

require_once($sourcedir '/Subs-Post.php');
createPost($msgOptions$topicOptions$posterOptions);

redirectexit('topic=' $attacked_topic);
}



//Same as Physical, except for the reducing MP and checking MP parts.
function Magical()
{
global $db_prefix$sourcedir$ID_MEMBER;

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

$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP5'
&& 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 = 'CP6'
&& 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'
&& 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'
&& 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'
&& ID_MEMBER = 
$attacked_id   
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'
&& ID_MEMBER = 
$ID_MEMBER   
LIMIT 1"
__FILE____LINE__);
list ($youHP) = mysql_fetch_row($request);
mysql_free_result($request);

//Get the attacker's MP Value.
$request db_query("
SELECT value
FROM 
{$db_prefix}themes   
WHERE variable = 'CP10'
&& ID_MEMBER = 
$ID_MEMBER   
LIMIT 1"
__FILE____LINE__);
list ($MP) = mysql_fetch_row($request);
mysql_free_result($request);

$request db_query("
SELECT realname
FROM 
{$db_prefix}members   
WHERE ID_MEMBER = 
$ID_MEMBER   
LIMIT 1"
__FILE____LINE__);
list ($you) = mysql_fetch_row($request);
mysql_free_result($request);


$request db_query("
SELECT realname
FROM 
{$db_prefix}members   
WHERE ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($them) = mysql_fetch_row($request);
mysql_free_result($request);

$N1 mt_rand(110);
$N2 mt_rand(110);
$A1 $N1 $S;
$A2 $A1 $A;
$D1 $N2 $R;
$D2 $D1 $D;
$MP2 $MP $A $MP $A 0

if(empty($A))
 
{
fatal_error('You have no Magic attack value! Did you really think you could win by attacking for 0?'false);
$HP2 0;
}

//No Mp? No attack.
elseif ($MP $A)
{
fatal_error('You do not have enough MP! Magic attacks are not free, you know.'false);
$HP2 0;
}
elseif($attacked_id == $ID_MEMBER)
 
{
fatal_error('You cannot attack yourself!'false);
$HP2 0;
}

elseif(empty($HP))
{
fatal_error('You cannot attack a dead person!'false);
$HP2 0;
}
elseif(empty($youHP))
{
fatal_error('You cannot attack someone if you are dead!'false);
$HP2 0;
}
//Are you beating the Ref?
elseif($attacked_id == 42)
{
fatal_error('You cannot attack the Referee!'false);
$HP2 0;
}
elseif ($A1 $D2)
{
$damage $A $A;
$HP2 $HP $damage $HP $damage 0;
$msg '' .($you). ' blasted ' .($them). ' for ' .($damage). ' damage!';
}
elseif ($A2 $D2)
{
$HP2 $HP $A $HP $A 0;
$msg '' .($you). ' attacked ' .($them). ' using Magic for ' .($A). ' damage!';
}
elseif ($A2 <= $D1)
{
$msg '' .($them). ' dodged a Magic attack from ' .($you). ' and took no damage!';
}
elseif ($A2 <= $D2)
{
$DA $A $D $A $D 0;
$damage $DA 1;
$HP2 $HP $damage $HP $damage 0;
$msg '' .($them). ' blocked a Magic attack from ' .($you). ', taking only ' .($damage). ' damage!';
}


db_query("
UPDATE 
{$db_prefix}themes
SET value = 
{$HP2}
WHERE variable = 'CP9' && ID_MEMBER = 
{$attacked_id}"__FILE____LINE__);

//Pay for the spell.
db_query("
UPDATE 
{$db_prefix}themes
SET value = 
{$MP2}
WHERE variable = 'CP10' && ID_MEMBER = 
{$ID_MEMBER}"__FILE____LINE__);

//Did you Kill them?
if (empty($HP2))
{
//Get their EXP.
$request db_query("
SELECT posts
FROM 
{$db_prefix}members   
WHERE ID_MEMBER = 
$attacked_id   
LIMIT 1"
__FILE____LINE__);
list ($Exp) = mysql_fetch_row($request);
mysql_free_result($request);

$Exp2 $Exp/10;

round($Exp2);

//Give the winner some EXP.
db_query("
UPDATE 
{$db_prefix}members
SET posts = posts + 
{$Exp2}
WHERE ID_MEMBER = 
{$ID_MEMBER}"__FILE____LINE__);

//Did they recieve a Random Item drop?
$lucky mt_rand(30,80);
if($lucky 40 && $lucky 60 && $lucky != 49 && $lucky != 51 && $lucky != 52 && $lucky != 58)
{
db_query("
INSERT INTO 
{$db_prefix}shop_inventory
(ownerid, itemid, amtpaid)
VALUES (
{$ID_MEMBER},
{$lucky},
0)"
, __FILE____LINE__);

$request db_query("
SELECT name
FROM 
{$db_prefix}shop_items   
WHERE id = 
$lucky   
LIMIT 1"
__FILE____LINE__);
list ($item) = mysql_fetch_row($request);
mysql_free_result($request);

$msg2 '' .($msg). ' ' .($you). ' killed ' .($them). '! Congratulations, ' .($you). '! You got ' .($Exp2). ' EXP, and an item dropped! You recieved 1 ' .($item). '!';
}

else
{
$msg2 '' .($msg). ' ' .($you). ' killed ' .($them). '! Congratulations, ' .($you). '! You got ' .($Exp2). ' EXP!';
}
$msgOptions = array(
'id' => 0,
'subject' => 'Physical Attack!',
'body' => $msg2,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => $attacked_topic,
'board' => $attacked_board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => 42,
'update_post_count' => 1,
);
}
Else
{
$msgOptions = array(
'id' => 0,
'subject' => 'Physical Attack!',
'body' => $msg,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => $attacked_topic,
'board' => $attacked_board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => 42,
'update_post_count' => 1,
);
}

require_once($sourcedir '/Subs-Post.php');
createPost($msgOptions$topicOptions$posterOptions);

redirectexit('topic=' $attacked_topic);
}

?>


Everything works fine, except one of my members gets an error when he tries to attack me:

Database Error
Please try again. If you come back to this error screen, report the error to an administrator.

I have no idea why though, other people can attack me and they can all attack each other. Any ideas?

Also, SiNaN, I'm not exactly sure how to make this into one function  :P sorry I'm not that good at this.

Also, the Round function isn't working for some reason.

[SiNaN]

Add this line to your Settings.php:

$db_show_debug = true;

Then you will be able to see the whole query causing error on the error page.

When you complete it, I can make it doing them with one function for you.

Instead of just round($var); you should make $var = round($var); to make it rounded.
Former SMF Core Developer | My Mods | SimplePortal

Daisuke_aurora

Thanks a bunch, SiNaN. It'll probably take me about a week to finish it though (I'm adding weapons and stat effects, spells, etc. stuff like that. It's all going to be "if" codes that check for the status effect / weapon and then carry out whatever the stat effect / weapon does.)

I'll post again if I need more help or when it's done.

Daisuke_aurora

Ok, my letters got big again. I tried changing the names of the buttons, and they got huge and my avatar pic is now an x. I changed them back, but somethign must be wrong, as it isn't fixed... Attached the 2 files I edited, any idea why it got messed up?

Daisuke_aurora

#59
Also I can't log in... no one can... strange...?

Edit: Also, I get these errors at the top of the page:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Load.php on line 1981

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Load.php on line 1981

Warning: Cannot modify header information - headers already sent by (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Load.php on line 1985

Warning: Cannot modify header information - headers already sent by (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Subs.php on line 3365

Warning: Cannot modify header information - headers already sent by (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Subs.php on line 3366

Warning: Cannot modify header information - headers already sent by (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Subs.php on line 3372

Warning: Cannot modify header information - headers already sent by (output started at /home/daisuke/public_html/forum/index.php:3) in /home/daisuke/public_html/forum/Sources/Subs.php on line 3375

Advertisement: