Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Server Modifications ONLY!
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05.07.2007, 16:28   #8
hel
Архивный участник
 
Join Date: Apr 2006
Posts: 729
Default

Guaresnay:
good share. i was thinking about making it.
some technical help for you, if you need it.

1. add "@set_time_limit(0);" in npcdata.php for unlimited execution time.
2. you can make output npcdata in unicode automaticaly, this is an basic example, which a bit slow, but working well:
functions.php:
Code:
function LineAnsiUni($str){
   return preg_replace_callback("/./",create_function('$match','return ($match[0]."\x00");'),$str);
}
npcdata.php:
Code:
...
$file=fopen("npcdata_new.txt", "a"); // i dont think, thats 'a' flag is good there. :) use "w". or for second generation it will not overwrite previously generated file.
fwrite($file,"\xFF\xFE"); // writing unicode header
...
while($row=mysql_fetch_array($link)){
   ...
   if($Active){if(fwrite($file, LineAnsiUni("npc_begin ... npc_end\r\n"))){$done=2;}} // writing lines with extra-bytes for each symbol (it is required).
   ...
}
3. use mysql_result for small queries, which returns 1 row result. for example you can change this:
Code:
$query="SELECT weaponType FROM weapon WHERE item_id = '".$weapon_id."'";
$link=mysql_query($query);
$row=mysql_fetch_array($link);
$type=$row['weaponType'];
to
Code:
$query="SELECT weaponType FROM weapon WHERE item_id = '".$weapon_id."'";
$link=mysql_query($query);
$type=mysql_result($result,0,'weaponType'); // 0 - first row from result, 'weaponType' is a name of a field
4. running sql queries inside cycles, (while, foreach, etc.) is VERY slow the script. in future try to make one big query and try to indexate result to array. for example:
Code:
function get_all_armors_weapons($sql){
   $query="SELECT * FROM weapon";
   $link=mysql_query($query,$sql);
   while($row_items=mysql_fetch_array($link)){
      $weapons_array[($row["item_id"])]=array("name" => $row["name"],"type" => "weapon");
   }
  $query="SELECT * FROM armor";
   $link=mysql_query($query,$sql);
   while($row_items=mysql_fetch_array($link)){
      $armors_array[($row["item_id"])]=array("name" => $row["name"],"type" => "armor");
   }
   return $armors_array+$weapons_array;
}
$id=1;
$wa_items=get_all_armors_weapons($conn);
echo ($wa_items[$id]["name"]." is ".$wa_items[$id]["type"]); // prints "short sword is a weapon".
this way more faster.

sorry if you don't like that i "teach" you how to programming, i just want to help you make your script better, because i'm interested in it, if you want more programming hints - pm me.
hel is offline  
 


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 21:56.