Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-01-2007, 09:41 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
object -> XML

Ok, i made this and figured it would be useful for others. It takes any object and converts it to xml.

It uses getStaticVarNames() because any vars in getVarNames() that aren't in getStaticVarNames() don't seem to work (such as clientr and client). I don't know why.

Anyway, the code:

PHP Code:
function generateNode(obj) {

  temp.xml = new TStaticVar();
  temp.xml = "";

  for (vn: obj.getStaticVarNames()) {
    if (obj.(@vn).objecttype() != 0) {
      if (obj.(@vn).size() > 0) {
      temp.xml.add("  <"@vn@">");
        for (i=0;i<=obj.(@vn).size()-1;i++) {
          temp.xml.add("    <index id=\"" @ i @ "\">" @ obj.(@vn)[i] @ "</index>");
  
        }
        temp.xml.add("  </"@vn@">");
      }
      else {
        temp.xml.add("  <"@vn@">");
        temp.tag = vn;
        temp.xml.addarray(generateNode(obj.(@vn)));
        temp.xml.add("  </"@temp.tag@">");
        
      }
    }
    else {
    temp.xml.add("  <"@vn@">"@ obj.(@vn) @"</"@vn@">");
    
    }
  }
  
  
  return temp.xml;
}
function toXML(obj,filename) {
  xml = new TStaticVar();
  xml.add("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
  
xml.add("<"@obj.name@">");
  
xml.addarray(generateNode(obj));
  
xml.add("</"@obj.name@">");
  
xml.savelines(filenamefalse);
  
}
usage:

PHP Code:
toXML(object,filename);
e.g.
toXML(player,player.account ".xml"); 
and sample output for a player object:

PHP Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<JkWhoSaysNi>
  <account>JkWhoSaysNi</account>
  <ani>hoverboardidle</ani>
  <aniparams></aniparams>
  <ap>100</ap>
  <arrows>5</arrows>
  <attached>false</attached>
  <attachid>0</attachid>
  <attachtype>0</attachtype>
  <attr>
    <index id="0"></index>
    <index id="1"></index>
    <index id="2"></index>
    <index id="3"></index>
    <index id="4"></index>
    <index id="5"></index>
    <index id="6"></index>
    <index id="7">-1</index>
    <index id="8">0</index>
    <index id="9">dn_space_name3.gani</index>
    <index id="10">-6.2681853</index>
    <index id="11">0</index>
    <index id="12">0</index>
    <index id="13">0</index>
    <index id="14"></index>
    <index id="15"></index>
    <index id="16"></index>
    <index id="17"></index>
    <index id="18"></index>
    <index id="19"></index>
    <index id="20">1</index>
    <index id="21">1</index>
    <index id="22"></index>
    <index id="23"></index>
    <index id="24"></index>
    <index id="25"></index>
    <index id="26"></index>
    <index id="27"></index>
    <index id="28"></index>
    <index id="29"></index>
    <index id="30"></index>
  </attr>
  <body>body10.png</body>
  <bodyimg>body10.png</bodyimg>
  <bombs>10</bombs>
  <canspin>false</canspin>
  <carriesblackstone>false</carriesblackstone>
  <carriesbush>false</carriesbush>
  <carriesnpc>false</carriesnpc>
  <carriessign>false</carriessign>
  <carriesstone>false</carriesstone>
  <carriesvase>false</carriesvase>
  <chat></chat>
  <colors>
    <index id="0">darkblue</index>
    <index id="1">black</index>
    <index id="2">darkblue</index>
    <index id="3">darkblue</index>
    <index id="4">darkblue</index>
    <index id="5">black</index>
  </colors>
  <computerfirstlogin>0</computerfirstlogin>
  <darts>5</darts>
  <deaths>4</deaths>
  <dir>2</dir>
  <fullhearts>3</fullhearts>
  <glovepower>1</glovepower>
  <graalversion>4.2</graalversion>
  <gralats>0</gralats>
  <guild>scriptering</guild>
  <head>head86.png</head>
  <headimg>head86.png</headimg>
  <headset>-1</headset>
  <hearts>3</hearts>
  <horseimg></horseimg>
  <hp>3</hp>
  <id>6</id>
  <initialized>false</initialized>
  <isfemale>false</isfemale>
  <ismale>true</ismale>
  <ispaused>false</ispaused>
  <joinedclasses></joinedclasses>
  <kills>0</kills>
  <language>English</language>
  <languagedomain>en</languagedomain>
  <lastdead>39935339</lastdead>
  <level>
  <board></board>
  <height>64</height>
  <initialized>false</initialized>
  <isnopkzone>false</isnopkzone>
  <ispaused>false</ispaused>
  <issparringzone>false</issparringzone>
  <joinedclasses></joinedclasses>
  <maxlooplimit>10000</maxlooplimit>
  <name>osl3.nw</name>
  <npcs>
    <index id="0">Knight/Test</index>
  </npcs>
  <players>
    <index id="0">JkWhoSaysNi</index>
  </players>
  <projectiles>
  <initialized>false</initialized>
  <ispaused>false</ispaused>
  <joinedclasses></joinedclasses>
  <maxlooplimit>10000</maxlooplimit>
  <name>projectiles</name>
  <scriptlogmissingfunctions>false</scriptlogmissingfunctions>
  <timeout>0</timeout>
  </projectiles>
  <scriptlogmissingfunctions>false</scriptlogmissingfunctions>
  <tilelayercount>1</tilelayercount>
  <tilelayers>
    <index id="0"></index>
  </tilelayers>
  <tiles>
  <initialized>false</initialized>
  <ispaused>false</ispaused>
  <joinedclasses></joinedclasses>
  <maxlooplimit>10000</maxlooplimit>
  <name>obj</name>
  <scriptlogmissingfunctions>false</scriptlogmissingfunctions>
  <timeout>0</timeout>
  </tiles>
  <timeout>0</timeout>
  <width>64</width>
  </level>
  <logintime>39935339</logintime>
  <maxhp>3</maxhp>
  <maxlooplimit>10000</maxlooplimit>
  <movementlimit>10001</movementlimit>
  <mp>0</mp>
  <name>JkWhoSaysNi</name>
  <nick>Knight (scriptering)</nick>
  <onlinetime>106524</onlinetime>
  <pause>false</pause>
  <paused>false</paused>
  <platform>win</platform>
  <playersindex>0</playersindex>
  <rating>1500</rating>
  <ratingd>350</ratingd>
  <rupees>0</rupees>
  <scriptlogmissingfunctions>false</scriptlogmissingfunctions>
  <shield>no-shield.gif</shield>
  <shieldimg>no-shield.gif</shieldimg>
  <shieldpower>1</shieldpower>
  <sprite>0</sprite>
  <sword>sword1.gif</sword>
  <swordimg>sword1.gif</swordimg>
  <swordpower>1</swordpower>
  <timeout>0</timeout>
  <trial>false</trial>
  <upgradestatus>vip</upgradestatus>
  <version>4.2</version>
  <weapons>
    <index id="0"></index>
    <index id="1">ServerConnect</index>
    <index id="2">-Player System</index>
    <index id="3">*Player/Tailor</index>
    <index id="4">*Staff/Admin Tool</index>
    <index id="5">*Staff/Boots</index>
    <index id="6">*Staff/Tag</index>
    <index id="7">-lavadamage</index>
    <index id="8">Hoverboard</index>
    <index id="9">*Staff/Summon</index>
    <index id="10">*ServerConnect</index>
    <index id="11">-MessageSys</index>
    <index id="12">flamethrower</index>
    <index id="13">wavemaker</index>
    <index id="14">Knight/Test</index>
  </weapons>
  <x>35.5</x>
  <y>21</y>
  <z>0</z>
</JkWhoSaysNi>
I intend to make a XML->Object function too.
__________________

Coming soon (Hopefully:P)
Reply With Quote
 


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 +2. The time now is 03:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.