16.07.2011, 19:01
Check this filterscript out:
And now check this results out:
Why the number contains the name too !?
pawn Код:
#include <a_samp>
new DB:MyDB;
//==============================================================================
public OnFilterScriptInit()
{
MyDB = db_open("MyPhone.db");
db_free_result(db_query(MyDB, "CREATE TABLE IF NOT EXISTS `Users` (`Name`,`Number`)"));
return 1;
}
public OnFilterScriptExit()
{
db_close(MyDB);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/number", true))
{
new query[256], DBResult:Result;
new pName[24];
GetPlayerName(playerid, pName, sizeof(pName));
format(query, sizeof(query), "SELECT * FROM `Users` WHERE `Name` = '%s'", pName);
Result = db_query(MyDB, query);
if(!db_num_rows(Result))
{
new MyNumber[10];
MyNumber[0] = '0';
MyNumber[1] = '7';
MyNumber[2] = (1 + random(8)) + '0';
for(new i = 3; i < 10; i++)
MyNumber[i] = random(10) + '0';
format(query, sizeof(query), "INSERT INTO `Users` (`Name`,`Number`) VALUES('%s','%s')", pName, MyNumber);
db_free_result(db_query(MyDB, query));
/*
format(query, sizeof(query), "INSERT INTO `Users` (`Name`) VALUES('%s')", pName);
db_free_result(db_query(MyDB, query));
SendClientMessage(playerid, -1, query);
format(query, sizeof(query), "INSERT INTO `Users` (`Number`) VALUES('%s')", MyNumber);
db_free_result(db_query(MyDB, query));
SendClientMessage(playerid, -1, query);
*/
format(query, 128, "Name: %s | Phone number: %s", pName, MyNumber);
SendClientMessage(playerid, -1, query);
}
return 1;
}
return 0;
}
Why the number contains the name too !?