damagepy
09-10-2006, 05:17 PM
Got a problem. When I try to demote /promote someone it reads the currnt rank wrong, and sometime gives a Temporary Guild error.
The idea is to fast promote/demote someone to a named rank. How it works:
IF I have rights, it first search for the specified rankname through ranks, and saves its rankindex to TRANK. Then searchs the player (xxxyyy) or if its not specified ("") then it will be the one that I have currently selected (targeted). IF hes in the guild, checks its current rank, and saves the rankindex to PRANK. So he must be promoted/demoted from PRANK to TRANK (for example from rank 2 to 6). It checks the difference, and do 9-2 = 4 promote.
But it just do 2-3 promotion then gives 2-1 "Temporary guild error." message. If I do it again then it can do it from 4 to 6, but sometimes reads the current rank wrong. Must call the same function 2-3 times in a row to do it properly. My guess its some server lag (I got 82ms), or it cant handle fast promotes, cant refresh fast enough.
It means I cant do anything about promoting someone up/down 4-5 rank instantly?
example, calling the function:
GpyChangeRank("trial","xxxyyy");
local CYELLOW = "|cFFFFFF00"
local CWHITE = "|cFFFFFFFF"
local CPURPLE = "|cFFD060D0"
local CLRED = "|cFFFF8080"
local CLGREEN = "|cFF80FF80"
local CLGRAY = "|cFFC0C0C0"
local CHAT_END = "|r"
local CMYCOLOR = "|cFFFF8060"
function kiir(kirtxt) -- writes out a text
DEFAULT_CHAT_FRAME:AddMessage(CBLUE.."--- "..CMYCOLOR..kirtxt..CHAT_END);
end
function GpyChangeRank(gpyrank,gpytarget)
if (IsInGuild()) then
gpyrank=string.lower(gpyrank);
local trankname=gpyrank;
local prank=0; -- Player's current rank
local trank=0; -- Targeted (destination) rank
GuildRoster();
local selfname=string.lower(UnitName("player"));
-- if no target specified, it will be the current target...
if (gpytarget==nil or gpytarget=="") then
gpytarget=UnitName("target");
-- if (gpytarget~=nil) then kiir("NO TARGET! Using target: "..gpytarget); end;
end;
if (gpytarget~=nil) then
gpytarget=string.lower(gpytarget);
if (selfname ~= gpytarget) then
-- if (CanGuildDemote() and CanGuildPromote()) then
if (gpyrank ~= "") then
gn = GetNumGuildMembers(true);
-- searching for target's current rank index
for i=1,gn,1 do
gname, grank, grankIndex = GetGuildRosterInfo(i);
gname = string.lower(gname);
if (gname==gpytarget) then
prank=grankIndex+1;
-- kiir(gname.." rank: "..prank..", "..grank);
end;
end;
-- searching for spankrank's index
rn = GuildControlGetNumRanks();
for i=1,rn,1 do
if (string.lower(GuildControlGetRankName(i)) == trankname) then
trank=i;
-- kiir(trankname..": "..i);
end;
end;
if (trank~=0) then
if (prank~=0) then
local rtxt=""; for i=1,rn,1 do rtxt=rtxt.."("..i..")"..GuildControlGetRankName(i).." "; end; kiir(rtxt);
if (prank==trank) then kiir("No need, target already "..CPURPLE..string.upper(trankname).."!"); end;
kiir("Target ("..gpytarget..") current rank: "..prank.." Destination: "..trank);
if (prank<trank) then
kiir(CLRED.."Demoting "..CWHITE..string.upper(gpytarget)..CLRED.." to "..CYELLOW..string.upper(trankname)..CLRED.."...");
local demnum=trank-prank;
for i=1,demnum,1 do GuildDemoteByName(gpytarget); end;
end;
if (prank>trank) then
kiir(CLGREEN.."Promoting "..CWHITE..string.upper(gpytarget)..CLGREEN.." to "..CYELLOW..string.upper(trankname)..CLGREEN.."...");
local pronum=prank-trank;
for i=1,pronum,1 do GuildPromoteByName(gpytarget); end;
end;
else kiir("The target is not in the guild ("..gpytarget..")!"); end;
else kiir("Cant find that rank ("..trankname..")!"); end;
else kiir("You have no rights to Promote/Demote someone!"); end;
else kiir("You cant do this on yourself!"); end;
else kiir("There is no target!"); end;
else kiir("You are not in a GUILD!"); end;
end
The idea is to fast promote/demote someone to a named rank. How it works:
IF I have rights, it first search for the specified rankname through ranks, and saves its rankindex to TRANK. Then searchs the player (xxxyyy) or if its not specified ("") then it will be the one that I have currently selected (targeted). IF hes in the guild, checks its current rank, and saves the rankindex to PRANK. So he must be promoted/demoted from PRANK to TRANK (for example from rank 2 to 6). It checks the difference, and do 9-2 = 4 promote.
But it just do 2-3 promotion then gives 2-1 "Temporary guild error." message. If I do it again then it can do it from 4 to 6, but sometimes reads the current rank wrong. Must call the same function 2-3 times in a row to do it properly. My guess its some server lag (I got 82ms), or it cant handle fast promotes, cant refresh fast enough.
It means I cant do anything about promoting someone up/down 4-5 rank instantly?
example, calling the function:
GpyChangeRank("trial","xxxyyy");
local CYELLOW = "|cFFFFFF00"
local CWHITE = "|cFFFFFFFF"
local CPURPLE = "|cFFD060D0"
local CLRED = "|cFFFF8080"
local CLGREEN = "|cFF80FF80"
local CLGRAY = "|cFFC0C0C0"
local CHAT_END = "|r"
local CMYCOLOR = "|cFFFF8060"
function kiir(kirtxt) -- writes out a text
DEFAULT_CHAT_FRAME:AddMessage(CBLUE.."--- "..CMYCOLOR..kirtxt..CHAT_END);
end
function GpyChangeRank(gpyrank,gpytarget)
if (IsInGuild()) then
gpyrank=string.lower(gpyrank);
local trankname=gpyrank;
local prank=0; -- Player's current rank
local trank=0; -- Targeted (destination) rank
GuildRoster();
local selfname=string.lower(UnitName("player"));
-- if no target specified, it will be the current target...
if (gpytarget==nil or gpytarget=="") then
gpytarget=UnitName("target");
-- if (gpytarget~=nil) then kiir("NO TARGET! Using target: "..gpytarget); end;
end;
if (gpytarget~=nil) then
gpytarget=string.lower(gpytarget);
if (selfname ~= gpytarget) then
-- if (CanGuildDemote() and CanGuildPromote()) then
if (gpyrank ~= "") then
gn = GetNumGuildMembers(true);
-- searching for target's current rank index
for i=1,gn,1 do
gname, grank, grankIndex = GetGuildRosterInfo(i);
gname = string.lower(gname);
if (gname==gpytarget) then
prank=grankIndex+1;
-- kiir(gname.." rank: "..prank..", "..grank);
end;
end;
-- searching for spankrank's index
rn = GuildControlGetNumRanks();
for i=1,rn,1 do
if (string.lower(GuildControlGetRankName(i)) == trankname) then
trank=i;
-- kiir(trankname..": "..i);
end;
end;
if (trank~=0) then
if (prank~=0) then
local rtxt=""; for i=1,rn,1 do rtxt=rtxt.."("..i..")"..GuildControlGetRankName(i).." "; end; kiir(rtxt);
if (prank==trank) then kiir("No need, target already "..CPURPLE..string.upper(trankname).."!"); end;
kiir("Target ("..gpytarget..") current rank: "..prank.." Destination: "..trank);
if (prank<trank) then
kiir(CLRED.."Demoting "..CWHITE..string.upper(gpytarget)..CLRED.." to "..CYELLOW..string.upper(trankname)..CLRED.."...");
local demnum=trank-prank;
for i=1,demnum,1 do GuildDemoteByName(gpytarget); end;
end;
if (prank>trank) then
kiir(CLGREEN.."Promoting "..CWHITE..string.upper(gpytarget)..CLGREEN.." to "..CYELLOW..string.upper(trankname)..CLGREEN.."...");
local pronum=prank-trank;
for i=1,pronum,1 do GuildPromoteByName(gpytarget); end;
end;
else kiir("The target is not in the guild ("..gpytarget..")!"); end;
else kiir("Cant find that rank ("..trankname..")!"); end;
else kiir("You have no rights to Promote/Demote someone!"); end;
else kiir("You cant do this on yourself!"); end;
else kiir("There is no target!"); end;
else kiir("You are not in a GUILD!"); end;
end