Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[v1.3] Academy of gold coins
#1
I own a script to the gym with gold coins, but there are still some bugs that I am not able to solve. So I'll post the source code of the script so they can use and if possible, someone solve.

SQL Code:
PHP Code:
ALTER TABLE `usersADD `coinsINT11 NOT NULL DEFAULT '0',
ADD `coins_nINT11 NOT NULL DEFAULT '0',
ADD `nextsnobINT11 NOT NULL DEFAULT '0'

Add in action/snob.php:
PHP Code:
if($config['ag_style'] == '2'){
    
$coins_wood 28000;
    
$coins_stone 30000;
    
$coins_iron 25000;
    
$vill $_GET['village'];
    
$tpl->assign("coins_wood"$coins_wood);
    
$tpl->assign("coins_stone"$coins_stone);
    
$tpl->assign("coins_iron"$coins_iron);

    
$all_coins mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id = '".$user['id']."'")) or die (mysql_error());
    
$tpl->assign("allcoins"$all_coins['coins']);
    
$tpl->assign("nextsnob"$all_coins['nextsnob']);
    
$tpl->assign("coins_n"$all_coins['coins_n']);

    
$villages mysql_query("SELECT * FROM villages WHERE userid = '".$user['id']."'");
    while(
$a mysql_fetch_array($villages)){
        
$snob_recruit mysql_num_rows(mysql_query("SELECT * FROM recruit WHERE villageid = '".$a['id']."' AND `unit` = 'unit_snob'"));
        
$num_recruit mysql_fetch_array(mysql_query("SELECT snob_recruit FROM villages WHERE id = '".$a['id']."'"));
        if(
$num_recruit['0'] != $snob_recruit){
            
mysql_query("UPDATE villages SET snob_recruit = '".$snob_recruit."' WHERE id = '".$a['id']."'");
        }
        
$num_recruits += $num_recruit['0'];
        
$units mysql_query("SELECT unit_snob FROM unit_place WHERE villages_from_id = '".$a['id']."'");
        while(
$b mysql_fetch_array($units)){
            
$all_snob += $b['unit_snob'];
        }
    }
    
$tpl->assign("snob_recruit"$num_recruits);
    
$tpl->assign("all_snob"$all_snob);
    
$village_control mysql_fetch_array(mysql_query("SELECT control_villages FROM villages WHERE id = '".$vill."'")) or die (mysql_error());
    
$tpl->assign("village_control"$village_control['0']);

    
$resource mysql_fetch_array(mysql_query("SELECT * FROM villages WHERE id = '".$_GET['village']."'"));
    
$wood_r number_format($resource['r_wood'],0,'','');
    
$stone_r number_format($resource['r_stone'],0,'','');
    
$iron_r number_format($resource['r_iron'],0,'','');

    if(
$_GET['recruit'] == 'snob'){
        if(
$all_coins['nextsnob'] - $all_snob $num_recruits $village_control['0'] < 1){
            
$error 'Insuficienti taleri!'$tpl->assign("error"$error);
        }else{
            
$unit "unit_snob";
            
$count "1";
            
$building "snob";
            
$building_stage "1";
            
$vid $_GET['village'];
            
$wood $cl_units->get_woodprice($unit) * $count;
            
$stone $cl_units->get_stoneprice($unit) * $count;
            
$iron $cl_units->get_ironprice($unit) * $count;
            
$bh $cl_units->get_bhprice($unit) * $count;
             if(
$wood_r $wood OR $stone_r $stone OR $iron_r $iron){
                 
$error 'Insuficiente materiale prime'$tpl->assign("error"$error);
            }else{
                
mysql_query("UPDATE villages SET r_wood = r_wood - '".$wood."' WHERE id = '".$_GET['village']."'") or die (mysql_error());
                
mysql_query("UPDATE villages SET r_stone = r_stone - '".$stone."' WHERE id = '".$_GET['village']."'");
                
mysql_query("UPDATE villages SET r_iron = r_iron - '".$iron."' WHERE id = '".$_GET['village']."'");
                
mysql_query("UPDATE villages SET r_bh = r_bh + '".$bh."' WHERE id = '".$_GET['village']."'");
                
mysql_query("UPDATE villages SET snob_recruit = snob_recruit + '1' WHERE id = '".$_GET['village']."'");
                
$recruit $cl_units->recruit_units($unit$count$building$building_stage$vid);    
                
header("Location: game.php?village=$vid&screen=snob");
             }
        }
    }

    if(
$_GET['create'] == 'coins'){
        if(
$wood_r $coins_wood OR $stone_r $coins_stone OR $iron_r $coins_iron){
            
$error 'Insuficiente materiale prime';
            
$tpl->assign("error"$error);
        }else{
            
mysql_query("UPDATE users SET coins = coins + 1 WHERE id = '".$user['id']."'") or die (mysql_error());
            
mysql_query("UPDATE users SET coins_n = coins_n + 1 WHERE id = '".$user['id']."'") or die (mysql_error());
            
$nextcoins_1 mysql_fetch_array(mysql_query("SELECT nextsnob FROM users WHERE id = '".$user['id']."'")) or die (mysql_error());
            
$nextcoins_2 mysql_fetch_array(mysql_query("SELECT coins_n FROM users WHERE id = '".$user['id']."'")) or die (mysql_error());
            if(
$nextcoins_2['coins_n'] >= $nextcoins_1['nextsnob']){
                
mysql_query("UPDATE users SET nextsnob = nextsnob + 1 WHERE id = '".$user['id']."'") or die (mysql_error());
                
mysql_query("UPDATE users SET coins_n = '0' WHERE id = '".$user['id']."'") or die (mysql_error());
            }
            
mysql_query("UPDATE villages SET r_wood = r_wood - '".$coins_wood."' WHERE id = '".$_GET['village']."'") or die (mysql_error());
            
mysql_query("UPDATE villages SET r_stone = r_stone - '".$coins_stone."' WHERE id = '".$_GET['village']."'");
            
mysql_query("UPDATE villages SET r_iron = r_iron - '".$coins_iron."' WHERE id = '".$_GET['village']."'");
            
header("Location: game.php?village=$vill&screen=snob");
        }
    }


And replace the templates/game_snob.tpl by:
PHP Code:
<table>
    <
tr>
        <
td>
            <
img src="graphic/big_buildings/{$dbname}.png" title="Cazarma" alt="" />
        </
td>
        <
td>
            <
h2>Curte nobila ({$village.$dbname|stage})</h2>
            {
$description}
        </
td>
    </
tr>
</
table>
<
br />
{if 
$show_build}
    {if 
count($recruit_units)>0}
        <
table class="vis">
            <
tr>
                <
th width="150">Instructie</th>
                <
th width="120">Durata</th>
                <
th>Terminare</th>
                <
th width="100">Intrerupere*</th>
            </
tr>

            {foreach 
from=$recruit_units key=key item=value}
                <
tr {if $recruit_units.$key.lit}class="lit"{/if}>
                    <
td>{$recruit_units.$key.num_unit} {$cl_units->get_name($recruit_units.$key.unit)}</td>
                    {if 
$recruit_units.$key.lit && $recruit_units.$key.countdown>-1}
                        <
td><span class="timer">{$recruit_units.$key.countdown|format_time}</span></td>
                    {else}
                           <
td>{$recruit_units.$key.countdown|format_time}</td>
                    {/if}
                    <
td>{$recruit_units.$key.time_finished|format_date}</td>
                    <
td><a href="game.php?t=129107&amp;village={$village.id}&amp;screen={$dbname}&amp;action=cancel&amp;id={$key}&amp;h={$hkey}">intrerupe</a></td>
                </
tr>
            {/foreach}

        </
table>
        <
div style="font-size: 7pt;">* (90din materiile prime iti vor fi inapoiate)</div>
    {/if}

    {if !empty(
$error)}
        <
p><font class="error">{$error}</font></p>
    {/if}
    <
form action="game.php?village={$village.id}&amp;screen={$dbname}&amp;action=train&amp;h={$hkey}method="post" onsubmit="this.submit.disabled=true;">
        <
table class="vis">
            <
tr>
                <
th width="150">Unitate</th>
                <
th colspan="4" width="120">Avea nevoie</th>
                <
th width="130">Durata</th>
                <
th>In sat/Total</th>
                <
th>Recrutare</th>
            </
tr>

            {foreach 
from=$units key=unit_dbname item=name}
                <
tr>
                    <
td><a href="javascript:popup('popup_unit.php?unit={$unit_dbname}', 520, 520)"> <img src="graphic/unit/{$unit_dbname}.png" alt="" /> {$name}</a></td>
                    <
td><img src="graphic/holz.png" title="Holz" alt="" /> {$cl_units->get_woodprice($unit_dbname)}</td>
                    <
td><img src="graphic/lehm.png" title="Lehm" alt="" /> {$cl_units->get_stoneprice($unit_dbname)}</td>
                    <
td><img src="graphic/eisen.png" title="Eisen" alt="" /> {$cl_units->get_ironprice($unit_dbname)}</td>
                    <
td><img src="graphic/face.png" title="Arbeiter" alt="" /> {$cl_units->get_bhprice($unit_dbname)}</td>
                    <
td>{$cl_units->get_time($village.$dbname,$unit_dbname)|format_time}</td>
                    <
td>{$units_in_village.$unit_dbname}/{$units_all.$unit_dbname}</td>

                    {
$cl_units->check_needed($unit_dbname,$village)}
                    {if 
$cl_units->last_error==not_tec}
                        <
td class="inactive">Unitatea nu este inca cercetata</td>
                    {elseif 
$cl_units->last_error==not_needed}
                        <
td class="inactive">Cerintele de construire nu sunt indeplinite</td>
                    {elseif 
$cl_units->last_error==build_ah}
                        <
td class="inactive">Trebuie sa fie intarite.</td>
                    {elseif 
$cl_units->last_error==not_enough_ress}
                        <
td class="inactive">Nu sunt destule materii prime disponibile</td>
                    {elseif 
$cl_units->last_error==not_enough_bh}
                        <
td class="inactive">Prea putine ferme</td>
                    {else}
                        {if 
$ag_style==2}
                        {if  
$nextsnob-$all_snob-$snob_recruit-$village_control '1'
                        <
td class="inactive">Trebuie sa mai bateti taleri!</td>
                        {else}
                        <
td><a href="game.php?village={$village.id}&screen=snob&recruit=snob&h={$hkey}">Generare unitate</a></td>
                        {/if}
                        {else}
                        <
td><a href="game.php?h={$hkey}&amp;action=train_snob&amp;screen=snob&amp;village={$village.id}">Generare unitate</a></td>
                        {/if}
                    {/if}
                </
tr>
            {/foreach}


        </
table>
        <
br />
        {if 
$ag_style==0}
            <
h4>Numarul generatiilor de nobili care pot fi create în acest sat</h4>
            <
table class="vis">
            <
tr><td>Nivelul curtii nobile:</td><td>{$village.snob}</td></tr>
            <
tr><td>- satele cucerite de acest sat</td><td>{$village.control_villages}</td></tr>
            <
tr><td>-nobilimea existenta si cea tocmai creata în acest sat:</td><td>{$village.recruited_snobs}</td></tr>
            <
tr><th>Mai pot fi create:</th><th>{$village.snob-$village.control_villages-$village.recruited_snobs}</th></tr>
            </
table>
        {elseif 
$ag_style==1}
            <
h4>Numarul generatiilor de nobili care mai pot fi create</h4>
            <
table class="vis">
            <
tr><td>Limita GN:</td><td>{$village.snob_info.stage_snobs}</td></tr>
            <
tr><td>- GN existente:</td><td>{$village.snob_info.all_snobs}</td></tr>
            <
tr><td>- GN in producere:</td><td>{$village.snob_info.ags_in_prod}</td></tr>
            <
tr><td>- Numarul satelor cucerite:</td><td>{$village.snob_info.control_villages}</td></tr>
            <
tr><th>Mai pot fi create:</th><th>{$village.snob_info.can_prod}</th></tr>
            </
table>
        {elseif 
$ag_style==2}
        <
h4>Numarul generatiilor de nobili care mai pot fi create</h4>
            <
table class="vis">
            <
tr><td>Limita GN:</td><td>{$nextsnob}</td></tr>
            <
tr><td>- GN existente:</td><td>{$all_snob}</td></tr>
            <
tr><td>- GN in producere:</td><td>{$snob_recruit}</td></tr>
            <
tr><td>- Numarul satelor cucerite:</td><td>{$village_control}</td></tr>
            <
tr><th>Mai pot fi create:</th><th>{$nextsnob-$all_snob-$snob_recruit-$village_control}</th></tr>
            </
table>
        <
h4>Taleri</h4>
            <
table ><tr><td>
<
img src="graphic/gold_big.png" alt="Taleri" />
</
td>
<
td><h4>Taleri</h4>
<
p>
    
Trebuie sa-ti bati taleri pentru a produce mai multe Generatii de NobiliCu cat ai mai multi taleri cu atat mai multe sate poti asupri.
</
p>
</
td></tr></table>

<
br/>

<
table class="vis">
    <
tr>
        <
th colspan="2" width="350">Taleri</th>
    </
tr>
    <
tr>
        <
td>In total:</td><td>{$allcoins}</td>
    </
tr>
    <
tr><td style="background:none;" /></tr>
    <
tr>
        <
th colspan="2">Generatii de nobili</th>
    </
tr>
    <
tr>
        <
td>Limita actuala GN:</td><td>{$nextsnob}</td>
    </
tr>
    <
tr>
        <
td>Pana la limita {$nextsnobGN mai lipsesc:</td>
        <
td class="nowrap">{$nextsnob-$coins_ntaleri</td>
    </
tr>
    <
tr>
        <
td>Pentru limita GN {$nextsnobai economisit deja:</td>
        <
td class="nowrap">{$coins_ntaleri</td>
    </
tr>
</
table>
<
br/>

<
table class="vis">
    <
tr><th>Necesitate</th><th>Bate</th></tr>
    <
tr><td><img src="graphic/holz.png?1" title="Lemn" alt="" class=""/>{$coins_wood|format_number} <img src="graphic/lehm.png?1" title="Argila" alt="" class=""/>{$coins_stone|format_number} <img src="graphic/eisen.png?1" title="Fier" alt="" class=""/>{$coins_iron|format_number} </td><td>
        {if 
$village.r_wood $coins_wood OR $village.r_stone $coins_stone OR $village.r_iron $coins_iron}
        <
span class="inactive">Insuficiente materii prime.</span>
        {else}
        <
a href="game.php?village={$village.id}&screen=snob&create=coins">Bate taleri</a>
        {/if}
        </
td></tr>
</
table>
        {/if}
{/if}

{if 
count($snobed_villages)>&& $ag_style!=2}
    <
br /><br />
    <
table class="vis" width="300">
        <
tr>
            <
th>Sate asuprite de aceasta curte nobila</th>
        </
tr>
        {foreach 
from=$snobed_villages key=id item=villagename}
            <
tr>
                <
td>
                    <
a href="game.php?village={$village.id}&amp;screen=info_village&amp;id={$id}">{$villagename}</a>
                </
td>
            </
tr>
        {/foreach}
    </
table>
{/if} 

Let's GO!
Reply
#2
Well, we did Coins for 1.3, too. There are no bugs and our script is much more then these few lines Big Grin

MfG Manuel
Reply
#3
you could help me finish this script?
Reply
#4
@felipe, stop using others scripts, first, this is in romanian: $error = 'Insuficiente materiale prime'; meaning not enough resources.
Second, visit php.net, there's more information than you can learn. Why not doing it on your own ?

It's just a simple database structure, assuming 1 to N relations, of you can just increment $user['coins'] from db if you don't want a separate table.

Knowing the fact that N noblemen need (N*(N+1))/2 coins, you just need to compare the number of minted gold coins with the result from that equation. If there are more coins, just check the resources and the farm space, and train one noble.

Whats so hard... damn!
Reply
#5
@sinner, thanks
Reply




Users browsing this thread: 1 Guest(s)