[HELP]Input Dialog
#1

How would I make an input dialog where if I typed a certain number then it would do a function. I had the idea of making a command that works sorta like this. '/drift' opens an input dialog and the user would have to enter a number between 1 and 51. If the user types 1 it will teleport the player to the first drift spot and if the user types 2 then they would be teleported to the second drift spot and so on.
Reply
#2

Ah that's easy. Here's an example:

The command /drift (USING ZCMD)
pawn Код:
CMD:drift(playerid, params[])
{
    ShowPlayerDialog(playerid, 13379, DIALOG_STYLE_INPUT, "Choose your teleport", "Choose a number between 1 and 51.", "Go", "Cancel");
    return 1;
}
OnDialogResponse
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 13379)
    {
        if(response)
        {
            switch(strval(inputtext)) //Not tested, but I guess it'll work
            {
                case 1:
                {
                     //Teleport and whatever you want.
                }
                case 2:
                {
                    //And again...
                }
                case 3:
                {
                    //Blabla.
                }
                //ETC...
                default:
                {
                    //The player didn't do ID 1-51
                }
            }
        }
        else return SendClientMessage(playerid, 0xFF0000AA, "ERROR: Invalid teleport ID!");
    }
    return 1;
}
I THINK that this'll work. Untested!
Reply
#3

Alright I'll test this out and if i tdoesn't work I'll make another reply.
Reply
#4

It doesn't work. I type in '1' and it doesn't take me to the teleport whether I am in a car or not. Same for any of the others.

Here is my code...
pawn Код:
if(dialogid == 112)
    {
        if(!response)
        {
            switch(strval(inputtext)) //Not tested, but I guess it'll work
            {
                case 1:
                {
                    if(IsPlayerInAnyVehicle(playerid)) //if player is in any vehicle
                    {
                        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //if player state = driver
                        {
                            SetVehiclePos(GetPlayerVehicleID(playerid), -358.1943,1531.2909,75.1698 ); //set vehicle pos
                            SetVehicleZAngle(GetPlayerVehicleID(playerid), 264.7289); //set vehicle ang
                            SetCameraBehindPlayer(playerid); //set camera behind player
                        }
                        else //player is not the driver
                        {
                            SendClientMessage(playerid,0xFFFF00AA, "ERROR: You need to be the driver!");
                        }
                    }
                    else //player is not in any vehicle
                    {
                        SetPlayerPos(playerid, -329.3348,1536.3771,76.6117 ); //set player pos
                        SetPlayerFacingAngle(playerid, 276.8851); //set player facing ang
                        SetCameraBehindPlayer(playerid); //set camera behind the player
                    }
                    return 1;
                }
                case 2:
                {
                    if(IsPlayerInAnyVehicle(playerid)) //if player is in any vehicle
                    {
                        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //if player state = driver
                        {
                            SetVehiclePos(GetPlayerVehicleID(playerid), 2265.3010,1399.5085,42.8203); //set vehicle pos
                            SetVehicleZAngle(GetPlayerVehicleID(playerid), 269.7637); //set vehicle ang
                            SetCameraBehindPlayer(playerid); //set camera behind player
                        }
                        else //player is not the driver
                        {
                            SendClientMessage(playerid,0xFFFF00AA, "ERROR: You need to be the driver!");
                        }
                    }
                    else //player is not in any vehicle
                    {
                        SetPlayerPos(playerid, 2265.3010,1399.5085,42.8203); //set player pos
                        SetPlayerFacingAngle(playerid, 110.5445); //set player facing ang
                        SetCameraBehindPlayer(playerid); //set camera behind the player
                    }
                }
                case 3:
                {
                    if(IsPlayerInAnyVehicle(playerid)) //if player is in any vehicle
                    {
                        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //if player state = driver
                        {
                            SetVehiclePos(GetPlayerVehicleID(playerid), -2489.8352,-616.3492,132.5658); //set vehicle pos
                            SetVehicleZAngle(GetPlayerVehicleID(playerid), 178.7448); //set vehicle ang
                            SetCameraBehindPlayer(playerid); //set camera behind player
                        }
                        else //player is not the driver
                        {
                            SendClientMessage(playerid,0xFFFF00AA, "ERROR: You need to be the driver!");
                        }
                    }
                    else //player is not in any vehicle
                    {
                        SetPlayerPos(playerid, -2489.8352,-616.3492,132.5658); //set player pos
                        SetPlayerFacingAngle(playerid, 110.5445); //set player facing ang
                        SetCameraBehindPlayer(playerid); //set camera behind the player
                    }
                }
                case 4:
                {
                    //...and so on
                }
                //ETC...
                default:
                {
                    SendClientMessage(playerid, 0xFF0000AA, "ERROR: You have cancelled.");
                }
            }
        }
    }
Reply
#5

Remove the ! from
pawn Код:
if(!response)
So it will be like
pawn Код:
if(response)
Reply
#6

Like Fredde said, do if(response).
Response is a bool (true/false).
Alot of people uses "if(var == true)" or "if(var == false)". You can use instead "if(var)" or "if(!var)"). If response is 'false' (!response), it does mean that the player didn't respond (ESC) or pressed the cancel button (just the 2nd button). So you have said actually:

if player doesn't respond or press the 2nd (cancel) button

Reply
#7

Fixed. Thank you for the help. About a 100 or so more teles to go...lol
Reply
#8

Are you serious?? 100 TELEPORTS?

That will take you ages ( Time is money ). I recommend you to use a Dynamic Teleport Creator! You can have in way less time than actually adding bunch of code.
Reply
#9

Hello people,

I got a problem with saving files like a password and money. I have for the player a save file but now i wanna make a save file for the playerbank. I did the same thing as with the player saving file. The player file works but the bank file not. It is almost the same but do not work.

Can some one please help me with it

This is the code what i use for player save file and bank save file.

Код:
#define BankFile "ServerData/Bank/%s.ini"
#define PlayerFile "ServerData/Players/%s.ini"

Dialog_BankRegister(playerid, response, inputtext[])
{
	switch (response) // Check which button was clicked
	{
		case 1: // Player clicked "Register"
		{
			// Check if the player entered a password
			if(strlen(inputtext)>0)
			{

// Store the password   //THIS IS MY BROBLEM inputtext = 9876. he makes is 9 on create and save.
				format(BankData[playerid][BankPassword], 50, "%s", inputtext);
---------------------------------------------------------------------------------------
				BankFile_Create(playerid);//goto function
				SendClientMessage(playerid, geel, "Rekening gemaakt en klaar voor gebruik."); // Send a message to the client Account created and ready for use
				BankData[playerid][BankMoney] = 0;
				format(BankStringA, sizeof(BankStringA), " U heeft op de bank: %i ", BankData[playerid][BankMoney]);//You have on youre Account:
				ShowPlayerDialog(playerid, DialogBank, DIALOG_STYLE_LIST, BankStringA, TXT_DialogBankList, TXT_DialogButtonOke, TXT_DialogButtonCancel);
				return 1;
			}
			else // Ask the player to enter a proper password
			{
				ShowPlayerDialog(playerid, DialogBankRegister, DIALOG_STYLE_INPUT, "Welcome", "Voer goed wachtwoord in om te registreren:", "Register", "Cancel");//Enter good password to register
			}
		}
	    case 0: // Player clicked "Cancel"
		{
			return 1;
		}
	}
	return 1;
}

// This function will create the player-datafile for the given player (only used when a new player joins the server)
BankFile_Create(playerid)
{
	new file[100], File:PFile, Name[24], LineForFile[100];
	GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
	format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's account


	PFile = fopen(file, io_write); // Open the playerfile for writing

	format(LineForFile, 100, "Password %s\r\n", BankData[playerid][BankPassword]);// Construct the line: "Bank <BankPassword>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Money %i\r\n", 0); // Construct the line: "Money <bankmoney>"
	fwrite(PFile, LineForFile); // And save it to the file
	
	fclose(PFile); // Close the file

	return 1;
}

// This function will load the player's datafile (used when a player connects to the server)
BankFile_Load(playerid)
{
	// Setup local variables
	new file[100], File:PFile, Name[24], LineFromFile[100], ParameterName[50], ParameterValue[50];

	GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
	format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's account

	// Check if the player's datafile exists
	if (fexist(file))
	{
		PFile = fopen(file, io_read); // Open the playerfile for reading

		fread(PFile, LineFromFile); // Read the first line of the file

		// Keep reading until the end of the file is found (no more data)
		while (strlen(LineFromFile) > 0)
		{
			StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
			sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue

			// Store the proper value in the proper place
			if (strcmp(ParameterName, "Password", false) == 0) // If the parametername is correct ("Password")
			    format(BankData[playerid][BankPassword], 50, ParameterValue); // Store the password
			if (strcmp(ParameterName, "Money", false) == 0) // If the parametername is correct ("Money")
			    BankData[playerid][BankMoney] = strval(ParameterValue);
			
			fread(PFile, LineFromFile); // Read the next line of the file
		}

		fclose(PFile); // Close the file

		return 1; // Return if the file was read correctly
	}
	else
	    return 0; // Return 0 if the file couldn't be read (doesn't exist)
}

// This function will save all player-data (used when the player disconnects from the server)
BankFile_Save(playerid)
{
	new file[100], File:PFile, Name[24], LineForFile[100];
	GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
	format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's account

	PFile = fopen(file, io_write); // Open the playerfile for writing

	format(LineForFile, 100, "Password %s\r\n", BankData[playerid][BankPassword]); // Construct the line: "Password <Bankpassword>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Money %i\r\n", BankData[playerid][BankMoney]); // Construct the line: "Money <Bankmoney>"
	fwrite(PFile, LineForFile); // And save it to the file
	
	fclose(PFile); // Close the file

	return 1;
}

// This function will create the player-datafile for the given player (only used when a new player joins the server)
PlayerFile_Create(playerid)
{
	new file[100], File:PFile, Name[24], LineForFile[100];
	GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
	format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account


	PFile = fopen(file, io_write); // Open the playerfile for writing

	format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][PlayerPassword]);
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Sex %s\r\n", APlayerData[playerid][Sex]); // Construct the line: "Sex <Sex>"
	fwrite(PFile, LineForFile); // And save it to the file	
	format(LineForFile, 100, "Level %i\r\n", 0); // Construct the line: "Level <PlayerLevel>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "XPLevel %i\r\n", APlayerData[playerid][XPLevel]); // Construct the line: "Level <XPLevel>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Money %i\r\n", 0); // Construct the line: "Money <playermoney>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Score %i\r\n", 0); // Construct the line: "Score <playerscore>"
	fwrite(PFile, LineForFile); // And save it to the file
	
	format(LineForFile, 100, "BromLicense %i\r\n", 0); // Construct the line: "BromLicense <playerBromlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "AutoLicense %i\r\n", 0); // Construct the line: "AutoLicense <playerAutolicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "MotorLicense %i\r\n", 0); // Construct the line: "MotorLicense <playerMotorlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "BusLicense %i\r\n", 0); // Construct the line: "BusLicense <playerbuslicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "TruckerLicense %i\r\n", 0); // Construct the line: "TruckerLicense <playertruckerlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "TruckerALicense %i\r\n", 0); // Construct the line: "TruckerALicense <playertruckerAlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "TreinLicense %i\r\n", 0); // Construct the line: "MotorLicense <playerMotorlicense>"
	fwrite(PFile, LineForFile); // And save it to the file

	format(LineForFile, 100, "Wanted %i\r\n", 0); // Construct the line: "Wanted <wantedlevel>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Bans %i\r\n", 0); // Construct the line: "Bans <NumberOfBans>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "BanTime %i\r\n", 0); // Construct the line: "BanTime <TimeToUnban>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Logins %i\r\n", 0);
	fwrite(PFile, LineForFile); // And save it to the file
	
	fclose(PFile); // Close the file

	return 1;
}

// This function will load the player's datafile (used when a player connects to the server)
PlayerFile_Load(playerid)
{
	// Setup local variables
	new file[100], File:PFile, Name[24], LineFromFile[100], ParameterName[50], ParameterValue[50];

	GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
	format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account

	// Check if the player's datafile exists
	if (fexist(file))
	{
		PFile = fopen(file, io_read); // Open the playerfile for reading

		fread(PFile, LineFromFile); // Read the first line of the file

		// Keep reading until the end of the file is found (no more data)
		while (strlen(LineFromFile) > 0)
		{
			StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
			sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue

			// Store the proper value in the proper place
			if (strcmp(ParameterName, "Password", false) == 0) // If the parametername is correct ("Password")
			    format(APlayerData[playerid][PlayerPassword], 50, ParameterValue); // Store the password
			if (strcmp(ParameterName, "Sex", false) == 0) // If the parametername is correct ("Sex")
			    format(APlayerData[playerid][Sex], 50, ParameterValue); // Store the Sex
			if (strcmp(ParameterName, "Level", false) == 0) // If the parametername is correct ("playerLevel")
			    APlayerData[playerid][PlayerLevel] = strval(ParameterValue); // Store the adminlevel
			if (strcmp(ParameterName, "XPLevel", false) == 0) // If the parametername is correct ("playerLevel")
			    RewardPlayer(playerid, 0, 0, strval(ParameterValue)); // Store the XPLevel
			if (strcmp(ParameterName, "Money", false) == 0) // If the parametername is correct ("Money")
			    RewardPlayer(playerid, strval(ParameterValue), 0, 0); // Store the money
			if (strcmp(ParameterName, "Score", false) == 0) // If the parametername is correct ("Score")
			    RewardPlayer(playerid, 0, strval(ParameterValue), 0); // Store the score
			
			if (strcmp(ParameterName, "BromLicense", false) == 0) // If the parametername is correct ("BromLicense")
			    APlayerData[playerid][BromLicense] = strval(ParameterValue); // Store the BromLicense
			if (strcmp(ParameterName, "AutoLicense", false) == 0) // If the parametername is correct ("AutoLicense")
			    APlayerData[playerid][AutoLicense] = strval(ParameterValue); // Store the AutoLicense
			if (strcmp(ParameterName, "MotorLicense", false) == 0) // If the parametername is correct ("MotorLicense")
			    APlayerData[playerid][MotorLicense] = strval(ParameterValue); // Store the MotorLicense
			if (strcmp(ParameterName, "BusLicense", false) == 0) // If the parametername is correct ("BusLicense")
			    APlayerData[playerid][BusLicense] = strval(ParameterValue); // Store the BusLicense
			if (strcmp(ParameterName, "TruckerLicense", false) == 0) // If the parametername is correct ("TruckerLicense")
			    APlayerData[playerid][TruckerLicense] = strval(ParameterValue); // Store the TruckerLicense
			if (strcmp(ParameterName, "TruckerALicense", false) == 0) // If the parametername is correct ("TruckerALicense")
			    APlayerData[playerid][TruckerALicense] = strval(ParameterValue); // Store the TruckerALicense
			if (strcmp(ParameterName, "TreinLicense", false) == 0) // If the parametername is correct ("TreinLicense")
			    APlayerData[playerid][TreinLicense] = strval(ParameterValue); // Store the TreinLicense
			
			if (strcmp(ParameterName, "Wanted", false) == 0) // If the parametername is correct ("Wanted")
			    SetPlayerWantedLevel(playerid, strval(ParameterValue)); // Set the wanted-status
			if (strcmp(ParameterName, "Bans", false) == 0) // If the parametername is correct ("Bans")
			    APlayerData[playerid][Bans] = strval(ParameterValue); // Store the bans
			if (strcmp(ParameterName, "BanTime", false) == 0) // If the parametername is correct ("BanTime")
			    APlayerData[playerid][BanTime] = strval(ParameterValue); // Store the bantime
			if (strcmp(ParameterName, "Logins", false) == 0) // If the parametername is correct ("Logins")
			    APlayerData[playerid][Logins] = strval(ParameterValue); // Store the Logins

			fread(PFile, LineFromFile); // Read the next line of the file
		}

		fclose(PFile); // Close the file

		return 1; // Return if the file was read correctly
	}
	else
	    return 0; // Return 0 if the file couldn't be read (doesn't exist)
}

// This function will save all player-data (used when the player disconnects from the server)
PlayerFile_Save(playerid)
{
	new file[100], File:PFile, Name[24], LineForFile[100];
	GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
	format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account

	PFile = fopen(file, io_write); // Open the playerfile for writing

	format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][PlayerPassword]); // Construct the line: "Password <playerpassword>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Sex %s\r\n", APlayerData[playerid][Sex]); // Construct the line: "Sex <Sex>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Level %i\r\n", APlayerData[playerid][PlayerLevel]); // Construct the line: "Level <PlayerLevel>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "XPLevel %i\r\n", APlayerData[playerid][XPLevel]); // Construct the line: "Level <XPLevel>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Money %i\r\n", APlayerData[playerid][PlayerMoney]); // Construct the line: "Money <playermoney>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Score %i\r\n", APlayerData[playerid][PlayerScore]); // Construct the line: "Score <playerscore>"
	fwrite(PFile, LineForFile); // And save it to the file

	format(LineForFile, 100, "BromLicense %i\r\n", APlayerData[playerid][BromLicense]); // Construct the line: "BromLicense <playerBromlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "AutoLicense %i\r\n", APlayerData[playerid][AutoLicense]); // Construct the line: "AutoLicense <playerAutolicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "MotorLicense %i\r\n", APlayerData[playerid][MotorLicense]); // Construct the line: "MotorLicense <playerMotorlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "BusLicense %i\r\n", APlayerData[playerid][BusLicense]); // Construct the line: "BusLicense <playerbuslicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "TruckerLicense %i\r\n", APlayerData[playerid][TruckerLicense]); // Construct the line: "TruckerLicense <playertruckerlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "TruckerALicense %i\r\n", APlayerData[playerid][TruckerALicense]); // Construct the line: "TruckerALicense <playertruckerAlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "TreinLicense %i\r\n", APlayerData[playerid][TreinLicense]); // Construct the line: "TreinLicense <playertreinlicense>"
	fwrite(PFile, LineForFile); // And save it to the file
	
	format(LineForFile, 100, "Wanted %i\r\n", GetPlayerWantedLevel(playerid)); // Construct the line: "Wanted <wantedlevel>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Bans %i\r\n", APlayerData[playerid][Bans]); // Construct the line: "Bans <NumberOfBans>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "BanTime %i\r\n", APlayerData[playerid][BanTime]); // Construct the line: "BanTime <TimeToUnban>"
	fwrite(PFile, LineForFile); // And save it to the file
	format(LineForFile, 100, "Logins %i\r\n", APlayerData[playerid][Logins]); // Construct the line: "Logins"
	fwrite(PFile, LineForFile); // And save it to the file
	
	fclose(PFile); // Close the file

	return 1;
}
The problem is that i put in the password 9876 different then the inlog code for the player to login to the server 1234.
On create bankfile he only put : 9
Not 9876
What did i do wrong

Please help

Greetings from Marco Koobs
Reply
#10

@Lethal
- What I was doing was I had made all of these teleports in the past, except I made them as commands and I wanted to just copy and paste them over from the commands into the place of the 'case'.

@mkxxx
- You should probably make a new topic.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)