Daily Lucky Numbers:
5
10
22
38
47
49

Battle Mod

Started by Fog, July 10, 2013, 10:14:27 PM

Previous topic - Next topic

Fog

First Error...

Members say they get this error when trying to battle another member.

http://s000.tinyupload.com/index.php?file_id=08886079756872952770&gk=hyip

Chen Zhen

Fog,

  That is most likely from me fixing some of those php source files. I need the actual error from the error log so I can pinpoint the line causing the issue.

Chen Zhen


Fog,

  In /Sources/Battle/Battle_Battle.php

replace this function with code shown below:

function battle_fight()
{
global $smcFunc,  $monster, $sourcedir, $damage, $settings, $scripturl, $context, $txt, $modSettings, $user_info;
//We Need Our Template
$context['sub_template']  = 'battle_fight';
$context['page_title'] = $txt['battle'];

if ((@$_SESSION['just_attacked'] == 1))
fatal_error($txt['battle_cheatrefresh'], false);

$attack = !empty($_REQUEST['attack']) ? (int) $_REQUEST['attack'] : 0;
if ($attack == $user_info['id'])
fatal_error($txt['battle_error5'] , false);

// Query the database for the targets information.
$request = $smcFunc['db_query']('','
SELECT def, atk, hp, real_name, id_member, energy, stamina, level
FROM {db_prefix}members
WHERE id_member = '.$attack.'
LIMIT 1'
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$context['battle_target'] = array(
'def' => $row['def'],
'atk' => $row['atk'],
'hp' => $row['hp'],
'real_name' => $row['real_name'],
'id_member' => $row['id_member'],
'energy' => $row['energy'],
'stamina' => $row['stamina'],
'level' => $row['level']
);
}
$smcFunc['db_free_result']($request);

// Figure out the attack and defense and who is better.
$which_atk = 0; $which_def = 0; $this_atk = 0; $this_def = 0;
if ($user_info['def'] > $context['battle_target']['atk'])
$which_atk = $context['battle_target']['atk'] - $user_info['def'];

if ($user_info['atk'] > $context['battle_target']['def'])
$which_def = $context['battle_target']['def'] - $user_info['atk'];

if ($context['battle_target']['def'] > $user_info['atk'])
$this_atk = $user_info['atk'] - $context['battle_target']['def'];

if ($context['battle_target']['atk'] > $user_info['def'])
$this_def = $user_info['def'] - $context['battle_target']['atk'];

// Figure out damage. Put a random seed in, just in case opponents are equal.
if ($user_info['energy'] > 0 && $user_info['stamina'] > 0 && $user_info['hp'] > 0)
{
$this_def = $this_def + mt_rand (0, 5) ;
$this_atk = $this_atk + mt_rand (0, 5);
$which_def = $which_def + mt_rand (0, 5);
$which_atk = $which_atk + mt_rand (0, 5);
if ($which_atk > $this_def)
$this_dmg = $which_atk - $this_def;
else
$this_dmg = mt_rand (0, 5);

if ($this_atk > $which_def)
$which_dmg = $this_atk - $which_def;
else
$which_dmg = mt_rand (0, 5);

//Lets deduct all the stats here since we know we are all good to go.
if ($context['battle_target']['hp'] > 0)
{
// Calculate hp for target and user
$this_hp = $user_info['hp'] - $this_dmg;
$which_hp = $context['battle_target']['hp'] - $which_dmg;
if ($this_hp < 0)
$this_hp = 0;

if ($which_hp < 0)
$which_hp = 0;

// Deduct stamina. Energy commented out, not too common battle apps use energy for attacks, so it made sense to undo my code.
//if ($user_info['energy'] > 0) {$this_energy =  $user_info['energy'] - 1;}
if ($user_info['stamina'] > 0)
$this_stam =  $user_info['stamina'] - 1;

// Some random and logic experience routines.
// Note: I turned exp_def_mem into a max exerience cap, language files need edit to reflect this.[DONE]
if ($user_info['level'] <= $context['battle_target']['level'] && $this_dmg < $which_dmg || $user_info['level'] <= $context['battle_target']['level'] && $which_hp == 0)
{
$this_exp = $user_info['level'] - $context['battle_target']['level'];
$this_exp = $this_exp + mt_rand (0, 3);
if ($this_exp < 1)
$this_exp = 1;

if ($this_exp > $modSettings['exp_def_mem'])
$this_exp = $modSettings['exp_def_mem'];
}

}
else
fatal_error($txt['battle_game_error_toolate'], false);
}
else
fatal_error($txt['battle_game_error_rrro'], false);


//Some stuff to show the user depending on the outcome. Again need to get this assosicated with language files.
if ($which_dmg < $this_dmg)
{
// You lost
@$context['battle_message'] .= '
<center><img border="0" src="'.$settings['images_url'].'/battle/winloose/looser.png" alt=""/></center>
<br />'.$txt['battle_game_lost_you1'] .' '.$which_dmg.' '.$txt['battle_game_lost_you2'].'
<strong>'.$context['battle_target']['real_name'].'</strong> '.$txt['battle_game_lost_you3'].' '.$this_dmg.' '.$txt['battle_game_pm_msg1'].'<br  />';
}
elseif ($which_dmg > $this_dmg)
{
// You won
@$context['battle_message'] .= '
<center><img border="0" src="'.$settings['images_url'].'/battle/winloose/victory.png" alt=""/></center>
<br />'.$txt['battle_game_won_you'].' '.$which_dmg.' '.$txt['battle_game_lost_you2'] .'
<strong>'.$context['battle_target']['real_name'].'</strong> '.$txt['battle_game_lost_you3'].' '.$this_dmg.' '.$txt['battle_game_pm_msg1'].'.<br  />';
}
else
{
// You tied
@$context['battle_message'] .= '
<center><img border="0" src="'.$settings['images_url'].'/battle/winloose/draw.png" alt=""/></center>
<br />'.$txt['battle_game_tied_you'].' '.$which_dmg.' '.$txt['battle_game_lost_you2'].'
<strong>'.$context['battle_target']['real_name'].'</strong> '.$txt['battle_game_lost_you3'].' '.$this_dmg.' '.$txt['battle_game_pm_msg1'].'.<br  />';
}

// If they got some experience show them.
if (isset($this_exp))
$context['battle_message'] .= ''.$txt['battle_game_this_exp'].' '.$this_exp.' '.$txt['battle_game_this_exp1'].'.';

// How about a battle again link? That is if no one is dead.
if ($this_hp > 0 && $which_hp > 0)
{
$context['battle_message'] .= '<br />
'.$txt['battle_this_member'].' '.$which_hp.' '.$txt['battle_points_left'].'
        <form action="' . $scripturl . '?action=battle;sa=fight;attack='.$attack.';home" method="post">
<input type="submit" value ="'.$txt['battle_ex_atk_again'].'" />
</form>';
}

if ($this_hp < 1)
{
// You were killed
$context['battle_message'] .= '
<br /><br />'.$txt['battle_game_99'].' <strong>'.$context['battle_target']['real_name'].'</strong> '.$txt['battle_game_101'].'';
$bhist = ''.$user_info['name'].' '.$txt['battle_hist23'].' '.$context['battle_target']['real_name'].' '.$txt['battle_hist24'].'';
}

if ($which_hp < 1)
{
// You killed them
$context['battle_message'] .= '
<br /><br />'.$txt['battle_game_102'].' <strong>'.$context['battle_target']['real_name'].'</strong>.';
battle_return();
$bhist = ''.$user_info['name'].' '.$txt['battle_hist25'].' '.$context['battle_target']['real_name'];
$_SESSION['just_attacked'] = 1;
$this_slays =  $user_info['mem_slays'] + 1;
}

// Get ready to apply everything
$t = time();
if (isset($this_hp))
updateMemberData($user_info['id'], array('hp' => $this_hp));

if (isset($this_stam))
updateMemberData($user_info['id'], array('stamina' => $this_stam));

// if (isset($this_energy)) {updateMemberData($user_info['id'], array('energy' => $this_energy));}
if (isset($this_exp))
{
$this_exp =  $user_info['exp'] + $this_exp;
updateMemberData($user_info['id'], array('exp' => $this_exp));
}

if (isset($this_hp) && $this_hp == 0)
{
updateMemberData($user_info['id'], array('is_dead' => 1));
battle_Insert_dead($context['battle_target']['id_member'],$user_info['id'],$user_info['username'],$t);
}

if (isset($which_hp))
updateMemberData($context['battle_target']['id_member'], array('hp' => $which_hp));

if (isset($which_hp) && $which_hp == 0)
{
updateMemberData($context['battle_target']['id_member'], array('is_dead' => 1));
updateMemberData($user_info['id'], array('mem_slays' => $this_slays));
battle_Insert_dead($user_info['id'],$context['battle_target']['id_member'],$context['battle_target']['real_name'],$t);
}

//Reset some stuff before the template is phased, we have to be acurate because we just took some points away.
if (isset($this_hp))
$user_info['hp'] = $this_hp;

if (isset($this_stam))
$user_info['stamina'] = $this_stam;

if (isset($this_energy))
$user_info['energy'] = $this_energy;

if (isset($this_exp))
$user_info['exp'] = $this_exp;

if($modSettings['enable_battle_hist'] && isset($bhist))
add_to_battle_hist($bhist);

$request = $smcFunc['db_query']('','
SELECT bpm
FROM {db_prefix}members
WHERE  id_member = {int:attack}
LIMIT 1',
array(
'attack' => $attack,
)
);

list ($no_pm_battle) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

if ($no_pm_battle)
{
$msg = ''.$user_info['username'].' '.$txt['battle_game_pm_msg'].' '.$which_dmg.' '.$txt['battle_game_pm_msg1'].'
[url='. $scripturl. '?action=battle;sa=fight;attack='.$user_info['id'].']'.$txt['battle_game_pm_msg2'].'[/url]';

require_once($sourcedir.'/Subs-Post.php');
$pmfrom = array(
'id' => 0,
'name' => $txt['battle_game_pm_msg3'],
'username' => $txt['battle_game_pm_msg3']
);

$pmto = array(
'to' => array($context['battle_target']['id_member']),
'bcc' => array()
);
sendpm($pmto, $txt['battle_game_pm_msg4'], $msg, 0, $pmfrom);
}
}


Newer mod file with above edit is here:
http://s000.tinyupload.com/index.php?file_id=62244121491388326514

Fog

#78
I have a couple members playing it right now and that's how they found that error...

However they don't like the idea of being able to have a choice of attacking the tank out of range....

They are now asking if they can only attack tanks that include their level in the tanks settings...

I was thinking that they would like the option...

I'll tell them to donate $15 to get the changes done...LOL

You've poured a ton of effort into this and my members are embracing the idea but are full of questions...

I'm amazed how far you've help changed the game...

I'll try to handle most of their question on my end and make sure I'm not going to be a pain in the ass.

It would be cool to get it all dialed in...

Fog

I didn't get an error when attacking a member so it looks like that fixed it...

Thanks.

I'm guessing my screen shots with the url help point you in the right direction...

Like I said I didn't know where to start but you've been patient with me and I'm seeing how this all gets mapped out...


Chen Zhen


Fog,

Here is another file:
http://s000.tinyupload.com/index.php?file_id=02192852801545469294

If you are using your language file to replace, make sure to add this:

$txt['battle_hp_low'] = '<strong>Warning: Your HP is getting low</strong>';


When a person's HP is running low in the middle of a battle it will display a warning to them with a link to the shop.
I moved the attack link/button to the bottom when in battle so that it is easy to know which to press quickly.
Other needed links/buttons are displayed now after defeating monsters/users. Also if the person is dead and attempts to access a quest or explore they get a warning with a link which was missing before.

Prior to me adding anything requested I am going to fix the Leaders info which is not working at the moment.
I do not understand why they do not like the option of attacking the monster. If they do not want to attack, simply run away.

Fog

I hope you got some sleep sometime last night....

You've done more than I ever expected...Thanks

Fog

I have one guy on my website that does most of the admin work on the game and so I gave him the same questions you gave me.

Here's what he said...

What are you trying to accomplish btw?   Ideally I'd love to have the quests dependent upon more than level & energy.   Level & stamina?  Our choice to force them to level their attributes equally.

Do you want to be able to attack the tanks no matter what?  No.

Do you not want to be able to attack the tanks when your user level is beyond the range?  That would speed and clean things up.  Might go against the plan if the goal is to slow them up a bit.

Do you not want the tanks to attack you if outside the range? Definitely not be able to attack tanks above your level.  Under...see last ?

Do you not want the tanks to appear on the map if the user is outside the given range?  It would speed things up if that didn't happen.  Do it.  Much cleaner.

I have never played the game.. do the tanks attack you, vice versa or both? You attack tanks except for the "catch you unaware" thing.  Losing that would be good for people starting out.


I kind of thought the other way round myself on a few things...

Chen Zhen


Update:
http://s000.tinyupload.com/index.php?file_id=02067557409636957051

Changes:

! Added/Finished Leaders Board
! Fixed Admin -> Battle -> Members template and source files
! Language additions and changes
! Changed low hp warning logic and changed its button to just a link




  I'm going to get hold of Wayne & ask if I can take over this mod. After which I am going to fix all the code in it, make more changes/additions and release it anew.


Fog

I have Wayne on FB...do I need to say anything?

He knows I've been seeking help via FB...

Totally Awesome Job....

Let me know how I can help...

Fog

This may be an error on my part. I changed up the English text.

But there isn't a button to click on...


Fog

Here's another look at the no button for repairs.


Fog

If you want me to show you errors another way let me know.

Chen Zhen


Fog,

  You must have changed the entire hyperlink to just text.  Show me the edit you did to the language file that caused that issue.

Chen Zhen

Fog,

  Is this mod's normal behavior set up where an admin/moderator must add users to the game? Or does it normally start someone out with default stat values?