[Znote AAC] Simple Spell System

Discussion in 'Website Applications' started by Jetro, Sep 19, 2012.

  1. Jetro

    Jetro jangeldev

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

    [​IMG]

    go to config.php

    after this:
    PHP:
    1.     $config['vocations'] = array(
    2.         0 => 'No vocation',
    3.         1 => 'Sorcerer',
    4.         2 => 'Druid',
    5.         3 => 'Paladin',
    6.         4 => 'Knight',
    7.         5 => 'Master Sorcerer',
    8.         6 => 'Elder Druid',
    9.         7 => 'Royal Paladin',
    10.         8 => 'Elite Knight',
    11.     );
    put this:
    PHP:
    1. $config['voc_str'] = array(
    2.         '5' => 'Master Sorcerers',
    3.         '6' => 'Elder Druids',
    4.         '7' => 'Royal Paladins',
    5.         '8' => 'Elite Knights',
    6.         '1;5' => 'Sorcerers',
    7.         '2;6' => 'Druids',
    8.         '3;7' => 'Paladins',
    9.         '4;8' => 'Knights',
    10.     );
    now go to engine/function/general.php
    after this:
    PHP:
    1. function vocation_id_to_name($id) {
    2.     $vocations = config('vocations');
    3.     return ($vocations[$id] >= 0 ) ? $vocations[$id] :false ;
    4. }
    put this:
    PHP:
    1. function voc_str($id)
    2. {  
    3.     $vocs = config('voc_str');
    4.     $id = strVal($id);
    5.    
    6.     return ($vocs[$id] >= 0 ) ? $vocs[$id] :false ;
    7. }
    8.  
    9. function array_concat($array, $val)
    10. {
    11.     $ret = "";
    12.     $size = count($array) - 1;
    13.     for ($i = 0; $i <= $size; $i++)
    14.     {  
    15.    
    16.         $ret .= voc_str($array[$i]).''.($i < $size ? $val : '.');
    17.        
    18.     }
    19.    
    20.    
    21.     return $ret;
    22. }
    now create a new php file called spells.php and paste this:
    PHP:
    1. <?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?>
    2.  
    3.  
    4. <?php
    5. echo '<h1>Instant Spells</h1> ';
    6. $path = 'D:\Ocio & Programación\Server Tibia\SRCS\SERV\SRCS'; //HERE YOU MUST SET WHERE IS LOCATED YOUR DATA FOLDER
    7. if (is_dir($path)) {
    8.  
    9.    
    10.     $xml1 = simplexml_load_file($path."\data\spells\spells.xml");
    11. 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> ';
    12. foreach($xml1->instant as $spell)
    13. {
    14.     $soul = ($spell['soul'] ? $spell['soul'] : 0);
    15.     $vocs = array();
    16.     if($spell->vocation)
    17.     {    foreach($spell->vocation as $voc)
    18.         {
    19.            
    20.             array_push($vocs, $voc['id']); 
    21.         }      
    22.         $vocs = array_concat($vocs, ', ');
    23.        
    24.     }
    25.     else
    26.         $vocs = "All";
    27.        
    28.     $prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
    29.    
    30.     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>';
    31.    
    32. }
    33. echo'</TABLE>';
    34.  
    35.  
    36. echo'<h1>Conjure Spells</h1> ';
    37. 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> ';
    38. foreach($xml1->conjure as $spell)
    39. {
    40.     $soul = ($spell['soul'] ? $spell['soul'] : 0);
    41.    
    42.     $vocs = array();
    43.     if($spell->vocation)
    44.     {    foreach($spell->vocation as $voc)
    45.         {
    46.             array_push($vocs, $voc['id']); 
    47.         }      
    48.         $vocs = array_concat($vocs, ', ');
    49.     }
    50.     else
    51.         $vocs = "All";
    52.        
    53.     $prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
    54.        
    55.     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>';
    56.    
    57. }
    58. echo'</TABLE>';
    59.  
    60. }
    61. else
    62. {
    63.     echo '<br><b>Invalid path!</b>';
    64.      
    65. }
    66. ?>
    67. <?php include 'layout/overall/footer.php'; ?>
    and you are done :)
    remember, you need set the location of your data folder at $data
    Regards
     
    nemec likes this.
  2. cbrm

    cbrm Just another mod Staff Member Global Moderator

    Joined:
    Jan 6, 2009
    Messages:
    6,549
    Likes Received:
    852
    Best Answers:
    0
    approved
     
  3. Jetro

    Jetro jangeldev

    Joined:
    Aug 1, 2011
    Messages:
    452
    Likes Received:
    67
    Best Answers:
    0
    thanks cbrm
     
  4. Dalt0n

    Dalt0n Hiho:)

    Joined:
    Dec 14, 2011
    Messages:
    536
    Likes Received:
    29
    Best Answers:
    0
    Excelent Jetro, Thanks, i like it ;D
     
  5. Gall

    Gall Member

    Joined:
    Nov 8, 2007
    Messages:
    78
    Likes Received:
    10
    Best Answers:
    0
    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.
     
  6. Launian

    Launian Tsuki~

    Joined:
    Jul 7, 2008
    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Great script, but I'm getting a bug with the vocation listing: it just shows commas and periods, no name whatsoever. Any idea why?
     
  7. Jetro

    Jetro jangeldev

    Joined:
    Aug 1, 2011
    Messages:
    452
    Likes Received:
    67
    Best Answers:
    0
    do u have extra vocations? i mean more than 8
     
  8. Launian

    Launian Tsuki~

    Joined:
    Jul 7, 2008
    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    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.
     
  9. Jetro

    Jetro jangeldev

    Joined:
    Aug 1, 2011
    Messages:
    452
    Likes Received:
    67
    Best Answers:
    0
    show ur spells.xml
     
  10. Launian

    Launian Tsuki~

    Joined:
    Jul 7, 2008
    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
  11. Jetro

    Jetro jangeldev

    Joined:
    Aug 1, 2011
    Messages:
    452
    Likes Received:
    67
    Best Answers:
    0
    ok, replace spells.php for this
    PHP:
    1. <?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?>
    2.  
    3.  
    4. <?php
    5. echo '<h1>Instant Spells</h1> ';
    6. $path = 'D:\Ocio & Programación\Server Tibia\SRCS\SERV\SRCS';
    7. if (is_dir($path)) {
    8.  
    9.    
    10.     $xml1 = simplexml_load_file($path."\data\spells\spells.xml");
    11. 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> ';
    12. foreach($xml1->instant as $spell)
    13. {
    14.     $soul = ($spell['soul'] ? $spell['soul'] : 0);
    15.     $vocs = array();
    16.     if($spell->vocation)
    17.     {    foreach($spell->vocation as $voc)
    18.         {
    19.            
    20.             array_push($vocs, $voc['name']);   
    21.         }      
    22.         $vocs = array_concat($vocs, ', ');
    23.        
    24.     }
    25.     else
    26.         $vocs = "All";
    27.        
    28.     $prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
    29.    
    30.     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>';
    31.    
    32. }
    33. echo'</TABLE>';
    34.  
    35.  
    36. echo'<h1>Conjure Spells</h1> ';
    37. 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> ';
    38. foreach($xml1->conjure as $spell)
    39. {
    40.     $soul = ($spell['soul'] ? $spell['soul'] : 0);
    41.    
    42.     $vocs = array();
    43.     if($spell->vocation)
    44.     {    foreach($spell->vocation as $voc)
    45.         {
    46.             array_push($vocs, $voc['id']); 
    47.         }      
    48.         $vocs = array_concat($vocs, ', ');
    49.     }
    50.     else
    51.         $vocs = "All";
    52.        
    53.     $prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
    54.        
    55.     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>';
    56.    
    57. }
    58. echo'</TABLE>';
    59.  
    60. }
    61. else
    62. {
    63.     echo '<br><b>Invalid path!</b>';
    64.      
    65. }
    66. ?>
    67. <?php include 'layout/overall/footer.php'; ?>
    and in engine/function/general.php
    find the line:
    PHP:
    1. $ret .= voc_str($array[$i]).''.($i < $size ? $val : '.');
    replace it for this:

    PHP:
    1. $ret .= $array[$i].''.($i < $size ? $val : '.');
     
    Launian likes this.
  12. Launian

    Launian Tsuki~

    Joined:
    Jul 7, 2008
    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Thanks a lot! That fixed it! ^^ Great script. Hope some day you add sorting functionality and voc filtering xD

    Rep++ ^^
     
  13. Jetro

    Jetro jangeldev

    Joined:
    Aug 1, 2011
    Messages:
    452
    Likes Received:
    67
    Best Answers:
    0
    148 views and no comments
    [​IMG]

    - - - Updated - - -

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

    spells.php
    PHP:
    1. <?php require_once 'engine/init.php'; include 'layout/overall/header.php'; ?>
    2. <div class="inner">
    3.         <form action="spells.php#" method="post">
    4.             <select name="selected">
    5.             <option value="0">All</option>
    6.             <option value="1">Sorcerers</option>
    7.             <option value="2">Druids</option>
    8.             <option value="3">Paladins</option>
    9.             <option value="4">Knights</option>
    10.             </select>
    11.             <input type="submit" value="Sort by Vocation">
    12.         </form>
    13.     </div>
    14.  
    15. <?php
    16. echo '<h1>Instant Spells</h1> ';
    17. $path = 'D:\Ocio & Programación\Server Tibia\SRCS\SERV\SRCS';
    18. if (is_dir($path)) {
    19.     if ($config['log_ip'])
    20.     {
    21.         znote_visitor_insert_detailed_data(3);
    22.     }
    23.  
    24.    
    25.    
    26.     $val = $_POST['selected'];
    27.     $xml1 = simplexml_load_file($path."\data\spells\spells.xml");
    28.     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> ';
    29.     foreach($xml1->instant as $spell)
    30.     {
    31.        
    32.        
    33.         $soul = ($spell['soul'] ? $spell['soul'] : 0);
    34.         $vocs = array();
    35.         if($spell->vocation)
    36.         {  
    37.            
    38.             foreach($spell->vocation as $voc)
    39.             {
    40.            
    41.                 if ($val != 0)
    42.                 {
    43.                     if ($val == 1 && ($voc['id'] == '1;5' || $voc['id'] == '5'))
    44.                         array_push($vocs, $voc['id']);
    45.                     elseif ($val == 2 && ($voc['id'] == '2;6' || $voc['id'] == '6'))
    46.                         array_push($vocs, $voc['id']);
    47.                     elseif ($val == 3 && ($voc['id'] == '3;7' || $voc['id'] == '7'))
    48.                         array_push($vocs, $voc['id']);
    49.                     elseif ($val == 4 && ($voc['id'] == '4;8' || $voc['id'] == '8'))
    50.                         array_push($vocs, $voc['id']);
    51.                    
    52.                 }
    53.                 else
    54.                     array_push($vocs, $voc['id']);
    55.                    
    56.             }  
    57.            
    58.            
    59.             $vocs = array_concat($vocs, ', ');
    60.            
    61.            
    62.             if (strlen($vocs) == 0)
    63.                 continue;
    64.                
    65.         }
    66.         else
    67.             $vocs = "All";
    68.        
    69.         $prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
    70.    
    71.         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>';
    72.    
    73.     }
    74.     echo'</TABLE>';
    75.  
    76.  
    77.     echo'<h1>Conjure Spells</h1> ';
    78.     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> ';
    79.     foreach($xml1->conjure as $spell)
    80.     {
    81.         $soul = ($spell['soul'] ? $spell['soul'] : 0);
    82.         $vocs = array();
    83.     if($spell->vocation)
    84.     {    foreach($spell->vocation as $voc)
    85.         {
    86.             if ($val != 0)
    87.                 {
    88.                     if ($val == 1 && ($voc['id'] == '1;5' || $voc['id'] == '5'))
    89.                         array_push($vocs, $voc['id']);
    90.                     elseif ($val == 2 && ($voc['id'] == '2;6' || $voc['id'] == '6'))
    91.                         array_push($vocs, $voc['id']);
    92.                     elseif ($val == 3 && ($voc['id'] == '3;7' || $voc['id'] == '7'))
    93.                         array_push($vocs, $voc['id']);
    94.                     elseif ($val == 4 && ($voc['id'] == '4;8' || $voc['id'] == '8'))
    95.                         array_push($vocs, $voc['id']);
    96.                    
    97.                 }
    98.                 else
    99.                     array_push($vocs, $voc['id']);
    100.         }      
    101.         $vocs = array_concat($vocs, ', ');
    102.         if (strlen($vocs) == 0)
    103.                 continue;
    104.     }
    105.     else
    106.         $vocs = "All";
    107.         $prem = ($spell['prem'] == 1) ?  "<font color=green><strong>YES</strong></font>" : "<font color=red><strong>NO</strong></font>";
    108.        
    109.     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>';
    110.    
    111.     }
    112.     echo'</TABLE>';
    113.  
    114. }
    115. else
    116. {
    117.     echo '<br><b>Invalid path!</b>';
    118.      
    119. }
    120. ?>
    121.  
    122. <?php include 'layout/overall/footer.php'; ?>
    in engine/function/general.php
    the function array_concat must be replaced for this:
    PHP:
    1. function array_concat($array, $val)
    2. {
    3.     $ret = "";
    4.     $size = count($array) - 1;
    5.     if ($size < 0)
    6.         return false;
    7.        
    8.     for ($i = 0; $i <= $size; $i++)
    9.     {  
    10.         $ret .= voc_str($array[$i]).''.($i < $size ? $val : '.');
    11.        
    12.     }
    13.    
    14.    
    15.     return $ret;
    16. }
     
  14. Clorens

    Clorens Member

    Joined:
    Oct 5, 2011
    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    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
     
  15. soba

    soba I ♥ Deep House .

    Joined:
    May 10, 2009
    Messages:
    183
    Likes Received:
    5
    Best Answers:
    0
  16. Blysco

    Blysco Member

    Joined:
    Oct 12, 2013
    Messages:
    163
    Likes Received:
    2
    Best Answers:
    0
    It dont create a border..
     
  17. psychosisneamia

    psychosisneamia ~Beginner~

    Joined:
    Jun 7, 2012
    Messages:
    162
    Likes Received:
    7
    Best Answers:
    0
    Did anyone find a fix for the spells? The border is made but no spells appear. Any answers?
     

Share This Page

Loading...