Auto Spawn
#1

Alright, so I am trying to remove the spawn button and auto spawn the player after login, I have searched many threads, some of them had no effect and some had effect but not what exactly I want.

so, what I want is: When the player logs in he automatically spawns.

My codes for the automatic spawn and removing buttons:

pawn Код:
public OnPlayerRequestClass(playerid,classid)
{
    SetSpawnInfo(playerid, TEAM_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    SpawnPlayer(playerid);
    return 1;
}
pawn Код:
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;
}
pawn Код:
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;
}
pawn Код:
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;
}
The current problem is that it removes the spawn button and these thingys and it spawns the player, but it doesnt follow this
pawn Код:
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 );
    }
Reply
#2

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;
}
Then under your OnPlayerConnect (do not get this confused with the new public created above OnPlayerConnected) call your new public like so:

Код:
OnPlayerConnect(playerid)
{
	SetTimerEx("OnPlayerConnected",  5000, false, "i", playerid)
	// All your other OnPlayerConnect code.
	return 1;
}
I believe you need to wait as the player connects before you can spawn them as if you force spawn directly under OnPlayerConnect it may not work as the player may still be in the process of connecting.

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.
Reply
#3

Quote:
Originally Posted by MEW273
Посмотреть сообщение
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;
}
Then under your OnPlayerConnect (do not get this confused with the new public created above OnPlayerConnected) call your new public like so:

Код:
OnPlayerConnect(playerid)
{
	SetTimerEx("OnPlayerConnected",  5000, false, "i", playerid)
	// All your other OnPlayerConnect code.
	return 1;
}
I believe you need to wait as the player connects before you can spawn them as if you force spawn directly under OnPlayerConnect it may not work as the player may still be in the process of connecting.

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.
Thanks but, it is still the same buddy.
Reply
#4

Quote:
Originally Posted by Maro06
Посмотреть сообщение
Thanks but, it is still the same buddy.
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.
Reply
#5

Quote:
Originally Posted by MEW273
Посмотреть сообщение
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.
Works now, much appreciated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)