i tried to make a nice guild system. its kinda buggy…
durrr facepalm
but here it is anyway incase anyone wants it.
in order to get a list of all the guilds, i needed to patch the gserver. if anyone knows a better way, please tell me.
The patch adds a gr.updateguildlist triggeraction which sets some server flags:
server.guild.nameX (where X is a numerical index)
server.guild.count
i included a copy of a patched gserver for w32 if anyone is interested but cbf. Be warned. it crashes when u try to set serverflags from rc ;[
its probably best to also define server.stafftags1,2,3,4.
Commands in guild npc:
guild.list (needs the patch)
guild.create
guild.disband
guild.leave
guild.invite
guild.kick
// ranks: leader, recruiter, member
guild.setRank
// admin only
guild.remove
// NPC made by potato (NAT)
// -guild
//
// guild system npc
//
//
// supported commands:
//
// guild.list
//
// guild.create <guild>
// guild.disband
// guild.leave
//
// guild.invite <account>
// guild.kick <account>
//
// ranks: leader, recruiter, member
// guild.setRank <account> <Rank>
//
// admin only
// guild.remove <guild>
//
if (created||playerenters) {
toweapons -guilds;
this.timeLeft = 0;
//modes
this.mode = 0;
this.removingGuild = 1;
this.joiningGuild = 2;
this.leavingGuild = 3;
this.listGuilds = 4;
this.creatingGuild = 5;
this.disbandGuild = 6;
this.guildRank_member = 10;
this.guildRank_recruiter = 20;
this.guildRank_leader = 30;
}
if(actionGuildInvite){
if(strequals(#a,#p(0))){
setstring this.guildName,#p(1);
setplayerprop #c, Join Guild: #s(this.guildName)? (5);
this.mode = this.joiningGuild;
this.timeLeft = 5;
timeout = 1;
}
}
if(actionGuildKick){
if(strequals(#a,#p(0))){
triggeraction 0,0,gr.removeguildmember,#p(1),#a;
triggeraction 0,0,gr.setguild,#a,#a;
triggeraction 0,0,gr.removeguild,#a;
setstring client.guild,;
setstring client.guildRank,;
say2 You have been kicked from guild: #p(1)#bReason:#b#p(2);
}
}
if(actionGuildRank){
if(!strequals(#s(client.guild),)){
if(strequals(#a,#p(0))){
if( strequals(#p(1),leader) ){
setplayerprop #c, I'm now ranked Leader in my Guild!;
setstring client.guildRank,#v(this.guildRank_leader);
}
else if( strequals(#p(1),recruiter) ){
setplayerprop #c, I'm now ranked Recruiter in my Guild!;
setstring client.guildRank,#v(this.guildRank_recruiter);
} else {
setplayerprop #c, I'm now ranked Member in my Guild!;
setstring client.guildRank,#v(this.guildRank_member);
}
}
}
}
if(timeout){
if( (this.timeLeft > 0) && (this.mode > 0) ){
if(this.mode == this.joiningGuild){
setplayerprop #c, Join Guild: #s(this.guildName)? (#v(this.timeLeft));
timeout = 1;
this.timeLeft -= 1;
}
else if(this.mode == this.removingGuild || this.mode == this.disbandGuild){
setplayerprop #c, Remove Guild: #s(this.guildName)? (#v(this.timeLeft));
timeout = 1;
this.timeLeft -= 1;
}
else if(this.mode == this.leavingGuild){
setplayerprop #c, Leave Guild: #s(client.guild)? (#v(this.timeLeft));
timeout = 1;
this.timeLeft -= 1;
}
else if(this.mode == this.creatingGuild){
setplayerprop #c, Create Guild: #s(this.guildName)? (#v(this.timeLeft));
timeout = 1;
this.timeLeft -= 1;
}
else if(this.mode == this.listGuilds){
//reset box position
//divided by 16 to get tiles -> pixel
rect.x = playerx-18;
rect.y = playery-6;
rect.width = 18;
rect.height = 20;
//restrict to screen values
if( rect.x < 0 ){ rect.x = 0; }
if( rect.y < 0 ){ rect.y = 0; }
if( rect.width > screenwidth/16 ){ rect.width = screenwidth/16; }
if( rect.hieght > screenwidth/16 ){ rect.hieght = screenhieght/16; }
if( rect.x+rect.width > 64 ){ rect.x = 64-rect.width; }
if( rect.y+rect.height > 64 ){ rect.y = 64-rect.height; }
//draw box
showpoly 255,{
rect.x, rect.y,
rect.x+rect.width, rect.y,
rect.x+rect.width, rect.y+rect.height,
rect.x, rect.y+rect.height
}
changeimgcolors 255,0,0,0,1;
changeimgvis 255, 2;
//draw guild list heading
showimg 256,@TEMPSITC.TTF@bold@Guild List (#v(this.curPage)/#v(this.pages)),rect.x+4, rect.y+.5;
changeimgvis 256, 3;
//draw guilds
this.drawIndex = 257;
this.guildIndex = 0;
if( (this.guildsCount-this.staffGuildsCount) > this.linesPerPage ){
this.nonStaffGuildCount = 0;
for(this.guildIndex=0; this.nonStaffGuildCount < this.linesPerPage*this.curPage; this.guildIndex++){
if(this.guildIndex==this.guildsCount){ break; }
setstring this.guildName,#s(server.guild.name#v(this.guildIndex));
if(strcontains(#s(server.stafftags1),#s(this.guildName))||strcontains(#s(server.stafftags2),#s(this.guildName))||
strcontains(#s(server.stafftags3),#s(this.guildName))||strcontains(#s(server.stafftags4),#s(this.guildName))) {
continue;
}
this.nonStaffGuildCount++;
}
}
this.guildListLine = 0;
for(this.i=0; (this.guildListLine < this.linesPerPage); this.i++){
if(this.guildIndex==this.guildsCount+this.i){ break; }
setstring this.guildName,#s(server.guild.name#v(this.guildIndex+this.i));
if(strcontains(#s(server.stafftags1),#s(this.guildName))||strcontains(#s(server.stafftags2),#s(this.guildName))||
strcontains(#s(server.stafftags3),#s(this.guildName))||strcontains(#s(server.stafftags4),#s(this.guildName))) {
continue;
}
showimg this.drawIndex,@TEMPSITC.TTF@@#s(this.guildName), rect.x+1, rect.y+3+this.textSpacing*this.guildListLine;
changeimgvis this.drawIndex, 3;
this.drawIndex++;
this.guildListLine++;
}
//advance page
//left
if(keydown(1)){
if( this.curPage > 1 ){ this.curPage--; } else { this.exit = 1; }
}
//right
if(keydown(3)){
if(this.curPage < this.pages){ this.curPage++;} else { this.exit = 1; }
}
if(this.exit == 1){
setani idle,;
enabledefmovement;
hideimgs 255, 257+this.linesPerPage;
if(!client.minimapOff){
showstats 0x7FF;
}
} else {
this.timeLeft = 10;
timeout = .2;
}
}
} else {
this.mode = 0;
this.timeLeft = 0;
timeout = 0;
setplayerprop #c, Guild action timed out;
}
}
if(playerchats){
if( this.mode != 0 && strequals(#c,no) ){
this.mode = 0;
this.timeLeft = 0;
timeout = 0;
setplayerprop #c,Guild action declined;
}
if(strequals(#c,yes)){
//creating
if(this.mode == this.creatingGuild ){
playerrupees -= 500;
setstring client.guild,#s(this.guildName);
setstring client.guildRank,#v(this.guildRank_leader);
triggeraction 0,0,gr.addguildmember,#s(this.guildName),#a,#n;
triggeraction 0,0,gr.setguild,#s(this.guildName),#a;
setplayerprop #c,Guild Created: #s(this.guildName);
}
//removing guild
else if(this.mode == this.removingGuild ){
triggeraction 0,0,gr.removeguild,#s(this.guildName);
setplayerprop #c,Removed guild: #s(this.guildName);
}
//disbanding guild
else if(this.mode == this.disbandGuild ){
triggeraction 0,0,gr.removeguild,#s(this.guildName);
setplayerprop #c,Disbanded guild: #s(this.guildName);
setstring client.guild,;
setstring client.guildRank,;
}
//joining
else if(this.mode == this.joiningGuild ){
triggeraction 0,0,gr.addguildmember,#s(this.guildName),#a,#n;
triggeraction 0,0,gr.setguild,#s(this.guildName),#a;
setplayerprop #c,Joined Guild: #s(this.guildName);
setstring client.guild,#s(this.guildName);
setstring client.guildRank,#v(this.guildRank_member);
}
//leaving
else if(this.mode == this.leavingGuild ){
setplayerprop #c,Left guild: #s(client.guild);
triggeraction 0,0,gr.removeguildmember,#s(client.guild),#a;
triggeraction 0,0,gr.setguild,#a,#a;
triggeraction 0,0,gr.removeguild,#a;
setstring client.guild,;
setstring client.guildRank,;
}
this.mode = 0;
this.timeLeft = 0;
timeout = 0;
}
if(strequals(#c,guild.list)){
setani maps2,;
disabledefmovement;
setplayerprop #c, Looking at Guild List...;
//update server guild list flags
triggeraction 0,0,gr.updateguildlist,;
//count staff guilds
this.staffGuildsCount = 0;
for(this.i=0; this.i < strtofloat(#s(server.guild.count)); this.i++){
setstring this.guildName,#s(server.guild.name#v(this.i));
if(strcontains(#s(server.stafftags1),#s(this.guildName))||strcontains(#s(server.stafftags2),#s(this.guildName))||
strcontains(#s(server.stafftags3),#s(this.guildName))||strcontains(#s(server.stafftags4),#s(this.guildName))) {
this.staffGuildsCount++;
}
}
setstring server.staffGuildsCount,#v(this.staffGuildsCount);
//initialise settings for guild list box
this.guildsCount = strtofloat(#s(server.guild.count));
this.textSpacing = (20/16);
this.linesPerPage = 12;
this.pages = int((this.guildsCount-this.staffGuildsCount)/this.linesPerPage-.04);
this.remainder = (this.guildsCount-this.staffGuildsCount)%this.linesPerPage;
if(this.remainder != 0){ this.pages++; }
this.curPage= 1;
this.exit = 0;
showstats 0x6FF; //hide minimap
this.mode = this.listGuilds;
this.timeLeft = 10;
timeout = 0.1;
}
if(startswith(guild.create,#c)){
tokenize #c;
if(strequals(#t(1),)){
setplayerprop #c,syntax: guild.create <guild name>;
} else {
if( strequals(#s(client.guild),) ){
//check if players have enough money
if(playerrupees < 500){
setplayerprop #c, Not enough money to start guild (500 rupees);
}else{
//check if guild already exists
this.guildExists = 0;
for(this.i=0; this.i < strtofloat(#s(server.guild.count)); this.i++){
setstring this.guildName,#s(server.guild.name#v(this.i));
if( strequals(#t(1),#s(this.guildName)) ){
this.guildExists = 1;
break;
}
}
if(this.guildExists == 0){
setstring this.guildName,#t(1);
this.mode = this.creatingGuild;
this.timeLeft = 5;
timeout = 0.1;
} else {
setplayerprop #c, Guild already exists: #t(1);
}
}
} else {
setplayerprop #c, Can't make guild, already in one: #s(client.guild);
}
}
}
if(startswith(guild.disband,#c)){
if(!strequals(#s(client.guild),)){
if( strtofloat(#s(client.guildRank)) == this.guildRank_leader){
setstring this.guildName,#s(client.guild);
this.mode = this.disbandGuild;
this.timeLeft = 5;
timeout = 0.1;
} else {
setplayerprop #c, Can't disband, rank too low;
}
} else {
setplayerprop #c, Can't disband, not in guild;
}
}
if(startswith(guild.remove,#c)){
if(strcontains(#s(server.stafftags1),#g)||strcontains(#s(server.stafftags2),#g)||
strcontains(#s(server.stafftags3),#g)||strcontains(#s(server.stafftags4),#g)) {
tokenize #c;
if(strequals(#t(1),)){
setplayerprop #c,syntax: guild.disband <guild name>;
} else {
setstring this.guildName,#t(1);
this.mode = this.removingGuild;
this.timeLeft = 5;
timeout = 0.1;
}
}
}
if(strequals(#c,guild.leave)){
if(strequals(#s(client.guild),)){
setplayerprop #c, Can't leave. Not in a guild;
} else {
setstring this.guildName,#s(client.guild);
this.mode = this.leavingGuild;
this.timeLeft = 5;
timeout = 0.1;
}
}
if( startswith(guild.invite,#c) ){
if( strequals(#s(client.guild),) ){
setplayerprop #c, Can't invite. Not in a guild;
} else {
if( strtofloat(#s(client.guildRank)) > this.guildRank_member ){
tokenize #c;
if(strequals(#t(1),)){
setplayerprop #c,syntax: guild.invite <account>;
} else {
tokenize #c;
this.i=0;
while(this.i < playerscount){
triggeraction players[this.i].x+1.45,players[this.i].y+1.45,GuildInvite,#t(1),#s(client.guild),#t(2);
this.i+=1;
}
}
}
}
}
if( startswith(guild.kick,#c) ){
if( strequals(#s(client.guild),) ){
setplayerprop #c, Can't kick. Not in a guild;
} else {
if( strtofloat(#s(client.guildRank)) > this.guildRank_member ){
tokenize #c;
if(strequals(#t(1),) || strequals(#t(2),)){
setplayerprop #c,syntax: guild.kick <account> <reason>;
} else {
tokenize #c;
this.i=0;
while(this.i < playerscount){
triggeraction players[this.i].x+1.45,players[this.i].y+1.45,GuildKick,#t(1),#s(client.guild);
this.i+=1;
}
}
}
}
}
if(startswith(guild.setrank,#c)){
if(!strequals(#s(client.guild),)){
if( strtofloat(#s(client.guildRank)) == this.guildRank_leader ){
tokenize #c;
this.i=0;
while(this.i < playerscount){
triggeraction players[this.i].x+1.45,players[this.i].y+1.45,GuildRank,#t(1),#t(2);
this.i+=1;
}
} else {
setplayerprop #c, Can't change rank. Ranked too low;
}
} else {
setplayerprop #c, Can't set rank. Not in a guild;
}
}
}