08.02.2016, 21:57
(Note!: My mainlanguage is german.)
"Function" your variable-names - Make your life easier!
Because there are many guys who write there code like the example[1] below, i now want to tell you an easier way to done.
[1] the example - Actualy used.
You now always have to repeat this wherever you want to add the rankname. /ban command, /kick command, maybe a /say command and freaking everywhere, where you want to show the current rankname.
With a easy method you are able to reduce your needed code and to make your life easier. Just check the example[2]!
[2] the example - Should be used.
By adding this in your script, you are able to use this everywhere. For some scripting examples watch the example[3].
[3] the example - How it works
You can use this for every.
Examples: GetPlayerFactionName | GetPlayerVehicleName | GetPlayerAnyThingName ...
Also it dosnt have to be a player-based function. You can use this for everything.
How does it works?
#Best Regards.
Because there are many guys who write there code like the example[1] below, i now want to tell you an easier way to done.
[1] the example - Actualy used.
PHP Code:
if(PlayerInfo[playerid][pAdmin] == 1)
{
SendClientMessage(playerid, YOUR_COLOR, "You`re: Moderator");
}
else if(PlayerInfo[playerid][pAdmin] == 2)
{
SendClientMessage(playerid, YOUR_COLOR, "You`re: Supporter");
}
else if(PlayerInfo[playerid][pAdmin] == 3)
{
SendClientMessage(playerid, YOUR_COLOR, "You`re: Administrator");
}
Result for Rank 2: "You`re Supporter"
With a easy method you are able to reduce your needed code and to make your life easier. Just check the example[2]!
[2] the example - Should be used.
PHP Code:
GetPlayerAdminName(playerid)
{
new result[14];
switch(PlayerInfo[playerid][pAdmin])
{
case 0:{result="No Admin";}
case 1:{result="Moderator";}
case 2:{result="Supporter";}
case 3:{result="Administrator";}
}
return result;
}
[3] the example - How it works
PHP Code:
new string[64];
format(string,sizeof(string),"You`re: %s",GetPlayerAdminName(playerid));
SendClientMessage(playerid, YOUR_COLOR, string);
Result for Rank 2: "You`re: Supporter"
Examples: GetPlayerFactionName | GetPlayerVehicleName | GetPlayerAnyThingName ...
Also it dosnt have to be a player-based function. You can use this for everything.
How does it works?
PHP Code:
GetPlayerAdminName(playerid) //Giving the function a name. Can be anything.
{
new result[14]; //creating a string where the output will be stored in.
switch(PlayerInfo[playerid][pAdmin]) //switching the variable. In this case we switch the players adminrank.
{
case 0:{result="No Admin";}//in the case the player got the adminrank zero, we would call him "No Admin"
case 1:{result="Moderator";}//in the case 1, moderator.
case 2:{result="Supporter";}//etc...
case 3:{result="Administrator";}
}
return result;//after the switch is done, and the "result" is now filled with the players adminname, we return the result.
}