Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 06-02-2007, 12:25 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Pretty nice!
__________________
Reply With Quote
  #3  
Old 06-02-2007, 01:42 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Looks very good. Don't see any purposes though, if you can't load it.
__________________
Reply With Quote
  #4  
Old 06-02-2007, 04:35 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
I don't even know what the point of XML is, nice work though.
Reply With Quote
  #5  
Old 06-02-2007, 04:04 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
Looks very good. Don't see any purposes though, if you can't load it.
You can load/read xml through loadlines I've heard/seen.

And there is functions for xml released in the engine..
or check out PFA's XML Parser :o
__________________
Reply With Quote
  #6  
Old 06-02-2007, 06:48 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
I suppose you could do this to load + save player atts every 30 minutes or whatever, and then you could look through an accounts file, and then look through the times, and see if they did something. Could be used to check for glitch abuse or so.
__________________
Reply With Quote
  #7  
Old 06-02-2007, 06:52 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
actually I'm using it to back up my DB NPCs, otherwise if they get reset, all the objects created on them are lost.

I'm still working on the XML import, i have it reading the simple data types. I just need to get the recursive part done so it recreates the arrays and objects
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #8  
Old 06-03-2007, 01:05 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by JkWhoSaysNi View Post
actually I'm using it to back up my DB NPCs, otherwise if they get reset, all the objects created on them are lost.

I'm still working on the XML import, i have it reading the simple data types. I just need to get the recursive part done so it recreates the arrays and objects
Still good
Waiting on XML import
__________________
Reply With Quote
  #9  
Old 06-03-2007, 01:09 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
That seems like an awfully large format to use. When you have to write down the name of the variable twice and use index for each member of an array.
__________________
Reply With Quote
  #10  
Old 06-03-2007, 02:13 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Amazing! Rep++
__________________
- Zidane / Zidaya
Reply With Quote
  #11  
Old 06-03-2007, 02:49 AM
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
Quote:
Originally Posted by Inverness View Post
That seems like an awfully large format to use. When you have to write down the name of the variable twice and use index for each member of an array.
but try to store objects recursivley in a format such as INI and you'll have problems.

Of course It is possible using a custom format but XML offers the ability of easily transporting the data and put it somewhere else like a website because there are plenty of parsers available.


As for "index", it could be replaced with CSV so it's just

array = {"a","b","c","d");

is represented as a,b,c,d

but that wouldn't account for objects stored in arrays or multi dimensional arrays.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #12  
Old 06-03-2007, 05:09 AM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
It's a shame this doesn't save flags into it as well =[
__________________
- Zidane / Zidaya
Reply With Quote
  #13  
Old 06-03-2007, 07:46 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
what do you mean by 'flags'? like clientr?
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #14  
Old 06-03-2007, 07:53 PM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
Nooo, I think he means flags like the american flag

just kidding <3
Reply With Quote
  #15  
Old 06-03-2007, 08:13 PM
Deadly_Killer Deadly_Killer is offline
Registered User
Join Date: Feb 2002
Posts: 227
Deadly_Killer is on a distinguished road
Quote:
Originally Posted by JkWhoSaysNi View Post
what do you mean by 'flags'? like clientr?
Yeah, and I just read your first message. You could make another thing to receive data by using

PHP Code:
for (temp.var : getdynamicvarnames())
{
  for (
temp.var2 temp.var.getdynamicvarnames())
  {
    
// format stuff herez
  
}

Just a guess though .
__________________
- Zidane / Zidaya
Reply With Quote
Reply


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 11:26 PM.


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