Jump to content

Help with Attack Script.


Recommended Posts

Basically, I am re-coding my V2 attack script (currently have a 1 click attack system in place) and instead of it listing every attack (sometimes it ends up in the tens of thousands as a HP battle), I want it to list say hit 1-4 and then skip to the last 4?


My attack

Their attack

my attack

their attack


my attack

their attack

my attack

their attack

They won, gaining them XX EXP and $XX,XXX

If you need me to elaborate more then I will try. I am not asking for you to code it, but give me a hint into the right direction.

Link to comment
Share on other sites

Yes Sir. Basically when it comes to a HP battle there can be thousands of "hits" causing players phones etc. to crash.

I understand.

I'm not entirely sure if this will help with optimization, but you could just do the processing that's needed to take the health, and then display random results?

Link to comment
Share on other sites

Assuming you store the outcome of each round into an array (the individual elements need not concern us here), then array_slice() would appear a handy starting point...

$result = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

if (count($result) > 8)
   $first_four = array_slice($result,  0, 4);
   $last_four  = array_slice($result, -4, 4);
   $result     = array_merge($first_four, array('...'), $last_four);

   [0] => 1
   [1] => 2
   [2] => 3
   [3] => 4
   [4] => ...
   [5] => 9
   [6] => 10
   [7] => 11
   [8] => 12

Though as with most PHP, there are multiple solutions. Which you choose, will be dependant on a number of things, I suspect most notably being the number of anticipated rounds. If this becomes too high, then the combat system may have to be reworked to reduce the load on the server.

Link to comment
Share on other sites

something on the lines of....


if($_GET['nextstep'] > 50)
print"<center><h1><font color='red'><span class="highlight">STALEMATE</span>!</h1> <h2>You both get bored and go home!</h2><a href="http://index.php" target="_blank">> Back</a></center>";
$h->endpage();event_add($odata['userid'],"<a href="http://viewuser.php?u=$userid" target="_blank">{$youdata['username']}</a> Tried to Attack you but ended in a stalemate.",$c);
$db->query("UPDATE users SET attacking=0 WHERE userid=$userid AND userid=$odata");


Will set the attack so when the total is 50 you can go no further....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...