PDA

View Full Version : Inputtext problem


Wex56
02/01/2016, 08:25 AM
Ok, so I tried to make something like police monitor and there I used select textdraw and other stuff, that doesn't matter right now.I have problem with geting string from dialog.I tried using inputtext and I'am getting errors so here is what I have done by now.
if(dialogid == DIALOG_RECORD)
{
if(response)
{
new id[MAX_PLAYERS], h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[inputtext][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[inputtext][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[inputtext][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}

If you need something else just post!

IceBilizard
02/01/2016, 09:07 AM
show the function or enum of CrimeInfo

Wex56
02/01/2016, 09:37 AM
Here you go
enum crInfo
{
cDone[MAX_PLAYER_NAME],
cReported[MAX_PLAYER_NAME],
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];

Lucky13
02/01/2016, 09:43 AM
I have a question: What you have to type in that dialog? the playerid or name?

IceBilizard
02/01/2016, 09:53 AM
try this

enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new ID = strval(inputtext);
new id[MAX_PLAYERS], h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[ID][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[ID][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[ID][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}

Wex56
02/01/2016, 11:57 AM
I have a question: What you have to type in that dialog? the playerid or name?

When dialog pop out I have to enter player name

try this

enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new ID = strval(inputtext);
new id[MAX_PLAYERS], h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[ID][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[ID][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[ID][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}


It's not working.There is no errors but when I type in name or ID in dialog it just show me blank text just like it did before.And as I know "strval" is used to convert string to integer

Lucky13
02/01/2016, 05:37 PM
Try this one:

enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new pid = strval(inputtext);
new h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[pid][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[pid][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[pid][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}

Wex56
03/01/2016, 08:52 AM
Try this one:

enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new pid = strval(inputtext);
new h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[pid][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[pid][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[pid][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}

It's same thing that IceBilizard has done.

Strval is used to convert string to integer

Lucky13
03/01/2016, 10:58 AM
It's same thing that IceBilizard has done.

Strval is used to convert string to integer

IceBilizard's:
enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new ID = strval(inputtext);
new id[MAX_PLAYERS], h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[ID][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[ID][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[ID][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}


Mine:
enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new pid = strval(inputtext);
new h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[pid][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[pid][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[pid][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}

See the difference? You define 2 times ( one time an integer & one time a string ) the same variable in IceBilizard's.

Did you test mine at least?

vannesenn
03/01/2016, 11:09 AM
if(dialogid == DIALOG_RECORD)
{
if(response)
{
new id, h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[id][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[id][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[id][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}

Lucky13
03/01/2016, 11:11 AM
if(dialogid == DIALOG_RECORD)
{
if(response)
{
new id, h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[id][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[id][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[id][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}


You have only new id; That will always return id 0...

AndySedeyn
03/01/2016, 11:11 AM
Variables are case-sensitive. ID and id are two different variables.
You could use sscanf to achieve this:


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext) {

switch(dialogid) {

case DIALOG_RECORD: {

if(response) {

if(!strlen(inputtext)) {

// inputtext is empty
// Reshow the dialog
}

new
tID;

if(!sscanf(inputtext, "u", tID)) { // The "u" specifier can either be a part of the player's name or their ID

new
h, m, s, Name[MAX_PLAYER_NAME];

gettime(h, m, s);
RPName(playerid, Name);

SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[tID][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[tID][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[tID][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}
}
}
return 0; // For filterscripts
}


You'll need the sscanf include and plugin: http://forum.sa-mp.com/showthread.php?t=570927

I put strlen before the sscanf function to make sure that the inputtext isn't empty. Though, I'm sure sscanf can achieve that.

vannesenn
03/01/2016, 11:13 AM
He needs to add only = strval(inputtext);

Wex56
03/01/2016, 02:46 PM
IceBilizard's:
enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new ID = strval(inputtext);
new id[MAX_PLAYERS], h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[ID][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[ID][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[ID][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}


Mine:
enum crInfo
{
cDone,
cReported,
cCrime[64],
};
new CrimeInfo[MAX_PLAYERS][crInfo];


if(dialogid == DIALOG_RECORD)
{
if(response)
{
new pid = strval(inputtext);
new h, m, s, Name[MAX_PLAYER_NAME];

gettime(h,m,s);
RPName(playerid, Name);
SCM(playerid, GRAD2, "_______________| {FFFFFF}MONITOR {BFC0C2}|_______________");
format(CmdString, sizeof CmdString, " Name: %s", CrimeInfo[pid][cDone]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Crime: %s", CrimeInfo[pid][cCrime]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Reported: %s", CrimeInfo[pid][cReported]);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, " Your name: %s", hIme);
SCM(playerid, WHITE, CmdString);
format(CmdString, sizeof CmdString, "________________________________|{FFFFFF}%d:%d{BFC 0C2}|__", h, m);
SCM(playerid, WHITE, CmdString);
}
}

See the difference? You define 2 times ( one time an integer & one time a string ) the same variable in IceBilizard's.

Did you test mine at least?

I tested it, but variables are case-sensative, so variable id and ID are different as I know.So that "new id;" in IceBlizzards code doesn't effect anything else beacuse I'am using variable ID.I think you'll understand the point.

Guys I'll check those things you posted and update this post

Tnx guys, especially Andy your code fixed it