[Znote AAC] Simple Spell System

Jetro

jangeldev
Joined
Aug 1, 2011
Messages
452
Best answers
0
Likes
67
Location
Venezuela
#1
Hi all, this is a simple spell system, it gets the info from spells.xml this is how it looks:



go to config.php

after this:
PHP:
	$config['vocations'] = array(
		0 => 'No vocation',
		1 => 'Sorcerer',
		2 => 'Druid',
		3 => 'Paladin',
		4 => 'Knight',
		5 => 'Master Sorcerer',
		6 => 'Elder Druid',
		7 => 'Royal Paladin',
		8 => 'Elite Knight',
	);
put this:
PHP:
$config['voc_str'] = array(
		'5' => 'Master Sorcerers',
		'6' => 'Elder Druids',
		'7' => 'Royal Paladins',
		'8' => 'Elite Knights',
		'1;5' => 'Sorcerers',
		'2;6' => 'Druids',
		'3;7' => 'Paladins',
		'4;8' => 'Knights',
	);
now go to engine/function/general.php
after this:
PHP:
function vocation_id_to_name($id) {
	$vocations = config('vocations');
	return ($vocations[$id] >= 0 ) ? $vocations[$id] :false ;
}
put this:
PHP:
function voc_str($id)
{	
	$vocs = config('voc_str');
	$id = strVal($id);
	
	return ($vocs[$id] >= 0 ) ? $vocs[$id] :false ;
}

function array_concat($array, $val)
{
	$ret = "";
    $size = count($array) - 1;
	for ($i = 0; $i <= $size; $i++) 
	{	
	
		$ret .= voc_str($array[$i]).''.($i < $size ? $val : '.');
		
	}
	
	
	return $ret;
}
now create a new php file called spells.php and paste this:
PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?> 


<?php 
echo '<h1>Instant Spells</h1> ';
$path = 'D:\Ocio & Programación\Server Tibia\SRCS\SERV\SRCS'; //HERE YOU MUST SET WHERE IS LOCATED YOUR DATA FOLDER
if (is_dir($path)) { 

   
	$xml1 = simplexml_load_file($path."\data\spells\spells.xml"); 
echo '<TABLE BORDER> <TR class="yellow"> <TD >Name</TD> <TD>Words</TD> <TD>Level</TD> <TD>Mana</TD> <TD>Soul</TD> <TD>Requires Premium?</TD> <TD>Vocations</TD></TR> ';
foreach($xml1->instant as $spell) 
{
	$soul = ($spell['soul'] ? $spell['soul'] : 0);
	$vocs = array();
	if($spell->vocation)
    {    foreach($spell->vocation as $voc)
		{
			
            array_push($vocs, $voc['id']);	
		}		
		$vocs = array_concat($vocs, ', ');
		
	}
	else
		$vocs = "All";
		
	$prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
	
	echo '<TR class="special"> <TD>'.$spell['name'].'</TD> <TD>'.$spell['words'].'</TD> <TD>'.$spell['lvl'].'<TD>'.$spell['mana'].'</TD> <TD> '.$soul.'</TD> <TD>'.$prem.' </TD> <TD>'.$vocs.'</TR></TR>';
	
}
echo'</TABLE>';


echo'<h1>Conjure Spells</h1> ';
echo '<TABLE BORDER> <TR class="yellow"> <TD >Name</TD> <TD>Words</TD> <TD>Level</TD> <TD>Mana</TD> <TD>Soul</TD> <TD>Requires Premium?</TD> <TD>Vocations</TD></TR> ';
foreach($xml1->conjure as $spell) 
{
	$soul = ($spell['soul'] ? $spell['soul'] : 0);
	
	$vocs = array();
	if($spell->vocation)
    {    foreach($spell->vocation as $voc)
		{
            array_push($vocs, $voc['id']);	
		}		
		$vocs = array_concat($vocs, ', ');
	}
	else
		$vocs = "All";
		
	$prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
		
	echo '<TR class="special"> <TD>'.$spell['name'].'</TD> <TD>'.$spell['words'].'</TD> <TD>'.$spell['lvl'].'<TD>'.$spell['mana'].'</TD> <TD> '.$soul.'</TD> <TD>'.$prem.' </TD> <TD>'.$vocs.'</TR> </TR>';
	
}
echo'</TABLE>';

}
else
{
	echo '<br><b>Invalid path!</b>'; 
     
} 
?> 
<?php include 'layout/overall/footer.php'; ?>
and you are done :)
remember, you need set the location of your data folder at $data
Regards
 
Joined
Nov 8, 2007
Messages
78
Best answers
0
Likes
10
#5
Nice, however on at least tibiawar layout for 1.2 version of accmaker it does strangely print vocations:

Flame Strike exori flam 14 20 0 YES , , Master Sorcerers, Elder Druids.
Strong Flame Strike exori gran flam 70 60 0 YES , Master Sorcerers.
 
Joined
Jul 7, 2008
Messages
34
Best answers
0
Likes
1
#6
Great script, but I'm getting a bug with the vocation listing: it just shows commas and periods, no name whatsoever. Any idea why?
 
Joined
Jul 7, 2008
Messages
34
Best answers
0
Likes
1
#8
Nope, just the 9 default vocations. I changed some stuff (attkspeed, managain, that kind of stuff), but I didn't add, delete or mess up with the ids.

I'm using TFS 2.14, in case that's any help.
 

Jetro

jangeldev
Joined
Aug 1, 2011
Messages
452
Best answers
0
Likes
67
Location
Venezuela
#11
ok, replace spells.php for this
PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?> 


<?php 
echo '<h1>Instant Spells</h1> ';
$path = 'D:\Ocio & Programación\Server Tibia\SRCS\SERV\SRCS'; 
if (is_dir($path)) { 

   
	$xml1 = simplexml_load_file($path."\data\spells\spells.xml"); 
echo '<TABLE BORDER> <TR class="yellow"> <TD >Name</TD> <TD>Words</TD> <TD>Level</TD> <TD>Mana</TD> <TD>Soul</TD> <TD>Requires Premium?</TD> <TD>Vocations</TD></TR> ';
foreach($xml1->instant as $spell) 
{
	$soul = ($spell['soul'] ? $spell['soul'] : 0);
	$vocs = array();
	if($spell->vocation)
    {    foreach($spell->vocation as $voc)
		{
			
            array_push($vocs, $voc['name']);	
		}		
		$vocs = array_concat($vocs, ', ');
		
	}
	else
		$vocs = "All";
		
	$prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
	
	echo '<TR class="special"> <TD>'.$spell['name'].'</TD> <TD>'.$spell['words'].'</TD> <TD>'.$spell['lvl'].'<TD>'.$spell['mana'].'</TD> <TD> '.$soul.'</TD> <TD>'.$prem.' </TD> <TD>'.$vocs.'</TR></TR>';
	
}
echo'</TABLE>';


echo'<h1>Conjure Spells</h1> ';
echo '<TABLE BORDER> <TR class="yellow"> <TD >Name</TD> <TD>Words</TD> <TD>Level</TD> <TD>Mana</TD> <TD>Soul</TD> <TD>Requires Premium?</TD> <TD>Vocations</TD></TR> ';
foreach($xml1->conjure as $spell) 
{
	$soul = ($spell['soul'] ? $spell['soul'] : 0);
	
	$vocs = array();
	if($spell->vocation)
    {    foreach($spell->vocation as $voc)
		{
            array_push($vocs, $voc['id']);	
		}		
		$vocs = array_concat($vocs, ', ');
	}
	else
		$vocs = "All";
		
	$prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
		
	echo '<TR class="special"> <TD>'.$spell['name'].'</TD> <TD>'.$spell['words'].'</TD> <TD>'.$spell['lvl'].'<TD>'.$spell['mana'].'</TD> <TD> '.$soul.'</TD> <TD>'.$prem.' </TD> <TD>'.$vocs.'</TR> </TR>';
	
}
echo'</TABLE>';

}
else
{
	echo '<br><b>Invalid path!</b>'; 
     
} 
?> 
<?php include 'layout/overall/footer.php'; ?>
and in engine/function/general.php
find the line:
PHP:
$ret .= voc_str($array[$i]).''.($i < $size ? $val : '.');
replace it for this:

PHP:
$ret .= $array[$i].''.($i < $size ? $val : '.');
 
Joined
Jul 7, 2008
Messages
34
Best answers
0
Likes
1
#12
Thanks a lot! That fixed it! ^^ Great script. Hope some day you add sorting functionality and voc filtering xD

Rep++ ^^
 

Jetro

jangeldev
Joined
Aug 1, 2011
Messages
452
Best answers
0
Likes
67
Location
Venezuela
#13
148 views and no comments


- - - Updated - - -

whatever, here is a new version, please update my first post :)
now it can be sorted by vocation


spells.php
PHP:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?> 
<div class="inner">
		<form action="spells.php#" method="post">
			<select name="selected">
			<option value="0">All</option>
			<option value="1">Sorcerers</option>
			<option value="2">Druids</option>
			<option value="3">Paladins</option>
			<option value="4">Knights</option>
			</select>
			<input type="submit" value="Sort by Vocation">
		</form>
	</div>

<?php 
echo '<h1>Instant Spells</h1> ';
$path = 'D:\Ocio & Programación\Server Tibia\SRCS\SERV\SRCS'; 
if (is_dir($path)) { 
	if ($config['log_ip']) 
	{
		znote_visitor_insert_detailed_data(3);
	}

	
	
	$val = $_POST['selected'];
	$xml1 = simplexml_load_file($path."\data\spells\spells.xml"); 
	echo '<TABLE BORDER> <TR class="yellow"> <TD >Name</TD> <TD>Words</TD> <TD>Level</TD> <TD>Mana</TD> <TD>Soul</TD> <TD>Requires Premium?</TD> <TD>Vocations</TD></TR> ';
	foreach($xml1->instant as $spell) 
	{
		
		
		$soul = ($spell['soul'] ? $spell['soul'] : 0);
		$vocs = array();
		if($spell->vocation)
		{   
			
			foreach($spell->vocation as $voc)
			{
			
				if ($val != 0)
				{
					if ($val == 1 && ($voc['id'] == '1;5' || $voc['id'] == '5')) 
						array_push($vocs, $voc['id']);
					elseif ($val == 2 && ($voc['id'] == '2;6' || $voc['id'] == '6')) 
						array_push($vocs, $voc['id']);
					elseif ($val == 3 && ($voc['id'] == '3;7' || $voc['id'] == '7')) 
						array_push($vocs, $voc['id']);
					elseif ($val == 4 && ($voc['id'] == '4;8' || $voc['id'] == '8')) 
						array_push($vocs, $voc['id']);
					
				}
				else
					array_push($vocs, $voc['id']);
					
			}	
			
			
			$vocs = array_concat($vocs, ', ');
			
			
			if (strlen($vocs) == 0)
				continue;
				
		}
		else
			$vocs = "All";
		
		$prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
	
		echo '<TR class="special"> <TD>'.$spell['name'].'</TD> <TD>'.$spell['words'].'</TD> <TD>'.$spell['lvl'].'<TD>'.$spell['mana'].'</TD> <TD> '.$soul.'</TD> <TD>'.$prem.' </TD> <TD>'.$vocs.'</TR></TR>';
	
	}
	echo'</TABLE>';


	echo'<h1>Conjure Spells</h1> ';
	echo '<TABLE BORDER> <TR class="yellow"> <TD >Name</TD> <TD>Words</TD> <TD>Level</TD> <TD>Mana</TD> <TD>Soul</TD> <TD>Requires Premium?</TD> <TD>Vocations</TD></TR> ';
	foreach($xml1->conjure as $spell) 
	{
		$soul = ($spell['soul'] ? $spell['soul'] : 0);
		$vocs = array();
	if($spell->vocation)
    {    foreach($spell->vocation as $voc)
		{
            if ($val != 0)
				{
					if ($val == 1 && ($voc['id'] == '1;5' || $voc['id'] == '5')) 
						array_push($vocs, $voc['id']);
					elseif ($val == 2 && ($voc['id'] == '2;6' || $voc['id'] == '6')) 
						array_push($vocs, $voc['id']);
					elseif ($val == 3 && ($voc['id'] == '3;7' || $voc['id'] == '7')) 
						array_push($vocs, $voc['id']);
					elseif ($val == 4 && ($voc['id'] == '4;8' || $voc['id'] == '8')) 
						array_push($vocs, $voc['id']);
					
				}
				else
					array_push($vocs, $voc['id']);
		}		
		$vocs = array_concat($vocs, ', ');
		if (strlen($vocs) == 0)
				continue;
	}
	else
		$vocs = "All";
		$prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
		
	echo '<TR class="special"> <TD>'.$spell['name'].'</TD> <TD>'.$spell['words'].'</TD> <TD>'.$spell['lvl'].'<TD>'.$spell['mana'].'</TD> <TD> '.$soul.'</TD> <TD>'.$prem.' </TD> <TD>'.$vocs.'</TR> </TR>';
	
	}
	echo'</TABLE>';

}
else
{
	echo '<br><b>Invalid path!</b>'; 
     
} 
?> 

<?php include 'layout/overall/footer.php'; ?>
in engine/function/general.php
the function array_concat must be replaced for this:
PHP:
function array_concat($array, $val)
{
	$ret = "";
    $size = count($array) - 1;
	if ($size < 0) 
		return false;
		
	for ($i = 0; $i <= $size; $i++) 
	{	
		$ret .= voc_str($array[$i]).''.($i < $size ? $val : '.');
		
	}
	
	
	return $ret;
}
 
Joined
Oct 5, 2011
Messages
90
Best answers
0
Likes
0
#14
It doesn't work for me...
The borders gets created and all but the spells doesn't just show up!
Using this as server path..

C:\Users\blabla\Desktop\otserv\data
 
Top