vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.8 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=235)
-   -   Major Additions - Realm Conquest System (https://vborg.vbsupport.ru/showthread.php?t=211920)

blissend 06-29-2009 10:40 PM

For those interested in adding a trade system, here is my really sloppy attempt and how you can do it. Hopefully the author will consider adding it and that I'm not out of line for posting this 8)

Notes...
  • You can send troops or gold. Simply click the user as if you were to do a raid/spy run. You should see the trade area above the raid/spy run area. You can trade with anyone thus can have traitors :D
  • It will tax you depending on your size (smaller = no tax, bigger than 2x caps to 76% tax and will only let you send 2x their size in amount). You will see a notice like raid/spy runs show but it won't be seen in history (requires more than adding code to do that me thinks). I also made it cost 5 turns to send gold and 1 to send troops... to lazy to make that editable but its easy enough to change in the code.
  • I leave it to you to figure out how to add this to your code. Not sure if I'm allowed to post my version. Files to edit are function_conquest_village.php, conquest.php and a template modification.
add these functions to function_conquest_village.php
PHP Code:

function run_sendtroops($player$village)
{
    global 
$vbulletin$settings$passcolor$failcolor;
    
    if (
$player[pTurns] < 1)
    {
        return 
'<font color="'.$failcolor.'">You can not trade as you do not have enough turns available.</font>';
    }
    
    
$troops $vbulletin->input->clean_gpc('p'"troopamount"TYPE_UINT);
    
    if (!
is_numeric($troops) && !is_int($troops))
    {
        return 
'<font color="'.$failcolor.'">Please enter an appropriate value.</font>';
    }
    elseif (
$player[pTroops] == 0)
    {
        return 
'<font color="'.$failcolor.'">You can not send troops because you don\'t have any!</font>';
    }
    elseif (
$troops >= $player[pTroops])
    {
        return 
'<font color="'.$failcolor.'">You can not send all of your troops or more than what you have!</font>';
    }

    if (
$player[pTroops] >= ($village[pTroops]*2)) $sendtax .77;
    elseif (
$player[pTroops] >= ($village[pTroops]+1)) $sendtax pow(0.75, (($player[pTroops]/$village[pTroops])*2.5));
    else 
$sendtax 0;
    
    if (
$player[pTroops] > ($village[pTroops]*2) && ($troops > ($village[pTroops]*2)))
    {
        
$troops $village[pTroops]*2;
        
$transferTotal $troops - ($troops $sendtax);
    }
    else 
$transferTotal $troops - ($troops $sendtax);
    
$transferTotal ceil($transferTotal);
    
$troopsLost ceil($troops $sendtax);
    
    
$playerNewTroops $player[pTroops] - $troops;
    
$villageNewTroops $village[pTroops] + $transferTotal;
    
    
// for debugging purposes
    //return '<font color="'.$failcolor.'">FAIL FAIL FAIL ALERT! '
    //.'<br />tax: '.$sendtax
    //.'<br />troops to send: '.$troops
    //.'<br />after tax: '.$transferTotal
    //.'<br />troops lost: '.$troopsLost
    //.'<br />playerNewTotal: '.$playerNewTroops
    //.'<br />villageNewTotal: '.$villageNewTroops.'</font>';
    
    
$newTurnCount $player[pTurns] - 1;
    
    
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_players SET pTurns = '".$newTurnCount."' WHERE playerID = ".$player[playerID]."");
    
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_players SET pTroops = '".$playerNewTroops."' WHERE playerID = ".$player[playerID]."");
    
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_players SET pTroops = '".$villageNewTroops."' WHERE playerID = ".$village[playerID]."");
    
    
//send_notice(1, $player, $village, $lootRatio);
    
    
if($troopLost != 0)
    {
        
$randomMessageChoice mt_rand(1,3);
        switch (
$randomMessageChoice)
        {
            case 
1: return '<font color="'.$passcolor.'">You have sent '.$troops.' troops but '.$troopsLost.' ran away.</font>';


            case 
2: return '<font color="'.$passcolor.'">You have sent '.$troops.' troops but '.$troopsLost.' got lost along the way.</font>';
            default: return 
'<font color="'.$passcolor.'">You have sent '.$troops.' troops but '.$troopsLost.' troops failed to make it there.</font>';
        }
    }
    else return 
'<font color="'.$passcolor.'">You have sent '.$troops.' troops.</font>';
}

function 
run_sendgold($player$village)
{
    global 
$vbulletin$settings$passcolor$failcolor;
    
    if (
$player[pTurns] < 5)
    {
        return 
'<font color="'.$failcolor.'">You can not trade as you do not have enough turns available.</font>';
    }
    
    
$gold $vbulletin->input->clean_gpc('p'"goldamount"TYPE_UINT);

    if (!
is_numeric($gold) && !is_int($troops))
    {
        return 
'<font color="'.$failcolor.'">Please enter an appropriate value.</font>';
    }
    elseif (
$player[pGold] == 0)
    {
        return 
'<font color="'.$failcolor.'">You can not send gold because you don\'t have any!</font>';
    }
    elseif (
$gold $player[pGold])
    {
        return 
'<font color="'.$failcolor.'">You can not send more gold than what you have!</font>';
    }
    
    if (
$player[pTroops] >= ($village[pTroops]*2)) $sendtax .77;
    elseif (
$player[pTroops] >= ($village[pTroops]+1)) $sendtax pow(0.75, (($player[pTroops]/$village[pTroops])*2.5));
    else 
$sendtax 0;

    if (
$player[pTroops] > ($village[pTroops]*2) && ($gold > ($village[pTroops]*2)))
    {
        
$gold $village[pTroops]*2;
        
$transferTotal $gold - ($gold $sendtax);
    }
    else 
$transferTotal $gold - ($gold $sendtax);
    
$transferTotal ceil($transferTotal);
    
$goldLost ceil($gold $sendtax);

    
$playerNewGold $player[pGold] - $gold;
    
$villageNewGold $village[pGold] + $transferTotal;
    
    
// for debugging purposes
    //return '<font color="'.$failcolor.'">FAIL FAIL FAIL ALERT! '
    //.'<br />tax: '.$sendtax
    //.'<br />gold to send: '.$gold
    //.'<br />after tax: '.$transferTotal
    //.'<br />gold lost: '.$goldLost
    //.'<br />playerNewTotal: '.$playerNewGold
    //.'<br />villageNewTotal: '.$villageNewGold.'</font>';
    
    
$newTurnCount $player[pTurns] - 5;

    
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_players SET pTurns = '".$newTurnCount."' WHERE playerID = ".$player[playerID]."");
    
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_players SET pGold = '".$playerNewGold."' WHERE playerID = ".$player[playerID]."");
    
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_players SET pGold = '".$villageNewGold."' WHERE playerID = ".$village[playerID]."");
    
    
//send_notice(1, $player, $village, $lootRatio);
    
    
if ($goldLost != 0)
    {
        
$randomMessageChoice mt_rand(1,3);
        switch (
$randomMessageChoice)
        {
            case 
1: return '<font color="'.$passcolor.'">You have sent '.$gold.' gold but '.$goldLost.' was taken as draconian tax.</font>';
            case 
2: return '<font color="'.$passcolor.'">You have sent '.$gold.' gold but '.$goldLost.' was stolen by steelzepplin.</font>';
            default: return 
'<font color="'.$passcolor.'">You have sent '.$gold.' gold but '.$goldLost.' was taxed and lost during the transfer.</font>';
        }
    }
    else return 
'<font color="'.$passcolor.'">You have sent '.$gold.' gold.</font>';


add this check to conquest.php
PHP Code:

// ########################################################################
// IS USER SENDING TROOPS?

if ($village fetch_village($vbulletin->input->clean_gpc('p''sendtroops'TYPE_UINT)))
{
    
$noticeTEXT run_sendtroops($player$village);
    
$player fetch_player($vbulletin->userinfo[userid]);
}

// ########################################################################
// IS USER SENDING GOLD?

if ($village fetch_village($vbulletin->input->clean_gpc('p''sendgold'TYPE_UINT)))
{
    
$noticeTEXT run_sendgold($player$village);
    
$player fetch_player($vbulletin->userinfo[userid]);


modify the conquest_village template for each theme used to have this above the raid/spy run area
HTML Code:

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr><td class="tcat" align="center">Trading</td></tr>

<tr><td class="alt1" align="center">
    <table cellpadding="5" cellspacing="0" border="0" width="100%" align="center">
    <tr>
        <td width="50%" valign="top">
            <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
            <tr>
                <td class="thead" align="center">Send Troops</td>
            </tr>
            <tr>
                <td class="alt1" align="center"><form action="$filename?do=village&pid=$village[playerID]" method="post">
                    <input type="hidden" name="securitytoken" value="$bbuserinfo[securitytoken]" />
                    <input type="hidden" name="sendtroops" value="$village[playerID]" />
                    <input name="troopamount" type="text" size="10" />
                    <input type="submit" value="Send">
                </form></td>
            </tr>
            </table>
        </td>
        <td width="50%" valign="top">
            <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
            <tr>
                <td class="thead" align="center">Send Gold</td>
            </tr>
            <tr>
                <td class="alt1" align="center"><form action="$filename?do=village&pid=$village[playerID]" method="post">
                    <input type="hidden" name="securitytoken" value="$bbuserinfo[securitytoken]" />
                    <input type="hidden" name="sendgold" value="$village[playerID]" />
                    <input name="goldamount" type="text" size="10" />
                    <input type="submit" value="Send">
                </form></td>
            </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td width="50%" align="center"><strong>Performing a troop trade cost 1 turn</strong></strong></td>
        <td width="50%" align="center"><strong>Performing a gold trade cost 5 turns</strong></strong></td>
    </tr>
    </table>
   
</td></tr>
</table>

It isn't pretty but it works which is all I cared about when doing this.

Just wanted to add thanks for the author for this mod! It is awesome and I have wasted too many hours on it :D

Hornstar 06-30-2009 04:32 AM

its a shame this has not had any updates in a while. I was beta testing it with my staff but they don't really seem that interested in this because of its lack of features/updates.

Jaxel 06-30-2009 11:33 PM

Sorry for the lack of updates... after a long wait I'm back to programming... working on a different mod right now (because that mod actually makes me money)... but this mod is up next.

blissend 07-01-2009 12:01 AM

Quote:

Originally Posted by Jaxel (Post 1840443)
Sorry for the lack of updates... after a long wait I'm back to programming... working on a different mod right now (because that mod actually makes me money)... but this mod is up next.

Awesome! I can't wait 8)

therogueforums 07-01-2009 07:40 AM

Quote:

Originally Posted by Jaxel (Post 1840443)
Sorry for the lack of updates... after a long wait I'm back to programming... working on a different mod right now (because that mod actually makes me money)... but this mod is up next.

Totally understandable :) looking forward to the updates!

ged 07-02-2009 12:49 PM

Quote:

Originally Posted by Jaxel (Post 1840443)
Sorry for the lack of updates... after a long wait I'm back to programming... working on a different mod right now (because that mod actually makes me money)... but this mod is up next.

Health first, money second and other mods third. :)

Good news! :)

therogueforums 07-02-2009 08:43 PM

Quote:

Originally Posted by blissend (Post 1839876)
For those interested in adding a trade system, here is my really sloppy attempt and how you can do it. Hopefully the author will consider adding it and that I'm not out of line for posting this 8)

Just made the changes, and all seems to be working correctly. Thank you! Hopefully, there will be resources latter on (that provide certain benefits when you have/obtain them), and are trade-able.

therogueforums 07-03-2009 08:09 AM

Is there any way to allow players to switch nations, WITHOUT going into the SQL?

ged 07-03-2009 11:05 AM

I think Jaxel has noted these suggestions and fixes, am I right Jaxel? :rolleyes:

Dutch_Boy 07-03-2009 05:51 PM

Quote:

Originally Posted by Jaxel (Post 1840443)
Sorry for the lack of updates... after a long wait I'm back to programming... working on a different mod right now (because that mod actually makes me money)... but this mod is up next.

Great still working on this mod.
Army is dead so i uninstalled it.

Ill give it a try :)


All times are GMT. The time now is 01:53 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01548 seconds
  • Memory Usage 1,869KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete