new PlayerDeaths[MAX_PLAYERS] rep ++
#1

Код:
new PlayerDeaths[MAX_PLAYERS];
new PlayerKills[MAX_PLAYERS];
What is the meaning of this?I saw this in wiki.
And what is 'new' here?I saw it in a lot of tutorials,scripts etc.I didn't get what is it.
Also what is 'MAX_PLAYERS'?
Basically just explain each and everything there in that code please.
And is this related to enums in anyway?
Reply
#2

this is varible example when player dies
onplayerdeath

pawn Код:
PlayerDeaths[playerid]++;
PlayerKills[killerid]++;
it add to ini file that player died few times and killed few times it show the string in ini file if player logged
Reply
#3

That creates a variable for every player that can join the server and connect it to the playerid.
The "new" creates the variable. ";" ends the line and defines the start of a new one.

With this you could for example do:
Код:
public OnPlayerDeath(playerid, killerid, reason)
{
        PlayerDeaths[playerid] ++;
        PlayerKills[killerid] ++; // ++ means add 1 to the current value.
	return 1;
}
And no this has nothing to do with enums but it can also be done with a enum.
The current way the value will reset on server restart and needs to be de reset everytime a player disconnects or joins.
Код:
public OnPlayerConnect(playerid)
{
     PlayerDeaths[playerid] = 0;
     PlayerKills[playerid] = 0;
     return 1;
}
Enum example:
Код:
enum pInfo
{
    pDeaths,
    pKills
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerDeath(playerid, killerid, reason)
{
        PlayerInfo[playerid][pDeaths] ++;
        PlayerInfo[killerid][pKills] ++; // ++ means add 1 to the current value.
	return 1;
}
Reply
#4

@Facerafter
I understood what the ++ means now.Thanks!
So by MAX_PLAYER means it just connects each player to any playerid?Right?
What happens if I don't put 'new PlayerDeaths[MAX_PLAYERS]' before Public OnPlayerDeath?Like this:
Код:
new PlayerDeaths[MAX_PLAYERS];
new PlayerKills[MAX_PLAYERS]

public OnPlayerDeath(playerid, killerid, reason)
{
        PlayerDeaths[playerid] ++;
        PlayerKills[killerid] ++; // ++ means add 1 to the current value.
	return 1;
}
From these codes what if this line isn't there
Код:
new PlayerDeaths[MAX_PLAYERS];
new PlayerKills[MAX_PLAYERS]
Reply
#5

There would be errors.
Because than you would be trying to assign a value to a variable that doesn't exist.

MAX_PLAYERS is a value defined with a_samp.inc & your server config
So if the max amount of players on your server can be 50.
with
Код:
new PlayerDeaths[MAX_PLAYERS];
You would create a variable for those 50 slots.
If you have 50 player slots you could also do this.
Код:
new PlayerDeaths[50];
but because the MAX_PLAYERS is a variable which changes dynamicly its the most used.
So if in the server config the max players is 50 now it will create 50 variables.
If tomorrow you change the max players to 100 the variable will also change automaticlly to 100
Reply
#6

Okay so MAX_PLAYERS I understood.
This part from your previous reply.I didn't get it.

"The current way the value will reset on server restart and needs to be de reset everytime a player disconnects or joins.
Код:
pu"blic OnPlayerConnect(playerid)
{
     PlayerDeaths[playerid] = 0;
     PlayerKills[playerid] = 0;
     return 1;
}
Does this mean if I put this code in my GM my stats will be reset to 0 each time I login?Even if my username is same and registered?
Reply
#7

no you dont need to reset it.
Reply
#8

Like I said
Код:
new PlayerDeaths[MAX_PLAYERS];
creates variables for every player slot in your server.

Image that im playerid 0 and I die twice and than leave the server.
This would cause that
Код:
 PlayerDeaths[playerid] // Playerid = 0
has a value of 2.

Shortly after that you join and you became playerid 0 that would mean that the value of 2 would still be connected to playerid 0. That would cause that you have 2 deaths while those deaths came from me.

Код:
new PlayerDeaths[MAX_PLAYERS];
Assigns a variable to every player id not the player itself and only resets at server restart.




Quote:
Originally Posted by UltraScripter
Посмотреть сообщение
no you dont need to reset it.
Please don't respond, you are only confusing him.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)