Auto spawn on public OnPlayerSpawn(playerid)
#1

I want it to auto spawn when the player is registered. It comes to where we can click at << >> "SPAWN" and i want it so that it skips that, so that we dont have to click spawn, how?
Reply
#2

Put that under OnPlayerConnect

Код:
SpawnPlayer(playerid);
Or check this topic - https://sampforum.blast.hk/showthread.php?tid=310992
Reply
#3

How do i add it correctly with this?


public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave");
}
else
{
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
}
return 1;
}

Thanks for your fast answer
Reply
#4

pawn Код:
forward SpawnFix(playerid);
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
 switch(dialogid)
 {
  case 0:
  {
   if(!response) return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
   SetTimerEx("SpawnFix", 1, 0, "i", playerid);
  }
 }
}
public SpawnFix(playerid)
{
 SpawnPlayer(playerid);
}
You have to delay the spawn a little, doesn't work otherwise.
Reply
#5

Can you please add it for me, too hard for me

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 0) // If it is the register dialog
    {
        if(response) // if the player pressed the first button in our case Register.
        {
            if(!strlen(inputtext) || strlen(inputtext) > 100) // if the text ISN'T between 1 - 100 characters.
            {
                ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
                SendClientMessage(playerid, -1, "Your password must be between (1 - 100) characters");
            }
            else // if the text IS between 1 - 100 characters.
            {
                new pName[MAX_PLAYER_NAME], pIP[16], HashPass[129]; // Creating 3 variables for player's name, IP, and a variable for hasing user's password.
                GetPlayerName(playerid, pName, sizeof(pName)); // getting player's name and storing it inside the pName variable we created above ^.
                GetPlayerIp(playerid, pIP, sizeof(pIP)); // getting player's IP and saving it inside the pIP variable we created before.
                WP_Hash(HashPass, sizeof(HashPass), inputtext); // we are hashing inputtext (meaning the text the player wrote under the register dialog).
                file_Create(UserPath(playerid)); // Creating the file in (Accounts/%s.ini)
                file_Open(UserPath(playerid)); // opening the file
                file_SetStr("Password", HashPass); // setting the player's password to the hashed number.
                file_SetStr("IP", pIP); // setting player's IP to his IP
                file_SetVal("Admin", 0); // setting his admin level to 0
                file_SetVal("Score", 0); // setting his score to 0
                file_SetVal("Money", 500); // setting his money to 500 (NOTE: you also need to use GivePlayerMoney under OnPlayerSpawn).
                file_SetVal("Deaths", 0); // setting his kills to 0
                file_SetVal("Kills", 0); // setting his deaths to 0
                file_SetFloat("PosX", 0.0); // setting his X position to 0.0
                file_SetFloat("PosY", 0.0); // setting his Y position to 0.0
                file_SetFloat("PosZ", 0.0); // setting his Z position to 0.0
                file_SetFloat("PosA", 0.0); // setting his Angle to 0.0
                file_SetVal("IsRegistered", 1);
                file_SetStr("MyMotto", "You Don't Have A Motto Set One Using /setmotto");
                file_Save(UserPath(playerid)); // saving the file.
                file_Close(); // closing the file (NOTE: ALWAYS AND I DO MEAN ALWAYS close a file don't keep it open)
                SendClientMessage(playerid, -1, "You have been successfully registered."); // Sending a message to the player telling him he have been successfully registered the color -1 is white.
            }
        }
    }
    else if(dialogid == 1) // if he is registered then show him the login dialog
    {
        if(response) // if he clicked the first button in our case LOGIN
        {
            new HashPass[129]; // creating a variable to store get the hashed password from his file
            WP_Hash(HashPass, sizeof(HashPass), inputtext); // hashing the text he entered under the login dialog
            if(!strcmp(HashPass, PlayerInfo[playerid][Password])) // comparing it to the text in his file if it is true
            {
                file_Open(UserPath(playerid)); // open his file
                PlayerInfo[playerid][Admin] = file_GetVal("Admin"); // set each variable in his enum to the one in his file
                PlayerInfo[playerid][Score] = file_GetVal("Score");
                PlayerInfo[playerid][Money] = file_GetVal("Money");
                PlayerInfo[playerid][Deaths] = file_GetVal("Deaths");
                PlayerInfo[playerid][Kills] = file_GetVal("Kills");
                PlayerInfo[playerid][PosX] = file_GetFloat("PosX");
                PlayerInfo[playerid][PosY] = file_GetFloat("PosY");
                PlayerInfo[playerid][PosZ] = file_GetFloat("PosZ");
                PlayerInfo[playerid][PosA] = file_GetFloat("PosA");
                PlayerInfo[playerid][IsRegistered] = file_GetVal("IsRegistered");
                file_Close(); // Closing the file.
            }
            else
            {
                SendClientMessage(playerid, -1, "wrong password entered try again"); // if the password doesn't match the one in his file then tell him that it is incorrect
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave"); // and re-show the login dialog
            }
        }
    }
    return 1;
}
Just as you guys know, incase it has something to do with this: When i click spawn now, without the auto spawn thing, i cant spawn.
Reply
#6

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 0:
        {
            if(!response) return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
            if(!strlen(inputtext) || strlen(inputtext) > 100) // if the text ISN'T between 1 - 100 characters.
            {
                ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
                SendClientMessage(playerid, -1, "Your password must be between (1 - 100) characters");
            }
            else // if the text IS between 1 - 100 characters.
            {
                new pName[MAX_PLAYER_NAME], pIP[16], HashPass[129]; // Creating 3 variables for player's name, IP, and a variable for hasing user's password.
                GetPlayerName(playerid, pName, sizeof(pName)); // getting player's name and storing it inside the pName variable we created above ^.
                GetPlayerIp(playerid, pIP, sizeof(pIP)); // getting player's IP and saving it inside the pIP variable we created before.
                WP_Hash(HashPass, sizeof(HashPass), inputtext); // we are hashing inputtext (meaning the text the player wrote under the register dialog).
                file_Create(UserPath(playerid)); // Creating the file in (Accounts/%s.ini)
                file_Open(UserPath(playerid)); // opening the file
                file_SetStr("Password", HashPass); // setting the player's password to the hashed number.
                file_SetStr("IP", pIP); // setting player's IP to his IP
                file_SetVal("Admin", 0); // setting his admin level to 0
                file_SetVal("Score", 0); // setting his score to 0
                file_SetVal("Money", 500); // setting his money to 500 (NOTE: you also need to use GivePlayerMoney under OnPlayerSpawn).
                file_SetVal("Deaths", 0); // setting his kills to 0
                file_SetVal("Kills", 0); // setting his deaths to 0
                file_SetFloat("PosX", 0.0); // setting his X position to 0.0
                file_SetFloat("PosY", 0.0); // setting his Y position to 0.0
                file_SetFloat("PosZ", 0.0); // setting his Z position to 0.0
                file_SetFloat("PosA", 0.0); // setting his Angle to 0.0
                file_SetVal("IsRegistered", 1);
                file_SetStr("MyMotto", "You Don't Have A Motto Set One Using /setmotto");
                file_Save(UserPath(playerid)); // saving the file.
                file_Close(); // closing the file (NOTE: ALWAYS AND I DO MEAN ALWAYS close a file don't keep it open)
                SendClientMessage(playerid, -1, "You have been successfully registered."); // Sending a message to the player telling him he have been successfully registered the color -1 is white.
                SetTimerEx("SpawnFix", 1, 0, "i", playerid);
               }
        }
        case 1:
        {
            if(!response) return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave");
            new HashPass[129]; // creating a variable to store get the hashed password from his file
            WP_Hash(HashPass, sizeof(HashPass), inputtext); // hashing the text he entered under the login dialog
            if(!strcmp(HashPass, PlayerInfo[playerid][Password])) // comparing it to the text in his file if it is true
            {
                file_Open(UserPath(playerid)); // open his file
                PlayerInfo[playerid][Admin] = file_GetVal("Admin"); // set each variable in his enum to the one in his file
                PlayerInfo[playerid][Score] = file_GetVal("Score");
                PlayerInfo[playerid][Money] = file_GetVal("Money");
                PlayerInfo[playerid][Deaths] = file_GetVal("Deaths");
                PlayerInfo[playerid][Kills] = file_GetVal("Kills");
                PlayerInfo[playerid][PosX] = file_GetFloat("PosX");
                PlayerInfo[playerid][PosY] = file_GetFloat("PosY");
                PlayerInfo[playerid][PosZ] = file_GetFloat("PosZ");
                PlayerInfo[playerid][PosA] = file_GetFloat("PosA");
                PlayerInfo[playerid][IsRegistered] = file_GetVal("IsRegistered");
                file_Close(); // Closing the file.
                //SetTimerEx("SpawnFix", 1, 0, "i", playerid); // Uncomment this for (by removing the // ) spawning the player upon login aswell
            }
            else
            {
                SendClientMessage(playerid, -1, "wrong password entered try again"); // if the password doesn't match the one in his file then tell him that it is incorrect
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave"); // and re-show the login dialog
            }
        }
    }
    return 1;
}
forward SpawnFix(playerid);
public SpawnFix(playerid)
{
 SpawnPlayer(playerid);
}
Reply
#7

I replaced your OnDialogResponse with mine, and i got the forward and public of the spawnfix, no errors, but still.. dosent auto spawn.
Reply
#8

pawn Код:
SetTimerEx("SpawnFix", 10, 0, "i", playerid);
Increase the delay by raising the time (interval)
pawn Код:
(funcname[], interval, repeating, const format[], {Float,_}:...)
("SpawnFix", 10, 0, "i", playerid)
Reply
#9

This is what i got now:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 0:
        {
            if(!response) return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
            if(!strlen(inputtext) || strlen(inputtext) > 100) // if the text ISN'T between 1 - 100 characters.
            {
                ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "Create An Account", "Please Create An Account On Our Server Before You Continue", "Register", "Leave");
                SendClientMessage(playerid, -1, "Your password must be between (1 - 100) characters");
            }
            else // if the text IS between 1 - 100 characters.
            {
                new pName[MAX_PLAYER_NAME], pIP[16], HashPass[129]; // Creating 3 variables for player's name, IP, and a variable for hasing user's password.
                GetPlayerName(playerid, pName, sizeof(pName)); // getting player's name and storing it inside the pName variable we created above ^.
                GetPlayerIp(playerid, pIP, sizeof(pIP)); // getting player's IP and saving it inside the pIP variable we created before.
                WP_Hash(HashPass, sizeof(HashPass), inputtext); // we are hashing inputtext (meaning the text the player wrote under the register dialog).
                file_Create(UserPath(playerid)); // Creating the file in (Accounts/%s.ini)
                file_Open(UserPath(playerid)); // opening the file
                file_SetStr("Password", HashPass); // setting the player's password to the hashed number.
                file_SetStr("IP", pIP); // setting player's IP to his IP
                file_SetVal("Admin", 0); // setting his admin level to 0
                file_SetVal("Score", 0); // setting his score to 0
                file_SetVal("Money", 500); // setting his money to 500 (NOTE: you also need to use GivePlayerMoney under OnPlayerSpawn).
                file_SetVal("Deaths", 0); // setting his kills to 0
                file_SetVal("Kills", 0); // setting his deaths to 0
                file_SetFloat("PosX", 0.0); // setting his X position to 0.0
                file_SetFloat("PosY", 0.0); // setting his Y position to 0.0
                file_SetFloat("PosZ", 0.0); // setting his Z position to 0.0
                file_SetFloat("PosA", 0.0); // setting his Angle to 0.0
                file_SetVal("IsRegistered", 1);
                file_SetStr("MyMotto", "You Don't Have A Motto Set One Using /setmotto");
                file_Save(UserPath(playerid)); // saving the file.
                file_Close(); // closing the file (NOTE: ALWAYS AND I DO MEAN ALWAYS close a file don't keep it open)
                SendClientMessage(playerid, -1, "You have been successfully registered."); // Sending a message to the player telling him he have been successfully registered the color -1 is white.
                SetTimerEx("SpawnFix", 2000, 0, "i", playerid);
               }
        }
        case 1:
        {
            if(!response) return ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave");
            new HashPass[129]; // creating a variable to store get the hashed password from his file
            WP_Hash(HashPass, sizeof(HashPass), inputtext); // hashing the text he entered under the login dialog
            if(!strcmp(HashPass, PlayerInfo[playerid][Password])) // comparing it to the text in his file if it is true
            {
                file_Open(UserPath(playerid)); // open his file
                PlayerInfo[playerid][Admin] = file_GetVal("Admin"); // set each variable in his enum to the one in his file
                PlayerInfo[playerid][Score] = file_GetVal("Score");
                PlayerInfo[playerid][Money] = file_GetVal("Money");
                PlayerInfo[playerid][Deaths] = file_GetVal("Deaths");
                PlayerInfo[playerid][Kills] = file_GetVal("Kills");
                PlayerInfo[playerid][PosX] = file_GetFloat("PosX");
                PlayerInfo[playerid][PosY] = file_GetFloat("PosY");
                PlayerInfo[playerid][PosZ] = file_GetFloat("PosZ");
                PlayerInfo[playerid][PosA] = file_GetFloat("PosA");
                PlayerInfo[playerid][IsRegistered] = file_GetVal("IsRegistered");
                file_Close(); // Closing the file.
                SetTimerEx("SpawnFix", 2000, 0, "i", playerid); // Uncomment this for (by removing the // ) spawning the player upon login aswell
            }
            else
            {
                SendClientMessage(playerid, -1, "wrong password entered try again"); // if the password doesn't match the one in his file then tell him that it is incorrect
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "Please Login By Writing Your Password Below", "Login", "Leave"); // and re-show the login dialog
            }
        }
    }
    return 1;
}
But i am not auto spawning when i login, but i am when i register.
Reply
#10

I made the loggin one to 3000 millisec so now its working thank you very much for your help, I repped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)