OnPlayerRequestClass - Need Help!
#1

Hey Guys,

i made this script:
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 2000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 2000, 0);
         }
     }
    return 1;
}
When i join, and on spawn when i click > arrow, i only See Green team, Not Yellow Team.
Please Help.
Reply
#2

Show your AddPlayerClass (Under GameModeInit)
Reply
#3

My Whole Script.
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 1
#define Yellow 2

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 2000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 2000, 0);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Please Help.
Reply
#4

Try this
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 0
#define Yellow 1

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 2000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 2000, 0);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#5

Quote:
Originally Posted by Infinity90
Посмотреть сообщение
Try this
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 0
#define Yellow 1

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 2000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 2000, 0);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Wrong

That will give same problem.
here is working code
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 1
#define Yellow 2

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 2000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 2000, 0);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#6

Quote:
Originally Posted by [HK]Ryder[AN]
Посмотреть сообщение
Wrong

That will give same problem.
here is working code
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 1
#define Yellow 2

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(1, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 2000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 2000, 0);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Thanks
Reply
#7

Guys, i want that when we Press >> on Spawn, it should say next team.
My Script:
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 1
#define Yellow 2

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0,-131.0807,112.4514,3.1172,159.1588,0,0,0,0,0,0); // GreenTeam
    AddPlayerClass(1,-182.7580,-26.3152,3.1172,344.3405,0,0,0,0,0,0); // YellowTeam
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 1000, 0); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 1000, 0);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SetPlayerSkin(playerid, 107);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SetPlayerSkin(playerid, 109);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nUse * to Team Chat.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nUse * to Team Chat.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Please Help!
Sorry for Double Post.
Reply
#8

use this
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

native WP_Hash(buffer[],len,const str[]);

#define register 1 //Defining register dialog so it won't mixed up with the other dialogs
#define login    2 //Defining login dialog so it won't mixed up with the other dialogs
#define thelpyellow 3
#define thelpgreen  4
#define UserPath "Users/%s.ini"

#define Green 1
#define Yellow 2

#define GreenColor 0x00FF00AA
#define YellowColor 0xFFFF00AA

enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo];

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}

forward loadaccount_user(playerid, name[], value[]);
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}



main()
{
    print("\n----------------------------------");
    print("          Green Vs Yellow           ");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Team Death Match");
    AddPlayerClass(0,-131.0807,112.4514,3.1172,159.1588,0,0,0,0,0,0); // GreenTeam
    AddPlayerClass(1,-182.7580,-26.3152,3.1172,344.3405,0,0,0,0,0,0); // YellowTeam
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    switch(classid) // Switching between the classids
    {
         case 0:
         {
              SetPlayerTeam(playerid, Green); // Setting players team
              GameTextForPlayer(playerid, "~g~Green Team", 1000, 3); // Screen msg for player to show what team
         }

         case 1:
         {
              SetPlayerTeam(playerid, Yellow); // Same as above
              GameTextForPlayer(playerid, "~y~Yellow Team", 1000, 3);
         }
     }
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
    if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
    {
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(GetPlayerTeam(playerid) == Green)
    {
        SetPlayerColor(playerid, GreenColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SetPlayerSkin(playerid, 107);
        SendClientMessage(playerid, YellowColor, "You Are in Green Team! Try /thelp for More Info.");
    }

    else if(GetPlayerTeam(playerid) == Yellow)
    {
        SetPlayerColor(playerid, YellowColor);
        GivePlayerWeapon(playerid, 25, 500);
        GivePlayerWeapon(playerid, 30, 500);
        SetPlayerSkin(playerid, 109);
        SendClientMessage(playerid, GreenColor, "You Are in Yellow Team! Try /thelp for More Info.");
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    SendDeathMessage(killerid, playerid, reason);
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    if(text[0] == '*') // : can be changed to whatever symbol u wanna use for player to enable the teamchat.
    {
        new string[128];  GetPlayerName(playerid, string, sizeof(string)); // Making the new's
        format(string, sizeof(string), "[Team Radio] %s: %s", string, text[1]); // Formatted the message
        printf("%s", string); // Printed it BOTH ingame + the server log

        for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
        {
            if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
        }
        return 0;
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/thelp", cmdtext, true, 10) == 0)
    {
      if(GetPlayerTeam(playerid) == Green)
      {
        ShowPlayerDialog(playerid, thelpgreen, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Green team.\nUse * to Team Chat.\nYour Objective is to Kill the Soldiers of Yellow Team.\nGood Luck!", "Close", "");
      }
      else if(GetPlayerTeam(playerid) == Yellow)
      {
        ShowPlayerDialog(playerid, thelpyellow, DIALOG_STYLE_MSGBOX, "Team Help", "Your in Yellow team.\nUse * to Team Chat.\nYour Objective is to Kill the Soldiers of Green Team.\nGood Luck!", "Close", "");
      }
      return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == register) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == login) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,login,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#9

@Ryder don't just post the code. Explain the person what you modified and why.
Reply
#10

Thanks Guys.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)