SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 08/02/2016, 10:57 PM   #1
Big Clucker
Join Date: Nov 2014
Posts: 153
Reputation: 45
Default "Function" your variable-names - Make your life easier!

(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.
PHP Code:
if(PlayerInfo[playerid][pAdmin] == 1)
SendClientMessage(playeridYOUR_COLOR"You`re: Moderator");
else if(
PlayerInfo[playerid][pAdmin] == 2)
SendClientMessage(playeridYOUR_COLOR"You`re: Supporter");
else if(
PlayerInfo[playerid][pAdmin] == 3)
SendClientMessage(playeridYOUR_COLOR"You`re: Administrator");

Result for Rank 2"You`re Supporter" 

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.
PHP Code:
0:{result="No Admin";}

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
PHP Code:
new string[64];
format(string,sizeof(string),"You`re: %s",GetPlayerAdminName(playerid));

Result for Rank 2"You`re: Supporter" 

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?
PHP Code:
GetPlayerAdminName(playerid//Giving the function a name. Can be anything.
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.
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";}
result;//after the switch is done, and the "result" is now filled with the players adminname, we return the result.

#Best Regards.
GangstaSunny is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Expecting "]" found ";" Doesn't Make Sense Nathan_Taylor Scripting Help 5 03/05/2014 12:55 AM
Deciding how to store "mission info" driftg0d Scripting Help 1 09/01/2014 03:46 AM
5 Dialog errors - Input line too long, undefined symbol "t","is" and "only" Deal-or-die Scripting Help 6 01/05/2012 01:08 PM
"Slight homing", make a missile "Slightly!" home a vehicle. Donya Help Archive 4 11/06/2011 10:20 PM

All times are GMT. The time now is 01:55 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.