/invite and /acceptinvite not working :/ -
arjanforgames - 15.07.2013
This is my /invite code.
pawn Код:
CMD:invite(playerid, params[])
{
new player;
if(sscanf(params, "u", player)) return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /invite [playerid / name]");
if(player != INVALID_PLAYER_ID)
{
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 1)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 1;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 2)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 2;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 3)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 3;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 4)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 4;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 5)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 5;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 6)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 6;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
if(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 7)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = 7;
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
}
else
{
SendClientMessage(playerid, -1, "* The player is not online.");
}
return 1;
}
But when I do /acceptinvite it says: "You dont have a pending invitation"
pawn Код:
CMD:acceptinvite(playerid, params[])
{
new player;
if(player != INVALID_PLAYER_ID)
{
new string[128];
new aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
if(invitedFor[playerid] == 1)
{
PlayerInfo[playerid][pTeam] = 1;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
if(invitedFor[playerid] == 2)
{
PlayerInfo[playerid][pTeam] = 2;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
if(invitedFor[playerid] == 3)
{
PlayerInfo[playerid][pTeam] = 3;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
if(invitedFor[playerid] == 4)
{
PlayerInfo[playerid][pTeam] = 4;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
if(invitedFor[playerid] == 5)
{
PlayerInfo[playerid][pTeam] = 5;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
if(invitedFor[playerid] == 6)
{
PlayerInfo[playerid][pTeam] = 6;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
if(invitedFor[playerid] == 7)
{
PlayerInfo[playerid][pTeam] = 7;
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
}
else
{
SendClientMessage(playerid, -1, "You dont have a pending invitation!");
}
}
else
{
SendClientMessage(playerid, -1, "* The player is not online.");
}
return 1;
}
Defines:
pawn Код:
new invitedFor[MAX_PLAYERS];
Re: /invite and /acceptinvite not working :/ -
Misiur - 15.07.2013
Well, you need to learn about elseif. Currently if the invitedFor isn't equal 7, you'll get error
BTW: Your code can be a little shorter (which also includes the fix)
pawn Код:
CMD:invite(playerid, params[])
{
new player;
if(sscanf(params, "u", player)) return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /invite [playerid / name]");
if(player != INVALID_PLAYER_ID)
{
if(PlayerInfo[playerid][pLeader] == 1 && 1 <= PlayerInfo[playerid][pTeam] <= 7)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = PlayerInfo[playerid][pTeam];
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
}
else
{
SendClientMessage(playerid, -1, "* The player is not online.");
}
return 1;
}
CMD:acceptinvite(playerid, params[])
{
new player;
if(player != INVALID_PLAYER_ID)
{
new string[128];
new aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
if(1 <= invitedFor[playerid] <= 7)
{
PlayerInfo[playerid][pTeam] = invitedFor[playerid];
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
invitedFor[playerid] = 0;
} else
{
SendClientMessage(playerid, -1, "You dont have a pending invitation!");
}
}
else
{
SendClientMessage(playerid, -1, "* The player is not online.");
}
return 1;
}
Re: /invite and /acceptinvite not working :/ -
arjanforgames - 15.07.2013
Only the leader of pTeam == 1 can invite. If I make myself leader of 2/3/4/5/6/7 it doesnt work.
Re: /invite and /acceptinvite not working :/ -
Misiur - 15.07.2013
pLeader indicates that player is a leader, or holds number of team of which he's leader of?
Re: /invite and /acceptinvite not working :/ -
arjanforgames - 15.07.2013
pLead indicates if his is a leader so: 0 or 1 (false or true)
Thats why you need to use (if you want to check if someone is leader of faction 2):
pawn Код:
If(PlayerInfo[playerid][pLeader] == 1 && PlayerInfo[playerid][pTeam] == 2)
Re: /invite and /acceptinvite not working :/ -
Misiur - 15.07.2013
If you are using exactly my code, this shouldn't happen.
Let's debug it
pawn Код:
//Find
if(PlayerInfo[playerid][pLeader] == 1 && 1 <= PlayerInfo[playerid][pTeam] <= 7)
//Add line before
//1. If you have access to console:
printf("Is leader: %d, team number: %d, expression result: %d", PlayerInfo[playerid][pLeader], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pLeader] == 1 && 1 <= PlayerInfo[playerid][pTeam] <= 7);
//2. Otherwise
new debug[64];
format(debug, sizeof debug, "Is leader: %d, team number: %d, expression result: %d", PlayerInfo[playerid][pLeader], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pLeader] == 1 && 1 <= PlayerInfo[playerid][pTeam] <= 7);
SendClientMessage(playerid, -1, debug);
Then run the invite command
@down:
Do what I said in this post
Re: /invite and /acceptinvite not working :/ -
arjanforgames - 15.07.2013
I have this now:
pawn Код:
CMD:invite(playerid, params[])
{
new player;
if(sscanf(params, "u", player)) return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /invite [playerid / name]");
if(player != INVALID_PLAYER_ID)
{
if(PlayerInfo[playerid][pLeader] == 1 && 1 <= PlayerInfo[playerid][pTeam] <= 7)
{
new string[128];
new stringtarget[128];
new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
GetPlayerName(player, pName, MAX_PLAYER_NAME);
invitedFor[player] = PlayerInfo[playerid][pTeam];
format(string, sizeof(string), "You have invited %s to join %s", pName, FactionStatus(playerid));
format(stringtarget, sizeof(stringtarget), "You have been invited to join %s. Type "COL_RED"/acceptinvite"COL_WHITE" to join!", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(playerid, COLOR_LIGHTBLUE, stringtarget);
}
else
{
SendClientMessage(playerid, -1, "* Only leaders can use this command!");
}
}
else
{
SendClientMessage(playerid, -1, "* The player is not online.");
}
return 1;
}
And
pawn Код:
CMD:acceptinvite(playerid, params[])
{
new player;
if(player != INVALID_PLAYER_ID)
{
new string[128];
new aName[MAX_PLAYER_NAME];
GetPlayerName(playerid, aName, MAX_PLAYER_NAME);
if(1 <= invitedFor[playerid] <= 7)
{
PlayerInfo[playerid][pTeam] = invitedFor[playerid];
PlayerInfo[playerid][pLeader] = 0;
PlayerInfo[playerid][pRank] = 1;
format(string, sizeof(string), "You have accepted the invitation and you are now part of %s", FactionStatus(playerid));
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
invitedFor[playerid] = 0;
} else
{
SendClientMessage(playerid, -1, "You dont have a pending invitation!");
}
}
else
{
SendClientMessage(playerid, -1, "* The player is not online.");
}
return 1;
}
Only when im in faction 1 and I do: /invite arjan I get "bla bla /acceptinvite".
All other number of factions (2/3/4/5/6/7) give me: "* Only leaders can use this command"