/*
create table guild_invite (
id int(11) unsigned primary key auto_increment,
char_id int(11) unsigned,
guild_id int(11) unsigned,
key (char_id),
key (guild_id),
unique (char_id,guild_id)
) engine = innodb;
*/
- script kjhlkjgsdfds -1,{
OnInit:
bindatcmd "guildinvite", strnpcinfo(0)+"::OnInvite", 0,100;
bindatcmd "guildaccept", strnpcinfo(0)+"::OnAccept", 0,100;
bindatcmd "guildreject", strnpcinfo(0)+"::OnReject", 0,100;
bindatcmd "invitelist", strnpcinfo(0)+"::OnList", 0,100;
// bindatcmd "guildjoin", strnpcinfo(0)+"::OnJoin", 0,100;
end;
OnJoin:
if ( .@atcmd_numparameters > 1 )
.@chat$ = implode( .@atcmd_parameters$, " " );
else
.@chat$ = .@atcmd_parameters$;
.@gid = atoi( .@chat$ );
if ( getguildname( .@gid ) == "null" ) {
requestguildinfo .@gid;
sleep2 200; // slow down to retrieve information from char-server.exe
}
guildjoin .@gid, getcharid(0);
end;
OnInvite:
if ( .@atcmd_numparameters > 1 )
.@chat$ = implode( .@atcmd_parameters$, " " );
else
.@chat$ = .@atcmd_parameters$;
.@origin_name$ = strcharinfo(0);
.@gid = getcharid(2);
if ( !.@gid ) {
message .@origin_name$, "[Guild Invitation] You must have a guild to use this command.";
end;
}
if ( getguildmasterid( .@gid ) != getcharid(0) ) {
message .@origin_name$, "[Guild Invitation] You must be a guild master to use this command.";
end;
}
if ( !.@atcmd_numparameters ) {
message .@origin_name$, "[Guild Invitation] You must input a player name.";
end;
}
if ( !( .@cid = getcharid( 0, .@chat$ ) ) ) {
if ( !query_sql( "select char_id, guild_id, name from `char` where name = '"+ escape_sql( .@chat$ ) +"'", .@cid, .@player_gid, .@name$ ) ) {
message .@origin_name$, "[Guild Invitation] Player not exist";
end;
}
if ( .@player_gid ) {
message .@origin_name$, "[Guild Invitation] Player ["+ .@name$ +"] already has a guild.";
end;
}
if ( query_sql( "select 1 from guild_invite where char_id = "+ .@cid +" and guild_id = "+ .@gid, .@dummy ) ) {
message .@origin_name$, "[Guild Invitation] Player ["+ .@name$ +"] has already invited by this guild.";
end;
}
query_sql "insert into guild_invite values ( null, "+ .@cid +", "+ .@gid +" )";
message .@origin_name$, "[Guild Invitation] The player ["+ .@name$ +"] will receive an invitation on his/her next login.";
}
else {
.@name$ = rid2name( getcharid( 3, .@chat$ ) );
if ( getcharid( 2, .@name$ ) ) {
message .@origin_name$, "[Guild Invitation] Player ["+ .@name$ +"] already has a guild.";
end;
}
if ( query_sql( "select 1 from guild_invite where char_id = "+ .@cid +" and guild_id = "+ .@gid, .@dummy ) ) {
message .@origin_name$, "[Guild Invitation] Player ["+ .@name$ +"] has already invited by this guild.";
end;
}
query_sql "insert into guild_invite values ( null, "+ .@cid +", "+ .@gid +" )";
message .@name$, "[Guild Invitation] You have an invitation by ["+ strcharinfo(0) +"] from the ["+ strcharinfo(2) +"] guild.";
message .@origin_name$, "[Guild Invitation] The player ["+ .@name$ +"] has received an invitation.";
}
end;
OnAccept:
if ( .@atcmd_numparameters > 1 )
.@chat$ = implode( .@atcmd_parameters$, " " );
else
.@chat$ = .@atcmd_parameters$;
.@origin_name$ = strcharinfo(0);
if ( getcharid(2) ) {
message strcharinfo(0), "[Guild Invitation] You already have a guild.";
end;
}
if ( !.@atcmd_numparameters ) {
message .@origin_name$, "[Guild Invitation] You must input a guild name.";
end;
}
if ( !query_sql( "select guild_id, name from guild where name = '"+ escape_sql( .@chat$ ) +"'", .@gid, .@gname$ ) ) {
message .@origin_name$, "[Guild Invitation] No such guild name exist.";
end;
}
if ( getguildname( .@gid ) == "null" ) {
requestguildinfo .@gid;
sleep2 200; // slow down to retrieve information from char-server.exe
}
if ( !query_sql( "select 1 from guild_invite where char_id = "+ getcharid(0) +" and guild_id = "+ .@gid, .@dummy ) ) {
message .@origin_name$, "[Guild Invitation] You don't have invitation from that guild.";
end;
}
.@reason = guildjoin( .@gid, getcharid(0) );
if ( !.@reason ) {
message .@origin_name$, "[Guild Invitation] You have successfully join the guild ["+ .@gname$ +"].";
query_sql "delete from guild_invite where char_id = "+ getcharid(0);
}
else if ( .@reason == -4 ) {
message .@origin_name$, "[Guild Invitation] You can't join that guild because the guild is already FULL.";
end;
}
else {
message .@origin_name$, "[Guild Invitation] Chiii ~ Unknown ERROR.";
end;
}
end;
OnReject:
query_sql "delete from guild_invite where char_id = "+ getcharid(0);
message strcharinfo(0), "[Guild Invitation] You have rejected all guild invitations.";
end;
OnList:
.@origin_name$ = strcharinfo(0);
if ( getcharid(2) ) {
message .@origin_name$, "[Guild Invitation] You already have a guild";
query_sql "delete from guild_invite where char_id = "+ getcharid(0);
end;
}
.@nb = query_sql( "select guild_id from guild_invite where char_id = "+ getcharid(0), .@gid );
if ( !.@nb ) {
message .@origin_name$, "[Guild Invitation] You don't have any guild invitation.";
end;
}
for ( .@i = 0; .@i < .@nb; .@i++ ) {
if ( getguildname( .@gid[.@i] ) == "null" ) {
requestguildinfo .@gid[.@i];
sleep2 200; // slow down to retrieve information from char-server.exe
}
message .@origin_name$, "[Guild Invitation] "+( .@i +1 )+". "+ getguildname( .@gid[.@i] );
}
end;
OnPCLoginEvent:
.@origin_name$ = strcharinfo(0);
.@nb = query_sql( "select guild_id from guild_invite where char_id = "+ getcharid(0), .@gid );
if ( !.@nb ) end;
message .@origin_name$, "[Guild Invitation] You have "+ .@nb +" pending guild invitations";
for ( .@i = 0; .@i < .@nb; .@i++ ) {
if ( getguildname( .@gid[.@i] ) == "null" ) {
requestguildinfo .@gid[.@i];
sleep2 200; // slow down to retrieve information from char-server.exe
}
message .@origin_name$, "[Guild Invitation] "+( .@i +1 )+". "+ getguildname( .@gid[.@i] );
}
end;
}