• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Znote AAC] Simple Spell System

Jetro

jangeldev
Joined
Aug 1, 2011
Messages
452
Reaction score
68
Location
Venezuela
Hi all, this is a simple spell system, it gets the info from spells.xml this is how it looks:

DUGT74M.png


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
 
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.
 
Great script, but I'm getting a bug with the vocation listing: it just shows commas and periods, no name whatsoever. Any idea why?
 
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.
 
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 : '.');
 
Thanks a lot! That fixed it! ^^ Great script. Hope some day you add sorting functionality and voc filtering xD

Rep++ ^^
 
148 views and no comments
1229277.jpg


- - - Updated - - -

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


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;
}
 
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
 
Back
Top