Trying to learn pawn... question about this piece of script
#1

Ok, so first let me show u the script that I copied from a site

public OnPlayerDisconnect(playerid, reason)
{
new pName[MAX_PLAYER_NAME], string[56];
GetPlayerName(playerid, pName, sizeof(pName));
switch(reason)
{
case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pName);
case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pName);
case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pName);
}
SendClientMessageToAll(0xAAAAAAAA, string);
return 1;
}

Ok, so I am just going to tell you what I am guessing, please tell me if I am wrong or right.

1. the line "public OnPlayerDisconnect(playerid, reason)" is basically saying that whatever is written after this happens happens when a player disconnects
2. the line "new pName[MAX_PLAYER_NAME], string[56];" sets pName so that from here on whenever u use pName (don't know how to use it though) it replaces pName with the players name
3. the line "GetPlayerName(playerid, pName, sizeof(pName)); " is somehow linked to the line right before it...
4. the line "switch(reason)" no idea
5. the case 0, 1 and 2 is used so that later on, should A happen, go to case 0, should B happen, go to case 1
6 sendclientmessagetoall pretty easy to guess, just sends a message to every one
7. can someone please explain the "string" at the end of "SendClientMessageToAll(0xAAAAAAAA, string);"


Thanks so much for ur help, im trying to learn pawno and from past experience with languages it's best to teach ur self
Reply
#2

1. Yes
2. This creates a new string called "pName" that the players name will be stored in, and creates a string which the message will be sent in.
3. The GetPlayerName Stores the players name into the "pName" string.
4. the switch(blah) will create a switch which has case 0: case 1: case:2 etc more on switches here
5. Your right, it will see if the player either left normaly, crashed/timedout or was kicked from the server and put it into the blank string.
6. Again yes
7. This will send the message that was put into "string" in question 5.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)