So to start off when you click on the slot you want to spawn in you cant type in the dialog for a few seconds. Once you can you type your character name into the dialog and then no more dialogs show up. We get these warnings aswell.
Код:
tryCreateCharacter(playerid, name[]) {
new query[128];
//mysql_real_escape_string(name,name);
format(query, sizeof(query),"SELECT 1 FROM `characters` WHERE `username` = \"%s\"",name);
mysql_function_query(MySQLCon, query, true, "onCreateChar", "ds", playerid,name);
}
forward onCreateChar(playerid, name[]);
public onCreateChar(playerid, name[]) {
new query[128];
new rows, fields;
cache_get_data(rows, fields);
if(rows > 0) {
ShowPlayerDialog(playerid, DIALOG_CREATE_CHARACTER, DIALOG_STYLE_INPUT, "Enter your name", "Enter you name please.","Ok","Cancel");
} else {
format(query, sizeof(query), "INSERT INTO `characters` (`username`,`accountid`) VALUES (\"%s\", %d)",name,GetPVarInt(playerid,"AccountID"));
mysql_function_query(MySQLCon, query, true, "onCharacterCreate", "ds", playerid,name);
}
}
forward onCharacterCreate(playerid, charname[], last_insert_id);
public onCharacterCreate(playerid, charname[], last_insert_id) {
new rows,fields,id;
cache_get_data(rows,fields);
id = cache_insert_id();
if(id == 0 || id == last_insert_id) {
SendClientMessage(playerid, COLOR_RED, "There was an error creating your account.");
}
#if debug
new dbgmsg[128];
format(dbgmsg,sizeof(dbgmsg),"[DBG]: Character ID: %d",id);
SendClientMessage(playerid, COLOR_RED,dbgmsg);
#endif
SetPVarInt(playerid, "CreateCharID", id);
new pvarname[32];
new index = 0;
do {
format(pvarname,sizeof(pvarname),"CharID%d",index++);
} while(GetPVarType(playerid, pvarname) == PLAYER_VARTYPE_INT);
SetPVarInt(playerid, pvarname, id);
format(pvarname,sizeof(pvarname),"CharUsername%d",index-1);
SetPVarString(playerid, pvarname, charname);
SetPVarInt(playerid, "NumCharacters", GetPVarInt(playerid,"NumCharacters")+1);
new string[128];
format(string, sizeof(string), "Please type you age below.");
ShowPlayerDialog(playerid,DIALOG_REGISTER_AGE,DIALOG_STYLE_INPUT,"{EDDC57}Registration required",string,"Register","Cancel");
}
Код:
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
if(clickedid == TDEditor_TD[2] || TDEditor_TD[5] || TDEditor_TD[9])
{
if(tdempty = true)
{
showCharacterCreationDialog(playerid);
}
else {
chooseCharacter(playerid, 0);
}
}
else if(clickedid == 1)
{
if(tdempty = true)
{
showCharacterCreationDialog(playerid);
}
else {
chooseCharacter(playerid, 1);
}
}
else if(clickedid == 2)
{
if(tdempty = true)
{
showCharacterCreationDialog(playerid);
}
else {
chooseCharacter(playerid, 2);
}
}
CancelSelectTextDraw(playerid);
TextDrawHideForPlayer(playerid, TDEditor_TD[0]);
TextDrawHideForPlayer(playerid, TDEditor_TD[1]);
TextDrawHideForPlayer(playerid, TDEditor_TD[2]);
TextDrawHideForPlayer(playerid, TDEditor_TD[3]);
TextDrawHideForPlayer(playerid, TDEditor_TD[4]);
TextDrawHideForPlayer(playerid, TDEditor_TD[5]);
TextDrawHideForPlayer(playerid, TDEditor_TD[6]);
TextDrawHideForPlayer(playerid, TDEditor_TD[7]);
TextDrawHideForPlayer(playerid, TDEditor_TD[8]);
TextDrawHideForPlayer(playerid, TDEditor_TD[9]);
TextDrawHideForPlayer(playerid, TDEditor_TD[10]);
CancelSelectTextDraw(playerid); // This will indeed call OnPlayerClickTextDraw again, but with an ID of 65535. The code above stops it from resulting in an eternal loop.
return 1;
}
That will probably always evaluate to true because it is only checked if TDEditor_TD 5 or 9 are different from 0, not if they're actually equal to clickedid.