public OnPlayerRequestClass(playerid,classid)
{
SetSpawnInfo(playerid, TEAM_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
new string[120];
if(roundStarted == 0)
{
SetSpawnInfo(playerid, TEAM_HUMANS, 26, -2260.7219, 686.1232 , 49.2969, 0, 10, 1, 23, 200, 25, 200);
GetPlayerName( playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof(string),"{00FF51}[HUMAN BORN]{FFFFFF} A new human is now born, his name is {FFEA00}%s", pName);
SendClientMessageToAll(-1, string );
}
if(roundStarted != 0)
{
SetSpawnInfo(playerid, TEAM_ZOMBIES, 26, -2260.7219, 686.1232 , 49.2969, 0, 10, 1, 23, 200, 25, 200);
GetPlayerName( playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof(string),"{E00000}[ZOMBIE BORN]{FFFFFF} A new zombie is now born, his name is {E00000}%s", pName);
SendClientMessageToAll(-1, string );
}
return 1;
}
public OnPlayerConnect(playerid)
{
new query[128]; //We use this variable to format our query
GetPlayerName(playerid, Name[playerid], 24); //Getting player's name
GetPlayerIp(playerid, IP[playerid], 16); //Getting layer's IP
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
// - We use mysql_format instead of format because we can use an %e specifier. %e specifier escapes a string so we can avoid sql injection which means we don't have to use mysql_real_escape_string
// - Formatting our query; SELECT `Password`, `ID` FROM `players` WHERE `Username`='%e' means we are selecting a Password and ID's column in the table that has player's name in Username column.
// - LIMIT 1; we only need 1 result to be shown
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
//lets execute the formatted query and when the execution is done, a callback OnAccountCheck will be called
//You can name the callback however you like
[B]TogglePlayerSpectating(playerid, 1)[/B];
return 1;
}
public OnAccountLoad(playerid)
{
pInfo[playerid][Admin] = cache_get_field_content_int(0, "Admin"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
pInfo[playerid][VIP] = cache_get_field_content_int(0, "VIP"); //Above
pInfo[playerid][Money] = cache_get_field_content_int(0, "Money");//Above
pInfo[playerid][posX] = cache_get_field_content_float(0, "PosX");//Above. Since player's position is a float, we use cache_get_field_content_float
pInfo[playerid][posY] = cache_get_field_content_float(0, "PosY");//Above
pInfo[playerid][posZ] = cache_get_field_content_float(0, "PosZ");//Above
GivePlayerMoney(playerid, pInfo[playerid][Money]);//Let's set their money
//For player's position, set it once they spawn(OnPlayerSpawn)
SendClientMessage(playerid, -1, "Successfully logged in"); //tell them that they have successfully logged in
TogglePlayerSpectating(playerid, 0);
SpawnPlayer(playerid);
return 1;
}
if(roundStarted == 0)
{
SetSpawnInfo(playerid, TEAM_HUMANS, 26, -2260.7219, 686.1232 , 49.2969, 0, 10, 1, 23, 200, 25, 200);
GetPlayerName( playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof(string),"{00FF51}[HUMAN BORN]{FFFFFF} A new human is now born, his name is {FFEA00}%s", pName);
SendClientMessageToAll(-1, string );
}
if(roundStarted != 0)
{
SetSpawnInfo(playerid, TEAM_ZOMBIES, 26, -2260.7219, 686.1232 , 49.2969, 0, 10, 1, 23, 200, 25, 200);
GetPlayerName( playerid, pName, MAX_PLAYER_NAME);
format(string, sizeof(string),"{E00000}[ZOMBIE BORN]{FFFFFF} A new zombie is now born, his name is {E00000}%s", pName);
SendClientMessageToAll(-1, string );
}
forward OnPlayerConnected(playerid); public OnPlayerConnected(playerid) { SetSpawnInfo(playerid, TEAM_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); return 1; }
OnPlayerConnect(playerid) { SetTimerEx("OnPlayerConnected", 5000, false, "i", playerid) // All your other OnPlayerConnect code. return 1; }
Hi Maro06,
I would take your code under OnPlayerRequestClass and create a new public like so: Код:
forward OnPlayerConnected(playerid); public OnPlayerConnected(playerid) { SetSpawnInfo(playerid, TEAM_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); return 1; } Код:
OnPlayerConnect(playerid) { SetTimerEx("OnPlayerConnected", 5000, false, "i", playerid) // All your other OnPlayerConnect code. return 1; } Give this a try and let me know if you run into any errors - there may be a better way of doing this, but I was having the same problem and searched and searched for solutions and this is the only working method I could find. |
Sorry to hear that. I'm not sure if I can help any further unfortunately.
I have placed the code I use on Pastebin, here's the link if you want to take a look: http://pastebin.com/NBERyW4A With the above when I connect to the server it spawns me after 5 seconds (but I cannot control the character). You could easily change it so you can control the character by changing TogglePlayerControllable(playerid, 0); to TogglePlayerControllable(playerid, 1); Hope this helps. |