Hello everyone
Another "so simple" question...
Im trying to put out from monster xml some new attributes. I need to put out "elements" .
I done new columns in mysql for them (firePercent, icePercent..etc.)
Now, what I want to get
For example : "dragon.xml"
he has elements attribute:
so i go to OTS_Monster.php and doing that:
is a copy of flags - just changed the flag to melement and flags to melements
it should work... but its not..
but.. when i just paste i dragon.xml those elements to "flags" like that:
and I try to get them out to mysql it works...
so...
------------------------------
1. maybe there is a problem with read by php from xml lines called "elements" and "element" ?
this is flags read from OTS_Monster:
this is my elements read from OTS_Monsters:
and code to mysql:
flag code:
my elements code:
and adding to mysql:
as Flag it works, but I want to read from "elements/element" xml lines, not pasting it twice to elements and flags..
ok, i figured it out
Another "so simple" question...
Im trying to put out from monster xml some new attributes. I need to put out "elements" .
I done new columns in mysql for them (firePercent, icePercent..etc.)
Now, what I want to get
For example : "dragon.xml"
he has elements attribute:
XML:
<elements>
<element firePercent="100"/>
<element earthPercent="80"/>
<element energyPercent="20"/>
<element icePercent="-10"/>
</elements>
so i go to OTS_Monster.php and doing that:
PHP:
/**
* Returns all monster flags (in format flagname => value).
*
* @return array Flags.
* @throws DOMException On DOM operation error.
*/
public function getMelements()
{
$melements = array();
// read all melements
foreach( $this->documentElement->getElementsByTagName('elements')->item(0)->getElementsByTagName('element') as $melement)
{
$melement = $melement->attributes->item(0);
$melements[$melement->nodeName] = (int) $melement->nodeValue;
}
return $melements;
}
/**
* Returns specified flag value.
*
* @param string $flag Flag.
* @return int|bool Flag value (false if not set).
* @throws DOMException On DOM operation error.
*/
public function getMelement($melement)
{
// searches for flag
foreach( $this->documentElement->getElementsByTagName('elements')->item(0)->getElementsByTagName('element') as $melement)
{
// found
if( $melement->hasAttribute($melement) )
{
return (int) $melement->getAttribute($melement);
}
}
// not found
return false;
}
it should work... but its not..
but.. when i just paste i dragon.xml those elements to "flags" like that:
XML:
<flags>
<flag summonable="0"/>
<flag attackable="1"/>
<flag hostile="1"/>
<flag illusionable="1"/>
<flag convinceable="0"/>
<flag pushable="0"/>
<flag canpushitems="1"/>
<flag canpushcreatures="1"/>
<flag targetdistance="1"/>
<flag staticattack="90"/>
<flag runonhealth="300"/>
<flag firePercent="100"/> ! those are added
<flag icePercent="-10"/> ! those are added
</flags>
and I try to get them out to mysql it works...
so...
------------------------------
1. maybe there is a problem with read by php from xml lines called "elements" and "element" ?
this is flags read from OTS_Monster:
PHP:
// read all flags
foreach( $this->documentElement->getElementsByTagName('flags')->item(0)->getElementsByTagName('flag') as $flag)
this is my elements read from OTS_Monsters:
PHP:
// read all melements
foreach( $this->documentElement->getElementsByTagName('elements')->item(0)->getElementsByTagName('element') as $melement)
and code to mysql:
flag code:
PHP:
//load monster flags
$flags = $monster->getFlags();
if(!isset($flags['summonable']))
$flags['summonable'] = '0';
if(!isset($flags['convinceable']))
$flags['convinceable'] = '0';
my elements code:
PHP:
$melemets = $monster->getMelements();
if(!isset($melemets['firePercent']))
$melemets['firePercent'] = '0';
if(!isset($melemets['icePercent']))
$melemets['icePercent'] = '0';
and adding to mysql:
PHP:
if(!in_array($name, $names_added)) {
try {
$db->insert(TABLE_PREFIX . 'monsters', array(
'name' => $name,
'mana' => empty($mana) ? 0 : $mana,
'exp' => $monster->getExperience(),
'health' => $health,
'speed_lvl' => $speed_lvl,
'use_haste' => $use_haste,
'voices' => json_encode($monster->getVoices()),
'immunities' => json_encode($monster->getImmunities()),
'summonable' => $flags['summonable'] > 0 ? 1 : 0,
'convinceable' => $flags['convinceable'] > 0 ? 1 : 0,
'firePercent' => $melemets['firePercent'],
'icePercent' => $melemets['icePercent'],
'race' => $race,
'loot' => json_encode($loot)
));
as Flag it works, but I want to read from "elements/element" xml lines, not pasting it twice to elements and flags..
Post automatically merged:
ok, i figured it out
Last edited: