This is an add on for the gang system created by Floydian (Gang Replacement)
With this add on all gangs start in a passive mode in which they can not war or have war declared on them. Once the leader/pres decides, they can choose to enter an aggressive mode. However, once they enter the aggressive mode, they can not return to the passive mode.
Installation: 1 file, 1 sql, and 2 files to edit
First run this sql
ALTER TABLE `gangs` ADD `gangSTATUS` INT( 1 ) NOT NULL DEFAULT '1'
Then the file you will be adding. It will be saved to /gangs/plugins/private/
gang_status.php
<?php
/**
* @name gang_status.php
* @author TwiztedFake
* @version 1.0.0
* @copyright All rights reserved by TwiztedFake 2010
* All rights reserved. No piracy is permitted. Use this file at your own risk.
* There is no warrenty, and the author assumes no liability.
ALTER TABLE `gangs` ADD `gangSTATUS` INT( 1 ) NOT NULL DEFAULT '1'
*/
if (!defined('GANG_MODULE')) {
return;
}
$gvars->actions += array(
'sgang_status' => 'sgang_status',
'sgang_status_update' => 'sgang_status_update',
);
$gvars->links_staff += array(
'sgang_status' => array(
'label' => 'Status',
'order' => 11
),
);
function sgang_status()
{
global $gvars;
if (!gang_auth_all($gvars->userid, array('pres', 'vice'))) {
echo "<h3>You are not authorized to access this portion of the staff panel.</h3>";
gang_go_back('yourgang.php'); return;
}
if($gvars->data['gangSTATUS'] == 1)
{
echo "
<h2>Gang Status</h2>
<p style='width: 450px; text-align: left;'>Your gang is currently in a passive state thus excluding it from any
warring. You may change your gangs status to aggressive at any time. However, once you enter an aggressive state,
your gang can not return to a passive state.
Once you put your gang in the aggressive state you are able to declare war against other gangs and other gangs
can declare war against you. During a war, if your gang losses all of its respect, the gang will be lost. Every thing
stored in your gangs vault will be lost (money, crystals, items).</p>
[b]To enter aggressive state, just click the button below.[/b]</p>
<form action=\"yourgang.php?action=sgang_status_update\" method=\"POST\">
<input type=\"submit\" value=\"Go Aggressive\" />
</form>";
}
else
{
print "
[b]Your gang is in an aggressive state and can not be changed[/b]";
}
}
function sgang_status_update()
{
global $gvars;
if (!gang_auth_all($gvars->userid, array('pres', 'vice'))) {
echo "<h3>You are not authorized to access this portion of the staff panel.</h3>";
gang_go_back('yourgang.php'); return;
}
mysql_query("UPDATE gangs SET gangSTATUS = 2 WHERE gangID = {$gvars->data['gangID']}");
echo "<h2>Your gang is now in an aggressive state.</h2>";
}
Open file
gangs/plugins/private/gang_staff.php
Find
function sgang_war() {
global $gvars;
Replace that entire function with the following
function sgang_war() {
global $gvars;
if (!gang_auth_all($gvars->userid, array('pres', 'vice'))) {
echo "<h3>You are not authorized to access this portion of the staff panel.</h3>";
gang_go_back('yourgang.php?action=sgang_home'); return;
}
$gang_list = array();
$q_get = sprintf('select gangID, gangNAME from gangs where gangID != %d AND gangSTATUS = 2 order by gangNAME', $gvars->ir['gang']);
$q_get = mysql_query($q_get);
if ($q_get and mysql_num_rows($q_get) > 0) {
while (list($gang_id, $gang_name) = mysql_fetch_row($q_get)) {
$gang_list[$gang_id] = $gang_name;
}
}
// warID, warDECLARER, warDECLARED, warTIME <<< gangwars
// surID, surWAR, surWHO, surTO, surMSG <<< surrenders
$war_list = '';
$war_ids = array();
$q_get = sprintf('select w.warID as war_id, ga.gangID as us_id, ga.gangNAME as us_name,
gb.gangID as them_id, gb.gangNAME as them_name, a.surID as us_sur_id, a.surMSG as us_sur_msg,
b.surID as them_sur_id, b.surMSG as them_sur_msg
from gangwars as w
left join surrenders as a on w.warID = a.surWAR and w.warDECLARER = a.surWHO
left join surrenders as b on w.warID = b.surWAR and w.warDECLARED = b.surWHO
left join gangs as ga on w.warDECLARER = ga.gangID
left join gangs as gb on w.warDECLARED = gb.gangID
where %d in (warDECLARER, warDECLARED)', $gvars->ir['gang']);
$q_get = mysql_query($q_get);
if ($q_get and mysql_num_rows($q_get) > 0) {
while ($row = mysql_fetch_assoc($q_get)) {
if (is_null($row['us_id']) or is_null($row['them_id'])) {
$q_del = sprintf('delete from gangwars where warID = %d', $row['war_id']);
mysql_query($q_del);
continue;
}
if ($gvars->ir['gang'] == $row['us_id']) {
$war_ids[$row['them_id']] = $row['them_id'];
} else {
$war_ids[$row['us_id']] = $row['us_id'];
}
$us_p = gang_get_gang_link($row['us_id'], $row['us_name']);
$them_p = gang_get_gang_link($row['them_id'], $row['them_name']);
$surrender = "No";
$surrender_msg = "N/A";
$surrender_accept = "<td colspan=\"2\">N/A</td>";
$surrender_accept = sprintf('
<td colspan="2" class="ygang_menu">
[url="yourgang.php?action=sgang_war_surrender&war_id=%d"]Offer Surrender[/url]
</td>', $row['war_id']);
if ($row['us_sur_id']) {
$surrender = $us_p;
$surrender_msg = $row['us_sur_msg'];
if ($gvars->ir['gang'] != $row['us_id']) {
$surrender_accept = sprintf('
<td class="ygang_menu">
[url="yourgang.php?action=sgang_war_accept&sur_id=%d"]Accept[/url]
</td>
<td class="ygang_menu">
[url="yourgang.php?action=sgang_war_decline&sur_id=%d"]Decline[/url]
</td>
', $row['us_sur_id'], $row['us_sur_id']);
} else {
$surrender_accept = '
<td colspan="2">
N/A
</td>';
}
}
if ($row['them_sur_id']) {
$surrender = $them_p;
$surrender_msg = $row['them_sur_msg'];
if ($gvars->ir['gang'] != $row['them_id']) {
$surrender_accept = sprintf('
<td class="ygang_menu">
[url="yourgang.php?action=sgang_war_accept&sur_id=%d"]Accept[/url]
</td>
<td class="ygang_menu">
[url="yourgang.php?action=sgang_war_decline&sur_id=%d"]Decline[/url]
</td>
', $row['them_sur_id'], $row['them_sur_id']);
} else {
$surrender_accept = '
<td colspan="2">
N/A
</td>';
}
}
$war_list .= sprintf('
<tr>
<td>
%s
</td>
<td>
%s
</td>
<td>
%s
</td>
<td>
%s
</td>
%s
</tr>%s
', $us_p, $them_p, $surrender, $surrender_msg, $surrender_accept, "\n");
}
}
$potential_wars = array_diff_key($gang_list, $war_ids);
$potential_war_list = '';
foreach ($potential_wars as $key => $value) {
$potential_war_list .= <<<EOT
<option value="$key">$value</option>\n
EOT;
}
echo <<<EOT
<h2>War Management</h2>
<table>
<tr>
<th>
Declarer
</th>
<th>
Declared
</th>
<th>
Surrendered?
</th>
<th>
Surrender Msg
</th>
<th colspan="2">
Surrender Links
</th>
</tr>
$war_list
</table>
<p class="bold center">Declare War</p>
<form method="post" action="yourgang.php?action=sgang_war_declare">
<table style="width: 220px">
<tr>
<th>
Declare war on:
<select name="gang_id">
<option value="0">Select one...</option
$potential_war_list
</select>
</th>
</tr>
<tr>
<th>
<input type="submit" value="Declare">
</th>
</tr>
</table>
</form>
EOT;
}
Next Find
function sgang_war_declare() {
global $gvars;
Replace entire function with the following
function sgang_war_declare() {
global $gvars;
if (!gang_auth_all($gvars->userid, array('pres', 'vice'))) {
echo "<h3>You are not authorized to access this portion of the staff panel.</h3>";
gang_go_back('yourgang.php?action=sgang_home'); return;
}
if($gvars->data['gangSTATUS'] != 2) {
echo "<h3>You can not declare war while the gang is in a passive state.</h3>";
gang_go_back('yourgang.php?action=sgang_home'); return;
}
if (!isset($_REQUEST['gang_id']) or intval($_REQUEST['gang_id']) < 1) {
echo "<h3>Which $gvars->name_sl are you declaring war on?</h3>";
gang_go_back('yourgang.php?action=sgang_war'); return;
}
$them_id = intval($_REQUEST['gang_id']);
$q_get = sprintf('select gangNAME from gangs where gangID = %d', $them_id);
$q_get = mysql_query($q_get);
if (!$q_get or mysql_num_rows($q_get) < 1) {
echo "<h3>The $gvars->name_sl you are declaring war on does not exist.</h3>";
gang_go_back('yourgang.php?action=sgang_war'); return;
}
list($other_name) = mysql_fetch_row($q_get);
$other_p = gang_get_gang_link($them_id, $other_name);
$q_get = sprintf('select count(*) from gangwars
where %d in (warDECLARER, warDECLARED) and %d in (warDECLARER, warDECLARED)', $gvars->ir['gang'], $them_id);
$q_get = mysql_query($q_get);
list($has_war) = mysql_fetch_row($q_get);
if ($has_war) {
echo "<h3>You are already in a war with $other_name.</h3>";
gang_go_back('yourgang.php?action=sgang_war'); return;
}
//Check for aggresive status
$cc = sprintf('select gangSTATUS from gangs where gangID = %d', $them_id);
$cc = mysql_query($cc);
list($gstat) = mysql_fetch_row($cc);
if ($gstat != 2) {
echo "<h3>This gang is passive and cannot be warred.</h3>";
gang_go_back('yourgang.php?action=sgang_war'); return;
}
// warID, warDECLARER, warDECLARED, warTIME <<< gangwars
$q_set = sprintf('insert into gangwars (warDECLARER, warDECLARED, warTIME)
values (%d, %d, unix_timestamp())', $gvars->ir['gang'], $them_id);
mysql_query($q_set);
if (mysql_affected_rows() < 1) {
echo "<h3>The war could not be declared.</h3>";
} else {
echo "<h3>The war has been declared.</h3>";
$us_p = gang_get_profile_link($gvars->ir['userid'], $gvars->ir['username']);
$us_gang__p = gang_get_profile_link($gvars->ir['gang'], $gvars->data['gangNAME']);
gang_new_event($gvars->ir['gang'], sprintf('%s declared war on %s.', $us_p, $other_p), 'escape');
gang_new_event($them_id, sprintf('%s declared war.', $us_gang__p), 'escape');
}
gang_go_back('yourgang.php?action=sgang_war');
}
Save & Close file gang_staff.php
Open
gangs/plugins/public/gang_list.php
Find
function gang_list() {
global $gvars;
Replace the entire function with the following
function gang_list() {
global $gvars;
// gangID, gangNAME, gangDESC, gangPREF, gangSUFF, gangMONEY, gangCRYSTALS, gangRESPECT, gangPRESIDENT, gangVICEPRES, gangCAPACITY, gangCRIME, gangCHOURS, gangAMENT
$where = array();
if (!isset($_REQUEST['letter']) or strlen($_REQUEST['letter']) != 1 or !ctype_alpha($_REQUEST['letter'])) {
$letter = '';
$form_letter = '';
} else {
$letter = $_REQUEST['letter'];
$where[] = sprintf('g.gangNAME like("%s%%")', $letter);
$form_letter = sprintf('<input type="hidden" name="letter" value="%s">', $letter);
}
if (!empty($where)) {
$where = 'where ' . implode(' and ', $where);
} else {
$where = '';
}
if (!isset($_REQUEST['offset']) or intval($_REQUEST['offset']) < 1) {
$offset = 0;
} else {
$offset = intval($_REQUEST['offset']);
}
if (!isset($_REQUEST['limit']) or intval($_REQUEST['limit']) < 25) {
$limit = 25;
} else if (intval($_REQUEST['limit']) > 100) {
$limit = 100;
} else {
$limit = intval($_REQUEST['limit']);
}
$q_get = sprintf('select count(*)
from gangs as g
%s
', $where);
$q_get = mysql_query($q_get);
list($total_results) = mysql_fetch_row($q_get);
$num_pages = ceil($total_results / $limit);
$current_page = floor($offset / $limit) + 1;
$q_get = sprintf('select gangID as gang_id, gangNAME as name, gangDESC as description,
gangPREF as prefix, gangSUFF as suffix, gangMONEY as money, gangCRYSTALS as crystals,
gangRESPECT as respect, gangPRESIDENT as president, gangVICEPRES as vice_president,
gangCAPACITY as capacity, gangCRIME as crime, gangCHOURS as crime_hours, gangSTATUS as status, gangAMENT as announcement,
up.username as pres_name, uv.username as vice_name
from gangs as g
left join users as up on gangPRESIDENT = up.userid
left join users as uv on gangVICEPRES = uv.userid
%s
order by g.gangNAME limit %d, %d
', $where, $offset, $limit);
$q_get = mysql_query($q_get);
if (!$q_get or mysql_num_rows($q_get) < 1) {
$gang_list = <<<EOT
<tr>
<td colspan="6">
<h3>No $gvars->name_pl found.</h3>
</td>
</tr>
EOT;
} else {
$gang_list = '';
while ($data = mysql_fetch_assoc($q_get)) {
$respect = number_format($data['respect']);
//Status setup
if($data['status'] == 2) {
$status = "<b style='color:red;'>Aggressive[/b]";
} else {
$status = "<b style='color:green;'>Passive[/b]";
}
if ($gvars->ir['gang']) {
$app_link = '';
} else {
$app_link = sprintf('| [url="gangs.php?action=gang_app&gang_id=%d"]Apply[/url]', $data['gang_id']);
}
$gang_list .= sprintf('
<tr>
<td>
%1$s
</td>
<td>
%2$s
</td>
<td>
%3$s
</td>
<td class="right">
%4$s
</td>
<td class="center">
%7$s
</td>
<td class="center">
%5$s
%6$s
</td>
</tr>
', gang_get_gang_link($data['gang_id'], $data['name']), gang_get_profile_link($data['president'], $data['pres_name']),
gang_get_profile_link($data['vice_president'], $data['vice_name']), $respect, gang_get_gang_link($data['gang_id'], 'View'), $app_link,$status);
}
}
$atoz = range('A', 'Z');
$all_selected = ' selected';
foreach ($atoz as $key => &$value) {
if (strtoupper($letter) === $value) {
$selected = ' selected';
$all_selected = '';
} else {
$selected = '';
}
$value = <<<EOT
[url="gangs.php?action=gang_list&letter=$value"]$value[/url]
EOT;
}
unset($value);
$atoz = implode(' ', $atoz);
$page_options = '';
for ($x = 1; $x <= $num_pages; $x++) {
$page_offset = $x * $limit - $limit;
if ($current_page == $x) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$page_options .= <<<EOT
<option value="$page_offset"$selected>$x</option>
EOT;
}
echo <<<EOT
<h2>$gvars->name_su List</h2>
<table>
<tr>
<td>
$atoz
[url="gangs.php?action=gang_list"]All[/url]
</td>
</tr>
<tr>
<td class="center">
<form method="get" action="gangs.php">
$form_letter
<input type="hidden" name="action" value="gang_list">
Page Number <select name="offset">$page_options</select>
<input type="submit" value="Go">
</form>
</td>
</tr>
</table>
<table style="width: 600px">
<tr>
<th>
$gvars->name_su
</th>
<th>
$gvars->pres
</th>
<th>
$gvars->vice_pres
</th>
<th>
Respect
</th>
<th>
Status
</th>
<th>
Links
</th>
</tr>
$gang_list
</table>
EOT;
}
Find
function gang_view() {
global $gvars;
Replace entire function with the following
function gang_view() {
global $gvars;
if (!isset($_REQUEST['gang_id']) or intval($_REQUEST['gang_id']) < 1) {
echo "<h3>Which $gvars->name_sl are you looking for?</h3>"; return;
}
$gang_id = intval($_REQUEST['gang_id']);
// gangID, gangNAME, gangDESC, gangPREF, gangSUFF, gangMONEY, gangCRYSTALS, gangRESPECT, gangPRESIDENT,
// gangVICEPRES, gangCAPACITY, gangCRIME, gangCHOURS, gangAMENT
$q_get = sprintf('select g.gangNAME, g.gangDESC, g.gangRESPECT, g.gangPRESIDENT, g.gangVICEPRES, g.gangCAPACITY, g.gangSTATUS
from gangs as g where g.gangID = %d', $gang_id);
$q_get = mysql_query($q_get);
if (!$q_get or mysql_num_rows($q_get) < 1) {
echo "<h3>The $gvars->name_sl you selected could not be found.</h3>"; return;
}
list($gang_name, $desc, $respect, $pres_id, $vice_id, $capacity, $gstat) = mysql_fetch_row($q_get);
$desc = nl2br($desc);
$pres_name = 'N/A';
$vice_name = 'N/A';
$q_get = sprintf('select userid, username, daysingang, level from users where gang = %d', $gang_id);
$q_get = mysql_query($q_get);
if (!$q_get or mysql_num_rows($q_get) < 1) {
echo "<h3>The $gvars->name_sl you selected does not have any members.</h3>";
_gang_delete($gang_id);
return;
}
$user_list = '';
$member_count = mysql_num_rows($q_get);
while (list($them_id, $them_name, $daysingang, $level) = mysql_fetch_row($q_get)) {
$profile = gang_get_profile_link($them_id, $them_name);
if ($pres_id == $them_id) {
$pres_name = $profile;
}
if ($vice_id == $them_id) {
$vice_name = $profile;
}
$user_list .= <<<EOT
<tr class="right">
<td class="left">
$profile
</td>
<td>
$level
</td>
<td>
$daysingang
</td>
</tr>\n
EOT;
}
if ($gvars->ir['gang']) {
$app_link = '';
} else {
$app_link = sprintf('<p class="center">[url="gangs.php?action=gang_app&gang_id=%d"]Apply[/url]</p>', $gang_id);
}
//Status setup
if($gstat == 2) {
$status = "<b style='color:red;'>Aggressive[/b]";
} else {
$status = "<b style='color:green;'>Passive[/b]";
}
echo <<<EOT
<h3>$gang_name</h3>
$app_link
<table style="width:400px;">
<tr>
<th>
$gvars->pres
</th>
<th>
$gvars->vice_pres
</th>
<th>
Members
</th>
<th>
Respect Level
</th>
<th>
Status
</th>
</tr>
<tr class="right">
<td class="left">
$pres_name
</td>
<td class="left">
$vice_name
</td>
<td>
$member_count
</td>
<td>
$respect
</td>
<td class="center">
$status
</td>
</tr>
<tr>
<th colspan="5">
Description
</th>
</tr>
<tr>
<td colspan="5">
$desc
</td>
</tr>
</table>
<h3>User List</h3>
<table style="width:400px;">
<tr>
<th>
User
</th>
<th>
Level
</th>
<th>
Days In Gang
</th>
</tr>
$user_list
</table>
EOT;
}