CMD problem -
DarkLored - 19.02.2014
Well i made factions but now i have problems with /finvite and /fkick that i made so basiclly when i do /finvite it auto adds the player without asking him if he accepts it or not
and /fkick command if you are in one faction and the other player is in another faction you can kick the player that is in a different faction
here is my code
/finvite
pawn Код:
CMD:finvite(playerid,params[])
{
new factionid;
if(pInfo[playerid][Faction] == 1)
{
new targetid, targetname[24], playername[24], string[128]; //Create the variables
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
pInfo[targetid][Faction] = 1; //Sets their faction variable to 0 (civilian)
pInfo[targetid][Rank] = 1; //Sets their rank variable to 0 (no rank)
}
if(pInfo[playerid][Faction] == 2)
{
new targetid, targetname[24], playername[24], string[128]; //Create the variables
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
pInfo[targetid][Faction] = 2; //Sets their faction variable to 0 (civilian)
pInfo[targetid][Rank] = 1; //Sets their rank variable to 0 (no rank)
}
if(pInfo[playerid][Faction] == 3)
{
new targetid, targetname[24], playername[24], string[128]; //Create the variables
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
pInfo[targetid][Faction] = 3; //Sets their faction variable to 0 (civilian)
pInfo[targetid][Rank] = 1; //Sets their rank variable to 0 (no rank)
}
if(pInfo[playerid][Faction] == 4)
{
new targetid, targetname[24], playername[24], string[128]; //Create the variables
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
pInfo[targetid][Faction] = 4; //Sets their faction variable to 0 (civilian)
pInfo[targetid][Rank] = 1; //Sets their rank variable to 0 (no rank)
}
return 1; //Returns a value
}
/fkick code
pawn Код:
CMD:fkick(playerid, params[]) //Format to create a command
{ //Open bracket
new id, string[128];
if(pInfo[playerid][Faction] == 1 && pInfo[playerid][Rank] == 6)
{
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"Usage: /fkick [playerid]");
SendClientMessage(id,COLOR_RED,"You have been kicked from RAF squad!");
format(string,sizeof(string),"You have kicked %s(%d) from the squad",GetName(id),id);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
pInfo[id][Faction] = 0;
pInfo[id][Rank] = 0;
}
return 1;
} //Closed
Re: CMD problem -
Golimad - 19.02.2014
pawn Код:
CMD:fkick(playerid, params[]) //Format to create a command
{ //Open bracket
new id, string[128];
if(pInfo[playerid][Rank] == 6)
{
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"Usage: /fkick [playerid]");
SendClientMessage(id,COLOR_RED,"You have been kicked from RAF squad!");
format(string,sizeof(string),"You have kicked %s(%d) from the squad",GetName(id),id);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
if(pInfo[id][Faction] == pInfo[playerid][Faction])
{
pInfo[id][Faction] = 0;
pInfo[id][Rank] = 0;
}
else return make some code here to send playerid a message ( he isnt in your faction )
}
return 1;
} //Closed
Use same principal for /finvite .. If it works, looking forward your +rep
Re: CMD problem -
MattTucker - 19.02.2014
pawn Код:
new finvited[MAX_PLAYERS]; // To store the player's ID
new fnumber[MAX_PLAYERS]; // For storing the faction number that he was invited to join
new finviter[MAX_PLAYERS]; // To send a client message for him to tell that the player accepted his invite
// All of the lines above can be placed ontop of the script - not the very top like after the enums.
CMD:finvite(playerid,params[])
{
new factionid,targetid, targetname[24], playername[24], string[128]; // Why not creating all of the "new"s here? :D
switch(PlayerInfo[playerid][Faction])
{
case 1: // Switch is faster than "if"
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad! Use /acceptfaction", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
// pInfo[targetid][Faction] = 1; Instead of those two lines we will get store some variables for use in other commands
// pInfo[targetid][Rank] = 1; (I explain better with commands)
finvited[targetid] = targetid;
fnumber[targetid] = 1;
}
case 2:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = targetid;
fnumber[targetid] = 2;
}
case 3:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = targetid;
fnumber[targetid] = 3;
}
case 4:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = targetid;
fnumber[targetid] = 4;
}
}
return 1; //Returns a value
}
CMD:acceptfaction(playerid, params[])
{
new string[100], name[MAX_PLAYER_NAME], name1[MAX_PLAYER_NAME]; // you can use this to make sure it's all working well
if(finvite[playerid] > -1) // Normally in any kind of server the player ids start from 0 - 1 - 2 - 3 -4 so on
{
GetPlayerName(finviter, name, sizeof(name));
GetPlayerName(finvited, name1, sizeof(name1));
PlayerInfo[playerid][Faction] = fnumber;
format(string, sizeof(string), "You have accepted %s request to join faction number %d",name, fnumber);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "%s has accepted your invite to join your faction!", name1);
SendClientMessage(finviter, -1, string);
}
return 1;
}
CMD:fkick(playerid, params[]) //Format to create a command
{ //Open bracket
new id, string[128];
if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"Usage: /fkick [playerid]");
// I moved the sscanf line to above the inner code to be able to compare the targetid's faction and the playerid's faction
// They are equal, the player gets kicked
if(pInfo[playerid][Faction] == PlayerInfo[id][Faction] && pInfo[playerid][Rank] == 6)
{
SendClientMessage(id,COLOR_RED,"You have been kicked from RAF squad!");
format(string,sizeof(string),"You have kicked %s(%d) from the squad",GetName(id),id);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
pInfo[id][Faction] = 0;
pInfo[id][Rank] = 0;
}
else
{
SendClientMessage(playerid, -1, "Player is not in you faction!");
return 1;
}
return 1;
} //Closed
You can try this hope it works out well for you as I did it in a hurry, if you find any bugs just notify me I will gladly fix/edit it.
EDIT: I have placed for you all commands /fkick /finvite /acceptfaction and some explaination inside the code and changed the 'if' statements as 'switch' is faster.
Re: CMD problem -
DarkLored - 19.02.2014
i get this error
pawn Код:
TDMv1.0.pwn(1418) : error 006: must be assigned to an array
this is the line
pawn Код:
pInfo[playerid][Faction] = fnumber;
Re: CMD problem -
MattTucker - 19.02.2014
Oh yes I am extremely sorry remove the '[MAX_PLAYERS]' from the 'fnumber' so that it would be
Again if any bugs, just inform me and sorry, I'm an amatuer scripter.
Re: CMD problem -
DarkLored - 19.02.2014
here is a bug on this line
pawn Код:
format(string, sizeof(string), "You have accepted %s request to join faction number %d",name, fnumber);
SendClientMessage(playerid, -1, string);
when i get invited by someone and then accept it, it says that i have been invited by DarkyBot which is my bot not the player that sended it to me
Re: CMD problem -
MattTucker - 19.02.2014
pawn Код:
new finvited[MAX_PLAYERS]; // To store the player's ID
new fnumber[MAX_PLAYERS]; // For storing the faction number that he was invited to join
new finviter; // To send a client message for him to tell that the player accepted his invite
new gotinvited; // The name is pretty obvious
// All of the lines above can be placed ontop of the script - not the very top like after the enums.
CMD:finvite(playerid,params[])
{
new factionid,targetid, targetname[24], playername[24], string[128]; // Why not creating all of the "new"s here? :D
switch(PlayerInfo[playerid][Faction])
{
case 1: // Switch is faster than "if"
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad! Use /acceptfaction", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = 1;
fnumber[targetid] = 1;
finviter = playerid;
gotinvited = targetid;
}
case 2:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = 1;
fnumber[targetid] = 2;
finviter = playerid;
gotinvited = targetid;
}
case 3:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = 1;
fnumber[targetid] = 3;
finviter = playerid;
gotinvited = targetid;
}
case 4:
{
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "Usage: /finvite [playerid/partofname]"); //Sends message if they do not type something in for the targetid/name
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Invalid playerid!"); //Sends a message if the player isn't connected
if(pInfo[playerid][Adminlevel] != 5 && pInfo[playerid][Rank] != 6) return SendClientMessage(playerid, -1, "You are not a high enough admin or you aren't the leader!"); //Sends a message if they aren't the leader of the faction and if they aren't admin
GetPlayerName(targetid, targetname, sizeof(targetname)); //Stores the targetid's name in the targetname variable
GetPlayerName(playerid, playername, sizeof(playername)); //Stores the playerid's name in the playername variable
format(string, sizeof(string), "You have been invited to %s squad!", targetname);//Formats the message that will be sent to you (the player)
SendClientMessage(playerid, -1, string);//Sends the message that is formatted above to the playerid in a random color
finvited[targetid] = 1;
fnumber[targetid] = 4;
finviter = playerid;
gotinvited = targetid;
}
}
return 1; //Returns a value
}
CMD:acceptfaction(playerid, params[])
{
new string[100], name[MAX_PLAYER_NAME], name1[MAX_PLAYER_NAME]; // you can use this to make sure it's all working well
if(finvited[playerid] == 1) // Got a better idea
{
GetPlayerName(finviter, name, sizeof(name));
GetPlayerName(gotinvited, name1, sizeof(name1));
PlayerInfo[playerid][Faction] = fnumber;
format(string, sizeof(string), "You have accepted %s invitation to join faction number %d.", name, fnumber);
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "%s has accepted your invitation to join your faction.", name2);
SendClientMessage(finviter, -1, string);
finvited[playerid] = 0;
}
return 1;
}
Re-wrote some stuff... Hope no other bugs happen.
Re: CMD problem -
DarkLored - 19.02.2014
its the same problem as before it says the my npc invited me
Re: CMD problem -
MattTucker - 19.02.2014
I'm sorry but I don't actually know why that's happening.
Re: CMD problem -
DarkLored - 19.02.2014
Oh i know why its because it counts the player as a npc i need to do when the player is using that command so it will say that he is not a npc thanks for help +1 to both