Daily Lucky Numbers:
5
8
14
28
31
49

Battle Mod

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

Previous topic - Next topic

Chen Zhen

Fog,

  Take a good look at those source files tonight. Post in here if/when you need further assistance and I will respond tomorrow.. time for some tv and then bed. 

Fog

Quote from: underdog on July 12, 2013, 12:16:19 AM
Fog,

  Take a good look at those source files tonight. Post in here if/when you need further assistance and I will respond tomorrow.. time for some tv and then bed.

I will sir...have a good night

Thanks.

Fog

#32
I found all the mon_range in the sources...however I did find this in Battle Temp.

// Attack or run away?

if (empty($row['mon_range']) or $row['mon_range'] <= $user_info['level']) {

echo '

                <br />

                <form action="' . $scripturl . '?action=battle;sa=fm;mon='.$row['id_monster'].'" method="post">

<input type="submit" value ="'.$txt['battle_atk'].'" />

                 </form>

'.$txt['battle_or'].'<br />

                 <form action="' . $scripturl . '?action=battle;sa=explore" method="post">

                 <input type="submit" value ="'.$txt['battle_run'].'" />

                 </form>';

}

else {

echo '<br />'.$txt['battle_not_range'].'',

battle_return();

}

}

}

}

}



Not sure what to do with this code...

It looks like this code you posted...

if ($userPower < $mon_range || $userPower > $mon_max_range)
{// ignore the user}

Fog

BTW...this is what the page looks like when you create or edit a Tank.


Chen Zhen

#34
Fog,

Perhaps this is what you want for that edit :

// Attack or run away?
$checkTank = array(!empty($row['mon_range']) ? $row['mon_range'] : 1, !empty($row['mon_max_range']) ? $row['mon_max_range'] : 1);
if ($checkTank[0] >= $user_info['level'] && $checkTank[1] <= $user_info['level']) {

echo '

                <br />

                <form action="' . $scripturl . '?action=battle;sa=fm;mon='.$row['id_monster'].'" method="post">

<input type="submit" value ="'.$txt['battle_atk'].'" />

                 </form>

'.$txt['battle_or'].'<br />

                 <form action="' . $scripturl . '?action=battle;sa=explore" method="post">

                 <input type="submit" value ="'.$txt['battle_run'].'" />

                 </form>';

}

else {

echo '<br />'.$txt['battle_not_range'].'',

battle_return();

}

}

}

}

}


  Before that will work you have to ensure it queries $row['mon_max_range'] in the mysql directly prior to it.

  Imo should be Tanks Attack Range instead of Tanks Starting Range because it is min/max. The template looks good but perhaps position the image directly above the drop-down directly to the right of Tank Image: (<-- couple of spaces)? .. just a suggestion.

Fog

Doing some testing...the min is working no problem

But the max isn't so far.

Chen Zhen

Fog,

  Check the edit again as I adjusted it. You need to add to the mysql query prior to the above edit. Show me the mysql ($smcFunc) just before that edit within the while loop.

Fog

How do I add the MySQL query and how would I show you?


Chen Zhen

Fog,

  The code you posted used a $row array so I am assuming just before that code is something querying data from the db. You will see something with $smcFunc in it follow by a while loop.

ie.

$request = $smcFunc['db_query']('', '

   SELECT name, atk, def, hp, img, max_hp, mon_range

   FROM {db_prefix}battle_monsters

   WHERE id_monster = {int:id_monster}',

   array(

      'id_monster' => $context['monster']['id'],

   )

);

  while ($row = $smcFunc['db_fetch_assoc']($request))

  {


.. you need to add mon_max_range to the query...


SELECT name, atk, def, hp, img, max_hp, mon_range, mon_max_range


Fog

function battle_search() {



global  $context, $user_info, $txt, $modSettings, $smcFunc;



// In the end every one of these should have a template instead of sharing.

$context['sub_template']  = 'battle_search';

$context['page_title'] = $txt['battle_expl'];



if(isset($_GET['open'])) {

// This is just here for now to pass the data.

explore_custom();

    } else {

// New battle search. Needed it badly, couldn't tell first attack from monsters or actions.

$rand = mt_rand(1, 2); // Well lets not count out the random

if ($rand == 1) {explore_custom_init();} else {explore_monster_init();}

}

}



function explore_custom_init() {



global  $context, $user_info, $txt, $modSettings, $smcFunc;



//Instead we will put a tag in a var.

$context['isbattle_action'] = true; // Now we know where we are.

$request = $smcFunc['db_query']('', '

SELECT m.id_explore, m.start

FROM {db_prefix}battle_explore AS m

ORDER BY RAND()

LIMIT 1',

array()

);



// Loop through all results

while ($row = $smcFunc['db_fetch_assoc']($request)) {

// And add them to the list

$context['battle_explore'][] = array(

'id_explore' => $row['id_explore'],

'start' => html_entity_decode($row['start']),

);

}

$smcFunc['db_free_result']($request);

}



function explore_monster_init() {



global  $context, $user_info, $txt, $modSettings, $smcFunc;



// First Attack !!!

$this_qfirstatk = mt_rand (0, 3);

if ($this_qfirstatk == 1) {

$this_firstatk = mt_rand (0, 25);

if ($this_firstatk > 0) {

$context['battle']['firstatk'] = $this_firstatk;

$user_info['hp'] = $user_info['hp'] - $this_firstatk;

if($user_info['hp'] < 0) {

$user_info['hp'] = 0;

$context['battle']['firstdead'] = true;

}

updateMemberData($user_info['id'], array('hp' => $user_info['hp']));

}

}

$request = $smcFunc['db_query']('', '

SELECT m.id_monster, m.name, m.atk, m.def, m.hp, m.img, e.id_explore, e.start, m.mon_range, m.mon_max_range

FROM {db_prefix}battle_monsters AS m

INNER JOIN {db_prefix}battle_explore AS e

WHERE hp <> 0

ORDER BY RAND()

LIMIT 1',

array()

);



// Loop through all results

while ($row = $smcFunc['db_fetch_assoc']($request)) {

// And add them to the list

$context['battle_explore'][] = array(

'id_monster' => $row['id_monster'],

'name' => $row['name'],

'mon_range' => $row['mon_range'],

                    'mon_max_range' => $row['mon_max_range'],

'atk' => $row['atk'],

'def' => $row['def'],

'hp' => $row['hp'],

'img' => $row['img']

);

}

$smcFunc['db_free_result']($request);

}


Fog

// Query the database for the targets information.

$request = $smcFunc['db_query']('','

SELECT def, atk, max_hp, hp, name, mon_range, mon_max_range

FROM {db_prefix}battle_monsters

WHERE id_monster = '.$attack_id.'

LIMIT 1'

);

while ($row = $smcFunc['db_fetch_assoc']($request)) {

$context['battle_target'] = array(

'def' => $row['def'],

'mon_range' => $row['mon_range'],

                    'mon_max_range' => $row['mon_max_range'],

'atk' => $row['atk'],

'max_hp' => $row['max_hp'],

'hp' => $row['hp'],

'name' => $row['name'],

);

}



This is what I have currently...as is the code above.

Chen Zhen


Fog,

  Does it still allow you to attack the monster/tank? or does it say tank not in range?

Fog

it's not with those last two codes I posted...

I've been tweaking the code prior to that and user-info.

I changed this code:

// Attack or run away?
$checkTank = array(!empty($row['mon_range']) ? $row['mon_range'] : 1, !empty($row['mon_max_range']) ? $row['mon_max_range'] : 1);
if ($checkTank[0] >= $user_info['level'] && $checkTank[1] <= $user_info['level']) {

echo '

                <br />


to

// Attack or run away?
$checkTank = array(!empty($row['mon_range']) ? $row['mon_range'] : 1, !empty($row['mon_max_range']) ? $row['mon_max_range'] : 2);
if ($checkTank[1] >= $user_info['level'] && $checkTank[2] <= $user_info['level']) {

echo '

                <br />


I was able to attack the Tanks but the level didn't matter.

In your code I couldn't attack period.

Chen Zhen


Fog,

  Both the mysql codes you posted put the data into $context yet the logic you posted was just using $row ... therefore you are not posting the proper mysql query.

this is the line of logic code you posted originally:

if (empty($row['mon_range']) or $row['mon_range'] <= $user_info['level']) {


.. see how it is using the $row array & not $context .. where is the mysql query for that code? 

Chen Zhen


What are you trying to accomplish btw?
Do you want to be able to attack the tanks no matter what?
Do you not want to be able to attack the tanks when your user level is beyond the range?
Do you not want the tanks to attack you if outside the range?
Do you not want the tanks to appear on the map if the user is outside the given range?

I have never played the game.. do the tanks attack you, vice versa or both?