Help with guilds
Help with guilds
Well I'm a mess and i don't know where to start with making a guild. I don't know if i need a database for that or can i just add it to my player database? I tried to find a guild tut on the search bar, but i failed, so if anyone knows where i can find one please point it out to me.
-
alexander19
- Posts: 180
- Joined: Fri Apr 02, 2010 1:05 pm
Re: Help with guilds
Well for the beggining you can start with halls's tutorials on forsaken sanctum 1.0 and check the guilds section.
For the database I used only guilds and guildmembers tables(halls had housing too,but my game didnt had any different building types,just plain guilds so I didnt used housing).
For the main guild page I had this:
When you visit the guild.php page...the script will check if you belong to a guild,if you do it will show a link to your main guild page,if you dont it will show a form where you can enter a name and create your own guild.
guild_creation.php (if you want to create your own guild):
Notice that I had some extra stuff there,like gtrade inside the guilds database table,which is actually the trade level of the guild(when a player gets the rank of merchant within the guild,his trade level will be inserterd within the guild table,and later this trade level will descrease the cost of guilds researches)
This is the researches table for the guild you created:
For the beggining I have only 2 researches,attack and defense and they'll get the values of 0,0,if you dont want your guild to have researches you can delete this line.
Now if you created your guild and want to visit it,you will be redirected to this page,guild2.php :
Ok this is the guild2.php page.
We have first a small menu,with 3 tabs:members/treasury(here the guild members can donate silver and members with a higher rank can do researches) and the administration page(here depending on your rank,you can add new members/delete members/delete guild/give ranks and change the guild info)
Next on the page we call the guild name and info and then we have a table with all guildmembers info and at the bottom page a leave button(in case someone decides to leave your guild)
Now there is a problem with the table,as you notices it shows all players experience and level,and to achieve this I had to upgrade the page everytime a player visits this page.
E.g if a player has lvl 2 and 500 exper and he didnt visit the guild for a week,and in the meantime he made lvl 5 and has 2k experience,the guild will show only lvl 2 and 500 exper,so unless he wont visist the guild again his info wont change...(ya I know this is kind of lame,but couldn't think of another good way..maybe running a cron or something would do the trick..)
Now lets see what happens if someone wants to leave the guild...leaveg.php:
Here we do 2 things:
First we check if the player had the rank of merchant in the guild,if it was merchant then we are going to reset the gtrade to zero.
Second we delete him from the guild.
Now lets see the administration page....administration.php:
Here we have a form with some hidden tabs(pid/subject/my_text...these are the things we need in the next script(addmember2.php) to send a pm to the user we want to join our guild.
Ohh and for the second menu(add members/give rank/delete and guild info....we check the rank of each guildmember, if a new player with the rank of 1(recruit) goes to this page,he wont see anything,if a player with a rank of 2 & 3(squire and merchant) checks this page,he can only add members,while a player of rank 4(noble) can give ranks too and a player of rank 5(Lord==Guild Creator) can delete members/the guild and change the guild info(which appears on the main page))
addmember2.php :
In this script we just send a pm to the player we want to recruit.
The pm contains this message:
You have been invited by playerx to join the x Guild.You can do so by clicking here!
And when they click on the "here" link,they will join your guild.
Btw...you cant do this if you dont have a pm system...there are tons of tutorials on making a pm system if you google for it,and if it doesn't look in the same way as mine,just change the info inside the addmember2.php.
Now lets see what happens if a player wants to join our guild and clicks on the link.....addmember3.php:
Inside this script we make some checks:if the player is already in another guild,if the guild he wants to join does not exit anymore.
And if those conditions are checked he can join the guild.
Now lets check the give ranks page....giverank.php:
Here we have 2 selections..1 for the player and another for the rank we want to give.
And at the bottom of the page I've put a rank description inside a table.
Now lets check regrank.php and see how the ranks are being inserted inside the database:
Here we need to make some checks:
First we need to check if the player's rank we want to change isn't equal or bigger than our and second if the rank we want to give isnt equal or bigger than ours.
For instance..player x has rank2 and we have rank 3,and we want to give player x rank 4...we cannot do that...and second if player x has rank 4 or 5 and we have rank 3,we cannot change its rank.
And then we've dealt with the merchant case...if we want to give the rank of merchant to another player that has a higher trade skill we have to reset the gtrade and give the previous player that was merchant a smaller rank(squire in this case)
Now for the delete page...deletegm.php:
Here we have 2 different scripts....delgm.php for deleting members and delg.php for deleting the guild.
Lets start with delgm:
And delg.php :
Now lets check the last page under the administration menu...the guild info...guildinfo.php:
I've added a little javascript here..to check the length of the text you're typing.
And the guildinfo2.php...:
This is most of it...if you want I'll give you the treasury scripts too..but after you'll finish with these first.
Gonna give you some info on the database too(it looks almost as the one halls used on his tuts):
guilds:
guildmembers:
researched(for the researches part....which you wont really need now):
Let me know if you find any errors(which I'm sure there are
)
Alexander,
For the database I used only guilds and guildmembers tables(halls had housing too,but my game didnt had any different building types,just plain guilds so I didnt used housing).
For the main guild page I had this:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
print "<input type='hidden' name='id' value='$playerinfo3[id]'>";
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
$player2="SELECT * from guildmembers where name='$player'";
$player3=mysql_query($player2) or die("could not find player!");
if($player4=mysql_fetch_array($player3)){
$gg = $player4['pid'];
$hing="SELECT name,pid,randid from guilds WHERE pid='$gg'";
$hing2=mysql_query($hing) or die("Could not get guild");
while($hing3=mysql_fetch_array($hing2))
{
print "<center><b><div style='color:#300000'> $hing3[name]</div> Guild<br><A href='guild2.php?name=$hing3[pid]&randid=$hing3[randid]'><big>Visit</a></b></center>";
}
}
else{
?>
<div align="center">
<div style="color:#009; font-weight:bold">Building a Guild House</div><br /><br />
<div style="color:#630; font-size:14px">A level 1 Guild House costs 2.000 silvers to build.<br>
It allows you to have 5 members.<br>
If you would like to build it then enter a name for your Guild and click create.This also registers your guild.</div><br /><br />
<form method="post" action="guild_creation.php">
<strong>30 character max </strong><input type="text" name="name" size="30" maxlength="30"><br>
<br />
<center><input type="submit" value="Create"></center>
</form>
</div>
<?php
}
?>
guild_creation.php (if you want to create your own guild):
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
print "<input type='hidden' name='id' value='$playerinfo3[id]'>";
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
$pid = $playerinfo3['id'];
$shname = $_POST['name'];
if ($playerinfo3['silver'] < 2000)
{
echo "<center><b>You dont have enough silver to build a Guild House.</b></center>";
echo "<center><b><A href='guild.php'>Go Back</b></center>";
fscript();
}
if ($shname == NULL)
{
echo " <center><b>You did not enter a name! Try again.</b></center>";
echo "<center><b><A href='guild.php'>Go Back</b></center>";
fscript();
}
elseif(strlen($shname)> 30)
{
echo " <center><b>The name you selected is too long,use a shorter one instead.</b></center>";
echo "<center><b><A href='guild.php'>Go Back</b></center>";
fscript();
}
$gcheck = "SELECT * from guilds WHERE pname = '$player'";
$gcheck2 = mysql_query($gcheck)or die("could not find guild!");
$gcheck3 = mysql_fetch_array($gcheck2);
if($gcheck3['pname'] == $player)
{
echo"<center><b>You belong to a guild already,therefore you cannot create another one!";
fscript();
}
else
{
$updateplayers="Update players set silver=silver-2000 where id='$pid'";
mysql_query($updateplayers) or die("Could not update player stats");
$randid = rand(150,500000);
$SQL = "INSERT into guilds(pid, pname, name, lvl, randid, greeting,gtrade) VALUES ('$pid','$playerinfo3[name]','$shname','1','$randid','Welcome to the guild!','0')";
mysql_query($SQL) or die("could not add guild");
$SQL = "INSERT into guildmembers(pid, name,rank,level,glevel,exper)VALUES('$pid','$playerinfo3[name]','Lord','$playerinfo3[level]',5,'$playerinfo3[exper]')";
mysql_query($SQL) or die("could not add guild member");
$SQL = "INSERT into researched(pid, attack, defense) VALUES ('$pid','0','0')";
mysql_query($SQL) or die("could not add guild");
echo "<center><b>The $shname Guild has been created</b></center>";
echo "<center><b><A href='guild.php'>Go Back</b></center>";
}
?>
This is the researches table for the guild you created:
Code: Select all
$SQL = "INSERT into researched(pid, attack, defense) VALUES ('$pid','0','0')";
mysql_query($SQL) or die("could not add guild");Now if you created your guild and want to visit it,you will be redirected to this page,guild2.php :
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$guild="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$guild2=mysql_query($guild) or die("Could not get housing");
$guild3=mysql_fetch_array( $guild2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
?>
<div style="color:#630; font-weight:bold">Members</div>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Administration</span></a></div>";?>
<div align="center">
<div style="font-size:16px; color:#009"><?php echo $guild3['name'] ?></div>
<br /><br /><br />
<?php echo $guild3['greeting'] ?>
<br /><br />
<?php
$updateplayers="Update guildmembers set exper=$playerinfo3[exper] where name='$player'";
mysql_query($updateplayers) or die("Could not update player stats");
$updateplayer="Update guildmembers set level=$playerinfo3[level] where name='$player'";
mysql_query($updateplayer) or die("Could not update player stats");
$player2="SELECT * from guildmembers where name='$player'";
$player3=mysql_query($player2) or die("could not find player!");
$player4=mysql_fetch_array($player3);
$gg = $player4['pid'];
$counter = 1;
print "<table border='0' width='70%' cellspacing='20' >";
print "<tr><td width='25%' valign='top'>";
print "</td>";
print "<td valign='top' width='75%'>";
$selectbackpack="SELECT * from guildmembers where pid='$gg' ORDER BY name ASC";
$selectbackpack2=mysql_query($selectbackpack) or die("could not select backpack");
print "<table class='tip1'border='1'; bgcolor='#655f52'>";
print "<tr><td><div style='color:#4b3608;font-weight:bold'>No.</div></td><td><div style='color:#4b3608;font-weight:bold'>Name</div></td><td><div style='color:#4b3608;font-weight:bold'>Level</div></td><td><div style='color:#4b3608;font-weight:bold'>Experience</div></td><td><div style='color:#4b3608;font-weight:bold'>Rank</div></td></tr>";
while($selectbackpack3=mysql_fetch_array($selectbackpack2))
{
print "<tr><td><div style='color:#141310;font-weight:bold'>$counter</div></td><td><div style='color:#141310;font-weight:bold'>$selectbackpack3[name]</div></td><td><div style='color:#141310;font-weight:bold'>$selectbackpack3[level]</div></td><td><div style='color:#141310;font-weight:bold'>$selectbackpack3[exper]</div></td><td><div style='color:#141310;font-weight:bold'>$selectbackpack3[rank]</div></td></div></tr>";
$counter++;
}
print "</table>";
print "</td></tr></table>";
?>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<form action="leaveg.php?name=<?php echo"$guild3[pid]"?>&randid=<?php echo"$guild3[randid]"?>" method="POST" accept-charset="UTF-8">
<input type="submit" value="Leave Guild" class="button1">
</form>
</div>We have first a small menu,with 3 tabs:members/treasury(here the guild members can donate silver and members with a higher rank can do researches) and the administration page(here depending on your rank,you can add new members/delete members/delete guild/give ranks and change the guild info)
Next on the page we call the guild name and info and then we have a table with all guildmembers info and at the bottom page a leave button(in case someone decides to leave your guild)
Now there is a problem with the table,as you notices it shows all players experience and level,and to achieve this I had to upgrade the page everytime a player visits this page.
E.g if a player has lvl 2 and 500 exper and he didnt visit the guild for a week,and in the meantime he made lvl 5 and has 2k experience,the guild will show only lvl 2 and 500 exper,so unless he wont visist the guild again his info wont change...(ya I know this is kind of lame,but couldn't think of another good way..maybe running a cron or something would do the trick..)
Now lets see what happens if someone wants to leave the guild...leaveg.php:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
if($members3['rank']=="Merchant")
{
$updategs="Update guilds set gtrade = '0' where pid='$pid'";
mysql_query($updategs) or die("Could not update guild");
}
mysql_query("DELETE FROM guildmembers WHERE name ='$player'");
echo"<center><b>You have left the ".$housing3['name']."!</b></center>";
?>First we check if the player had the rank of merchant in the guild,if it was merchant then we are going to reset the gtrade to zero.
Second we delete him from the guild.
Now lets see the administration page....administration.php:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 2)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else
print"<div style='color:#630; font-weight:bold'>Add Member</div>";
if($members3['glevel'] > 3)
{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='giverank.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
}
if($members3['glevel'] > 4)
{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='deletegm.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Delete</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Guild Info</span></a></div>";
}
?>
<div align="center">
<div style="font-weight:bold; color:#036">Add member</div>
<br />
<br />
<div style="color:#660">Enter the name of the member you want to add.</div>
<br />
<br />
<Br />
<form method="post" action="addmember2.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>">
<center>
<input type="text" name="name" size="30" maxlength="30"><br>
<input type="hidden" name="pid" value="<?php echo $pid; ?>"/>
<input type="hidden" name="subject" value="<?php echo "Invitation"; ?>"/>
<input type="hidden" name="my_text" value="<?php echo "You have been invited by ".$playerinfo3['name']." to join the ".$housing3['name']." Guild.You can do so by clicking <a href='addmember3.php?name=$housing3[pid]&randid=$housing3[randid]'>here</a>"; ?>"/>
<input type="submit" value="Submit">
</center></form>
</div>
Ohh and for the second menu(add members/give rank/delete and guild info....we check the rank of each guildmember, if a new player with the rank of 1(recruit) goes to this page,he wont see anything,if a player with a rank of 2 & 3(squire and merchant) checks this page,he can only add members,while a player of rank 4(noble) can give ranks too and a player of rank 5(Lord==Guild Creator) can delete members/the guild and change the guild info(which appears on the main page))
addmember2.php :
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 2)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else
print"<div style='color:#630; font-weight:bold'>Add Member</div>";
if($members3['glevel'] > 3)
{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='giverank.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
}
if($members3['glevel'] > 4)
{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='deletegm.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Delete</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Guild Info</span></a></div>";
}
$pid = $_POST['pid'];
$touser = $_POST['name'];
$touser = mysql_real_escape_string($_POST['name']);
$subject = $_POST['subject'];
$msg = $_POST['my_text'];
$m="SELECT * from guildmembers WHERE name='$touser' ";
$m2=mysql_query($m) or die("Could not get member");
$m3=mysql_fetch_array( $m2);
// preprocessed vars
$fromuser = $_SESSION['player'];
$DateOfRequest = date(" y:m:d : H:i:s", time()) ;
$ck_reciever = "SELECT name FROM players WHERE name = '".$touser."'";
if( mysql_num_rows( mysql_query( $ck_reciever ) ) == 0 ){
echo "<center><strong>The user you are trying to invite does not exist. Please go back and try again.</strong></center><br>
<form name=\"back\" action=\"administration.php?name=$housing3[pid]&randid=$housing3[randid]\"
method=\"post\">
<center><input type=\"submit\" value=\"Try Again\"></center>
</form>
";
exit();
}
if($m3['name'] == $touser)
{
echo "<center><strong>The user you are trying to invite is already in a guild.</strong></center><br>
<form name=\"back\" action=\"administration.php?name=$housing3[pid]&randid=$housing3[randid]\"
method=\"post\">
<center><input type=\"submit\" value=\"Try Again\"></center>
</form>
";
exit();
}
else{
$sql = mysql_query("INSERT INTO `pms` (`id`,`touser`,`fromuser`,`subject`,`message`,`read`,`deleted`,`datesent`) VALUES (NULL, '$touser',
'$fromuser', '$subject', '$msg', '0', '0','$DateOfRequest')");
// redirect away from post page.
echo " <center><strong>Your Invitation was Sent</strong></center>
<form name=\"back\" action=\"administration.php?name=$housing3[pid]&randid=$housing3[randid]\"
method=\"post\">
<center><input type=\"submit\" value=\"Go Back\"></center>";
}
?>
The pm contains this message:
You have been invited by playerx to join the x Guild.You can do so by clicking here!
And when they click on the "here" link,they will join your guild.
Btw...you cant do this if you dont have a pm system...there are tons of tutorials on making a pm system if you google for it,and if it doesn't look in the same way as mine,just change the info inside the addmember2.php.
Now lets see what happens if a player wants to join our guild and clicks on the link.....addmember3.php:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
$select="SELECT * from guildmembers where name = '$playerinfo3[name]'";
$select2=mysql_query($select) or die("could not select members");
$select3=mysql_fetch_array($select2);
if ($select3['name'] == $playerinfo3['name'])
{
echo"<center><b>You need to leave your guild before you can join another one.</b></center>";
exit();
}
$select="SELECT * from guilds where pid = '$pid' AND randid='$randid'";
$select2=mysql_query($select) or die("could not select members");
$select3=mysql_fetch_array($select2);
if($select3['pid'] != $pid)
{
echo"<center><b>You cannot join this guild,because it doesnt exist anymore!</b></center>";
exit();
}
$SQL = "INSERT into guildmembers(pid,name,rank,level,glevel,exper) VALUES ('$pid','$playerinfo3[name]','Recruit','$playerinfo3[level]','1','$playerinfo3[exper]')";
mysql_query($SQL) or die("could not add guild member");
echo "<center><b>Congratulations ".$player . " you have joined the ".$select3['name']." Guild.</b></center>";
?>And if those conditions are checked he can join the guild.
Now lets check the give ranks page....giverank.php:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 3)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Add member</span></a></div>";
print"<div style='color:#630; font-weight:bold'>Give Rank</div>";
}
if($members3['glevel'] > 4)
{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='deletegm.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Delete</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Guild Info</span></a></div>";
?>
<div align="center">
<div style="color:#006; font-weight:bold">Give Rank</div>
<Br />
<form action="regrank.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>" method="POST" accept-charset="UTF-8">
<div style="color:#069">Select a member</div>
<?php
print "<select name='playerchoice' length='20'>";
$classinfo="SELECT * from guildmembers WHERE pid = '$pid'";
$classinfo2=mysql_query($classinfo) or die("Could not select players");
while ($classinfo3=mysql_fetch_array($classinfo2))
{
print "<option>$classinfo3[name]</option>";
}
print "</select><br>";
?>
<div style="color:#066">Select a rank</div>
<br />
<?php
print "<select name='rankchoice' length='20'>";
$classrank="SELECT * from ranks";
$classrank2=mysql_query($classrank) or die("Could not select ranks");
while ($classrank3=mysql_fetch_array($classrank2))
{
print "<option>$classrank3[name]</option>";
}
print "</select><br>";
?>
<br />
<br />
<input type="submit" value="Save" class="button1">
</form>
<br />
<table bgcolor="#666666"><tr><td style=" font-size:14px;color:#f3e4c3;font-weight:bold " >*Lord-The Lord is the guild master and has full control over the guild and its members.<br />*Noble-The Noble is second in charge and has almost as many functions as the Lord with the exception of deleting the guild or its members.<br />*Merchant-The Merchant is the guild treasurer, his trade attribute influences the price of all researches made within the Guild.<br />*Squire-The Squire is a small member within the Guild,therefore he has limited functions.<br />*Recruit-The Recruit is a player new to the guild with no special functions.</td></tr></table>
</div>And at the bottom of the page I've put a rank description inside a table.
Now lets check regrank.php and see how the ranks are being inserted inside the database:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$playerchoice=$_POST['playerchoice'];
$rankchoice=$_POST['rankchoice'];
$playeri="SELECT * from players where name='$playerchoice'";
$playeri2=mysql_query($playeri) or die("could not get player !");
$playeri3=mysql_fetch_array($playeri2);
$pt = $playeri3['trade'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
$mm = $members3['glevel'];
$member="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerchoice'";
$member2=mysql_query($member) or die("could not get members");
$member3=mysql_fetch_array($member2);
$mm2 = $member3['glevel'];
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 3)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Add member</span></a></div>";
print"<div style='color:#630; font-weight:bold'>Give Rank</div>";
}
if($members3['glevel'] > 4)
{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='deletegm.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Delete</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Guild Info</span></a></div>";
?>
<div align="center">
<?php
if($mm <= $mm2)
{
echo"<center><b>This user has the same or bigger rank than yours,so you cannot change it.</b></center>";?>
<form method="post" action="giverank.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>">
<input type="submit" value="Go Back">
</form>
<?php
exit();
}
else{
if($rankchoice == 'Lord')
$rank = 5;
elseif($rankchoice == 'Noble')
$rank = 4;
elseif($rankchoice == 'Merchant')
$rank = 3;
elseif($rankchoice == 'Squire')
$rank = 2;
else
$rank = 1;
if($rank >= $mm)
{
echo"<center><b>You cannot give someone equal or bigger rank than yours.</b></center>";?>
<form method="post" action="giverank.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>">
<input type="submit" value="Go Back">
</form>
<?php
exit();
}
if($rank == 3)
{
$memberss="SELECT * from guildmembers WHERE pid='$pid' AND rank='Merchant'";
$memberss2=mysql_query($memberss) or die("Could not get housing");
$memberss3=mysql_fetch_array( $memberss2);
$grr = $memberss3['rank'];
$updategm="Update guildmembers set rank='Squire' where rank='$grr'";
mysql_query($updategm) or die("could not change ranks");
$updateguilds="Update guilds set gtrade= 0 + '$pt' where pid='$pid'";
mysql_query($updateguilds) or die("Database error");
}
$updateplayers="Update guildmembers set rank='$rankchoice' where name='$playerchoice'";
mysql_query($updateplayers) or die("Could not update player stats");
$updateplayer="Update guildmembers set glevel='$rank' where name='$playerchoice'";
mysql_query($updateplayer) or die("Could not update player stats");
echo"<b>Rank successfully saved!</b>";
}
?>
<br />
<br />
<form method="post" action="giverank.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>">
<input type="submit" value="Go Back">
</form>
</div>First we need to check if the player's rank we want to change isn't equal or bigger than our and second if the rank we want to give isnt equal or bigger than ours.
For instance..player x has rank2 and we have rank 3,and we want to give player x rank 4...we cannot do that...and second if player x has rank 4 or 5 and we have rank 3,we cannot change its rank.
And then we've dealt with the merchant case...if we want to give the rank of merchant to another player that has a higher trade skill we have to reset the gtrade and give the previous player that was merchant a smaller rank(squire in this case)
Now for the delete page...deletegm.php:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 5)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Add member</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='giverank.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
print"<div style='color:#630; font-weight:bold'Delete</div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Guild Info</span></a></div>";
}
?>
<div align="center">
<div style="color:#006; font-weight:bold">Delete Guild Member</div>
<br />
<form action="delgm.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>" method="POST" accept-charset="UTF-8">
<br />
<?php
print "<select name='playerchoice' length='20'>";
$classinfo="SELECT * from guildmembers WHERE pid = '$pid'";
$classinfo2=mysql_query($classinfo) or die("Could not select players");
while ($classinfo3=mysql_fetch_array($classinfo2))
{
print "<option>$classinfo3[name]</option>";
}
print "</select><br>";
?>
<br />
<br />
<input type="submit" value="Delete Member" class="button1">
</form>
<br />
<br />
<div style="color:#006; font-weight:bold">Delete Guild</div>
<br />
<b>Consider it before deleting the guild,because all the guild researches and members will be lost.</b>
<form action="delg.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>" method="POST" accept-charset="UTF-8">
<input type="submit" value="Delete Guild" class="button1">
</form>
</div>Lets start with delgm:
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$delplayer = $_POST['playerchoice'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 5)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Add member</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='giverank.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
print"<div style='color:#630; font-weight:bold'Delete</div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Guild Info</span></a></div>";
}
?>
<div align="center">
<?php
if($delplayer == $player)
{
echo"<center><b>You cannot delete yourself!</b></center>";
?>
<div align="center">
<form method="post" action="deletegm.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>">
<input type="submit" value="Go Back">
</form>
</div>
<?php
exit();
}
else
{
mysql_query("DELETE FROM guildmembers WHERE name ='$delplayer'");
echo"<center><b>Player successfully deleted!</b></center>";
if($members3['rank']=="Merchant")
{
$updategs="Update guilds set gtrade = '0' where pid='$pid'";
mysql_query($updategs) or die("Could not update guild");
}
}
?>
<div align="center">
<form method="post" action="deletegm.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>">
<input type="submit" value="Go Back">
</form>
</div>Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$pname = $housing3['pname'];
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
mysql_query("DELETE FROM guildmembers WHERE pid ='$pid'");
mysql_query("DELETE FROM guilds WHERE pid ='$pid'");
mysql_query("DELETE FROM researched WHERE pid='$pid'");
echo"<center><b>Guild successfully deleted!</b></center>";
?>Code: Select all
<?php
include_once 'connect.php';
session_start();
?>
<head>
<script language=JavaScript>
<!--
function check_length(my_form)
{
maxLen = 500; // max number of characters allowed
if (my_form.my_info.value.length >= maxLen) {
// Reached the Maximum length so trim the textarea
my_form.my_text.value = my_form.my_info.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of my_text counter
my_form.text_num.value = maxLen - my_form.my_info.value.length;}
}
//-->
</script>
</head>
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 5)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Add member</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='giverank.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='deletegm.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
print"<div style='color:#630; font-weight:bold'>Guild Info</div>";
}
?>
<div align="center">
<br />
<div style="color:#039; font-weight:bold">Guild Info</div>
<br />
<br />
<div style="color:#63C; font-weight:bold">Here you can change the guild information that will appear on the main page.</div>
<br />
<br />
<form action="guildinfo2.php?name=<?php echo"$housing3[pid]"?>&randid=<?php echo"$housing3[randid]"?>" method="post" name="sendpm">
<form name=my_form method=post>
<textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_info rows=12 cols=30></textarea>
<br>
<input size=1 value=500 name=text_num> Characters Left
<input type="submit" value="Save Info" />
</form>
</div>
And the guildinfo2.php...:
Code: Select all
<?php
include_once 'connect.php';
session_start();
?>
<head>
<script language=JavaScript>
<!--
function check_length(my_form)
{
maxLen = 500; // max number of characters allowed
if (my_form.my_info.value.length >= maxLen) {
// Reached the Maximum length so trim the textarea
my_form.my_text.value = my_form.my_info.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of my_text counter
my_form.text_num.value = maxLen - my_form.my_info.value.length;}
}
//-->
</script>
</head>
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pid = $_GET['name'];
$randid = $_GET['randid'];
$housing="SELECT * from guilds WHERE pid='$pid' AND randid = $randid";
$housing2=mysql_query($housing) or die("Could not get housing");
$housing3=mysql_fetch_array( $housing2);
$members="SELECT * from guildmembers WHERE pid='$pid' AND name = '$playerinfo3[name]'";
$members2=mysql_query($members) or die("Could not get housing");
$members3=mysql_fetch_array( $members2);
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
exit;}
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='guild2.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Members</span></a></div>";?>
<?php print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='treasury.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Treasury</span></a></div>";?>
<div style="color:#630; font-weight:bold">Administration</div>
<?php
if ($members3['glevel'] < 5)
{
echo"<center><b>Your rank is not high enough to acces this page!</b></center>";
exit();
}
else{
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='administration.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Add member</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='giverank.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
print"<div style='color:#630; font-weight:bold'><a style='height: 22px;' href='deletegm.php?name=$housing3[pid]&randid=$housing3[randid]'><span>Give Rank</span></a></div>";
print"<div style='color:#630; font-weight:bold'>Guild Info</div>";
}
?>
<div align="center">
<br />
<?php
$msg = $_POST['my_info'];
$updateplayers="Update guilds set greeting='$msg' where pid='$pid'";
mysql_query($updateplayers) or die("Could not update guild");
echo " <center><strong>Guild Info was saved.</strong></center>
<form name=\"back\" action=\"guildinfo.php?name=$housing3[pid]&randid=$housing3[randid]\"
method=\"post\">
<center><input type=\"submit\" value=\"Go Back\"></center>";
?>
</div>
Gonna give you some info on the database too(it looks almost as the one halls used on his tuts):
guilds:
Code: Select all
id int(5) auto increment
pid int(9)
name varchar(31)
pname varchar(31)
lvl smallint(2)
randid mediumint(11)
greeting text
donatedsilver int(15)
gtrade smallint(3)
Code: Select all
pid int(9)
name varchar(81)
rank varchar(31)
level smallint(4)
glevel smallint(2)
exper int(11)
donated mediumint(9)
Code: Select all
pid int(6)
attack tinyint(2)
defense tinyint(2)Alexander,
Re: Help with guilds
Wow this was very. . . complete? All i was looking for was someone who could point me to a simple tut, but this works too (actually better). I just wanted something that i could grow off of, but if i need any more help I'll post back here. Thanks
PS Sorry for the late reply i lost my bookmark to this site and it took me awile to find it again.
PS Sorry for the late reply i lost my bookmark to this site and it took me awile to find it again.