Current location: Hot Scripts Forums » General Web Coding » JavaScript » attack script


attack script

Reply
  #1 (permalink)  
Old 10-12-07, 03:11 PM
mrmaxey mrmaxey is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
someone needs to help me out my attack script of my game dont work it always says network is outta range even if its like 1 network rate difference and the allowed difference rate is 99%. who can spot the error
javascript Code:
  1. <script language="Javascript">
  2. <!--
  3.  
  4. <?php
  5. echo "\nvar font = \"{$font}\";";
  6. echo "\n\nvar reqturns = new Array();";
  7. for ( $i=0; $i<count($a_req_turns); $i++ )
  8.     echo "\nreqturns[{$i}] = {$a_req_turns[$i]};";
  9. echo "\n\nvar abnames = new Array()";
  10. echo "\nabnames[0] = \"Warfare\";";
  11. echo "\nabnames[1] = \"Black Market\";";
  12. echo "\nabnames[2] = \"Pimping\";";
  13. echo "\n\nvar reqabs = new Array();";
  14. for ( $i=0; $i<count($a_req_abs); $i++ ) {
  15.     echo "\nreqabs[{$i}] = new Array();";
  16.     $gia = explode(",", $a_req_abs[$i]);
  17.     for ( $j=0; $j<count($gia); $j++ )
  18.         echo "\nreqabs[{$i}][{$j}] = {$gia[$j]};";
  19. }
  20. echo "\n\nvar persnames = new Array();";
  21. for ( $i=0; $i<count($def_p_unames); $i++ ) {
  22.     echo "\npersnames[{$i}] = new Array();";
  23.     echo "\npersnames[{$i}][0] = \"{$def_p_unames[$i]}\";";
  24. }
  25. for ( $j=0; $j<count($pnames); $j++ )
  26.     echo "\npersnames[".floor($j/3)."][".($j%3+1)."] = \"{$pnames[$j]}\";";
  27.  
  28. echo "\n\nvar reqpers = new Array();";
  29. for ( $i=0; $i<count($a_req_pers); $i++ ) {
  30.     $gia = dexplode(":", ",", $a_req_pers[$i]);
  31.     echo "\nreqpers[{$i}] = new Array();";
  32.     for ( $j=0; $j<count($gia); $j++ ) {
  33.         echo "\nreqpers[{$i}][{$j}] = new Array();";
  34.         for ( $k=0; $k<count($gia[$j]); $k++ )
  35.             echo "\nreqpers[{$i}][{$j}][{$k}] = {$gia[$j][$k]};";
  36.     }
  37. }
  38. ?>
  39.  
  40.  
  41. function updatereqs() {
  42.     var gi = document.getElementById('attacktypezug').value;
  43.     if ( gi >= 0 ) {
  44.         document.getElementById('turnreqzug').value = reqturns[gi];
  45.         var gs = "Abilities: ";
  46.         var first = true;
  47.         for ( var i=0; i<reqabs[gi].length; i++ ) {
  48.             if ( reqabs[gi][i] > 0 ) {
  49.                 if ( !first ) gs += ", ";
  50.                 else first = false ;
  51.                 gs += ""+reqabs[gi][i]+" "+abnames[i];
  52.             }
  53.         }
  54.         if ( first ) gs += "Nothing.";
  55.         document.getElementById('absreqzug').innerHTML = font+""+gs;
  56.         gs = "Personnel: ";
  57.         var first = true;
  58.         for ( var i=0; i<reqpers[gi].length; i++ ) {
  59.             if ( reqpers[gi][i].length > 1 ) { // individual personnel
  60.                 for ( var j=0; j<reqpers[gi][i].length; j++ )
  61.                     if ( reqpers[gi][i][j] > 0 ) {
  62.                         if ( !first ) gs += ", ";
  63.                         else first = false ;
  64.                         gs += ""+reqpers[gi][i][j]+" "+persnames[i][j+1];
  65.                     }
  66.             } else {
  67.                 if ( reqpers[gi][i][0] > 0 ) {
  68.                     if ( !first ) gs += ", ";
  69.                     else first = false ;
  70.                     gs += ""+reqpers[gi][i][0]+" "+persnames[i][0];
  71.                 }
  72.             }
  73.         }
  74.         if ( first ) gs += "Nobody.";
  75.         document.getElementById('persreqzug').innerHTML = font+""+gs;
  76.     } else {
  77.         document.getElementById('turnreqzug').value = 0;
  78.         document.getElementById('absreqzug').innerHTML = font+"Abilities: Nobody.";
  79.         document.getElementById('persreqzug').innerHTML = font+"Personnel: Nobody.";
  80.     }
  81. }
  82.  
  83. function updateattackwho(arg) {
  84.     document.getElementById('attackwhozug').value = document.getElementById('attackwhoselectzug').value;
  85. }
  86.  
  87. -->
  88. </script>
  89.  
  90. <?php
  91. echo "\n<table align=center width=100% bgcolor=#{$bg} rules=none border=0 cellspacing=2>";
  92. echo "\n<tr><td width=50% align=left>{$font}";
  93. echo "\n<p><form action=\"{$PHP_SELF}\" method=\"post\">";
  94. echo "\n<input type=\"hidden\" name=\"func\" value=\"attack\">";
  95. echo "\nTarget: <input type=\"text\" name=\"attackwho\" id=\"attackwhozug\" value=\"{$auto_name}\" size=16>&nbsp ";
  96.  
  97. // get this user's attacks
  98. $gs = outq00("SELECT attacks_out_ids FROM rusers WHERE user_id={$user_id}") . "," . outq00("SELECT attacks_in_ids FROM rusers WHERE user_id={$user_id}");
  99. if ( $gs != "" ) {
  100.     $gia = explode(",", $gs); // get IDs
  101.     $names = array();
  102.     $dnames = array();
  103.     $somelen = 10;
  104.     for ( $k=0; $k<count($gia); $k++ ) { // get names of all users this user has attacked
  105.         if ( $gia[$k] != "" ) {
  106.             $names[$k] = outq00("SELECT name FROM rusers WHERE user_id={$gia[$k]}");
  107.             if ( strlen($names[$k]) > $somelen )
  108.                 $dnames[$k] = substr($names[$k], 0, $somelen)."...";
  109.             else
  110.                 $dnames[$k] = $names[$k];
  111.         } else $names[$k] = "";
  112.     }
  113.     echo "<select id=\"attackwhoselectzug\" onChange=\"javascript:updateattackwho()\">";
  114.     echo "\n<option value=\"\">-</option>";
  115.     for ( $k=0; $k<count($gia); $k++ )
  116.         if ( $names[$k] != "" )
  117.             echo "\n<option value=\"{$names[$k]}\">{$dnames[$k]}</option>";
  118.     echo "\n</select>";
  119. }
  120. echo "\n<br>Attack type: <select id=\"attacktypezug\" name=\"attacktype\" onChange=\"javascript:updatereqs()\">";
  121. echo "\n<option value=\"-1\">--</option>";
  122. for ( $k=0; $k<count($attack_types); $k++ )
  123.     echo "\n<option value=\"{$k}\">{$attack_types[$k]}</option>";
  124. echo "\n</select>";
  125. echo "\n<br>Leave a note: <input type=\"text\" name=\"attacknote\" value=\"\" size=16 maxlength=256>";
  126. echo "\n<br>";
  127. echo "\n&nbsp <input type=\"submit\" value=\"ATTACK\"></form></p>";
  128.  
  129. echo "\n</td><td width=50% align=left valign=top>{$font}";
  130.  
  131. echo "\n<p>Requirements for attack: <input type=\"text\" id=\"turnreqzug\" value=\"0\" size=5> turns";
  132. echo "\n<div id=\"absreqzug\">Abilities: Nothing.</div>";
  133. echo "\n<div id=\"persreqzug\">Personnel: Nobody.</div></p>";
  134.  
  135. echo "\n</td></tr></table>"; // close inner table
  136. echo "\n</td></tr></table>"; // close COMBAT table
  137.  

if someone can find the error in it please help me
__________________
The noob ammong the noobs

Last edited by mrmaxey; 10-12-07 at 03:31 PM. Reason: Merged.
Reply With Quote
  #2 (permalink)  
Old 10-12-07, 06:25 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Your not using php. That's the error
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #3 (permalink)  
Old 10-14-07, 12:26 AM
mrmaxey mrmaxey is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
so if i delete the php tags it must work ??
__________________
The noob ammong the noobs
Reply With Quote
  #4 (permalink)  
Old 10-14-07, 08:34 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by mrmaxey View Post
so if i delete the php tags it must work ??
Of course it must, that's the rule: delete tags that aren't needed and the rest of the code will automagically fix itself and start working, no matter how poorly-written or syntactically incorrect it may be.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #5 (permalink)  
Old 10-14-07, 08:40 PM
mrmaxey mrmaxey is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
well like you peepz said i deleted the php tags still not working :S
helpies
__________________
The noob ammong the noobs
Reply With Quote
  #6 (permalink)  
Old 10-14-07, 09:09 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your mixing PHP and Javascript, you need to re-think it.
Pick one language or the other. Or keep them separate.

Your using Javascript variables in the PHP code.

Your using PHP to echo Javascript thats writing PHP.

And your complicating it even further when you put half the PHP
in the Javascript <script> tag.

You're making it way too complicated.

Keep it simple.

If your going to write large programs you better learn simplicity.

Maybe you were trying to create a CLASS with this code?
If you were, then you need to give it a CLASS identifier and
move it out of the <script> tags.

PHP Code:

<?php
echo "\nvar font = \"{$font}\";";
echo 
"\n\nvar reqturns = new Array();";
for ( 
$i=0$i<count($a_req_turns); $i++ )
    echo 
"\nreqturns[{$i}] = {$a_req_turns[$i]};";
echo 
"\n\nvar abnames = new Array()";
echo 
"\nabnames[0] = \"Warfare\";";
echo 
"\nabnames[1] = \"Black Market\";";
echo 
"\nabnames[2] = \"Pimping\";";
echo 
"\n\nvar reqabs = new Array();";
for ( 
$i=0$i<count($a_req_abs); $i++ ) {
    echo 
"\nreqabs[{$i}] = new Array();";
    
$gia explode(","$a_req_abs[$i]);
    for ( 
$j=0$j<count($gia); $j++ )
        echo 
"\nreqabs[{$i}][{$j}] = {$gia[$j]};";
}
echo 
"\n\nvar persnames = new Array();";
for ( 
$i=0$i<count($def_p_unames); $i++ ) {
    echo 
"\npersnames[{$i}] = new Array();";
    echo 
"\npersnames[{$i}][0] = \"{$def_p_unames[$i]}\";";
}
for ( 
$j=0$j<count($pnames); $j++ )
    echo 
"\npersnames[".floor($j/3)."][".($j&#37;3+1)."] = \"{$pnames[$j]}\";";

echo "\n\nvar reqpers = new Array();";
for ( 
$i=0$i<count($a_req_pers); $i++ ) {
    
$gia dexplode(":"","$a_req_pers[$i]);
    echo 
"\nreqpers[{$i}] = new Array();";
    for ( 
$j=0$j<count($gia); $j++ ) {
        echo 
"\nreqpers[{$i}][{$j}] = new Array();";
        for ( 
$k=0$k<count($gia[$j]); $k++ )
            echo 
"\nreqpers[{$i}][{$j}][{$k}] = {$gia[$j][$k]};";
    }
}
?>
__________________
Jerry Broughton

Last edited by job0107; 10-14-07 at 09:39 PM.
Reply With Quote
  #7 (permalink)  
Old 10-14-07, 09:43 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
And whats with all the "\n"s?
__________________
Jerry Broughton
Reply With Quote
  #8 (permalink)  
Old 10-15-07, 01:21 AM
mrmaxey mrmaxey is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
\n is a definition to a other script imma gonna rewrite it i think cause all your help is great to bad its not helping me if someone van give me a simple attack script or write me one ill be so happy otherwise wish me luck cause im gonna need it .
i realize now i made the game source way to difficult
__________________
The noob ammong the noobs
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gallery script good/bad idea? joshg678 PHP 2 12-22-08 08:41 AM
Looking for a good review management script griz_fan Script Requests 10 07-29-07 05:08 AM
Login Script v1.9 Problem SuavyDoodle JavaScript 8 09-28-06 09:13 PM
Help me with this script !!! phpfreek Job Offers & Assistance 0 04-12-06 05:19 PM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM


All times are GMT -5. The time now is 11:32 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.