SA-MP Forums Archive
Events with "player array" instead of playerid - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Events with "player array" instead of playerid (/showthread.php?tid=663588)



Events with "player array" instead of playerid - PeanutButter - 06.02.2019

Hello, I haven't used Pawn in a very long time so unfortunately I've forgotten a lot of things.
I was wondering whether it's a bad idea to code like this:


Instead of having a playerid as a parameter, like this

PHP код:
enum e_pvars Name[MAX_PLAYER_NAME] };
new 
PlayerVars[MAX_PLAYERS][e_pvars];
public 
OnPlayerConnect(playerid// like this
{
 
    new 
name[MAX_PLAYER_NAME 1];
    
GetPlayerName(playeridnamesizeof(name));
    
SendClientMessageToAll(YELLOWname);
 
    return 
1;

I create a new event that uses a player array containing information about that player, like this



PHP код:
New_OnplayerConnect(Player[]) // like this
{
    
SendClientMessageToAll(YELLOWPlayer[Name]);
}
public 
OnPlayerConnect(playerid)
{
    
GetPlayerName(playeridPlayerVars[playerid][Name], MAX_PLAYER_NAME);
    
New_OnplayerConnect(PlayerVars[playerid]);
    return 
1;

What are the disadvantages of doing that?


Re: Events with "player array" instead of playerid - Robertsamp - 06.02.2019

I think u make the script a little slower, because you call a lower function that calls the main function.
Why not using the principal function?


Re: Events with "player array" instead of playerid - PeanutButter - 06.02.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
And you will need to collate and pass around all that data, even if you never use it.
I thought arrays are always passed by reference? Does it really affect the performance in a scenerio where those PlayerVars are going to be used anyway?