25.02.2013, 00:56
I have a cellphone system so I decided to make a mailbox.
my question is if the code is good to use, and not taking to much memory.
this is my code:
my question is if the code is good to use, and not taking to much memory.
this is my code:
pawn Код:
#define MAX_PLAYER_SMS 5
enum SMS_INFO
{
smsID,
smsOwner[256],
smsInfo[256],
smsFrom,
smsOn,
}
new SmsInfo[MAX_PLAYER_SMS][MAX_PLAYERS][SMS_INFO];
CMD:smsbox(playerid, params[])
{
new query[256];
format(query, sizeof(query), "SELECT * FROM `smslog` WHERE `name` = '%s'", GetName(playerid));
mysql_function_query(dbHandle, query, true, "DisplaySMSLog", "i", playerid);
return 1;
}
CMD:deletesms(playerid, params[])
{
new query[256], smsslot;
if(sscanf(params,"d",smsslot)) return SyntaxMSG(playerid, "/deletesms [sms-slot] (/smsbox)");
if(!SmsInfo[smsslot][playerid][smsOn]) return SCM(playerid, -1, "Invalid SMS slot id.");
format(query, sizeof(query), "DELETE FROM `smslog` WHERE `id` = %d", SmsInfo[smsslot][playerid][smsID]);
mysql_function_query(dbHandle, query, true, "OnPlayerDeleteSMS", "ii", playerid, smsslot);
return 1;
}
forward OnPlayerDeleteSMS(playerid, smsslot);
public OnPlayerDeleteSMS(playerid, smsslot)
{
SmsInfo[smsslot][playerid][smsOn] = 0;
return 1;
}
forward DisplaySMSLog(playerid);
public DisplaySMSLog(playerid)
{
new rows, fields, str[256], temp[128], total = 0;
cache_get_data(rows, fields);
if(!rows) return SCM(playerid, COLOR_YELLOWG, "You have no SMS's in your smsbox.");
while(total < rows)
{
cache_get_row(total, 0, temp), SmsInfo[total][playerid][smsID] = strval(temp);
cache_get_row(total, 1, SmsInfo[total][playerid][smsOwner]);
cache_get_row(total, 2, temp), SmsInfo[total][playerid][smsFrom] = strval(temp);
cache_get_row(total, 3, SmsInfo[total][playerid][smsInfo]);
SmsInfo[total][playerid][smsOn] = 1;
format(str, sizeof(str), "SMS %d: from %d, %s.", total, SmsInfo[total][playerid][smsFrom], SmsInfo[total][playerid][smsInfo]);
SCM(playerid, COLOR_YELLOWG, str);
total++;
}
return 1;
}
stock AddSMSToMySQL(playerid, fromnumber, info[])
{
new Query[500];
format(Query, sizeof(Query), "INSERT INTO `smslog` (name, fromnumber, info) VALUES('%s', %d, '%s')",GetName(playerid), fromnumber, info);
mysql_function_query(dbHandle, Query, true, "", "");
return 1;
}