SA-MP Forums Archive
MySQL Question important. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Question important. (/showthread.php?tid=418508)



MySQL Question important. - PaulDinam - 25.02.2013

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:

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;
}



Re: MySQL Question important. - Scenario - 25.02.2013

Um... you're using threaded queries, so... you have [almost] nothing to worry about.


Re: MySQL Question important. - PaulDinam - 25.02.2013

i need a command to remove sms from exact slot.. i've no idea how to do it


Re: MySQL Question important. - thefatshizms - 25.02.2013

Well firstly why use 256 cells for chat when it can only hold 128?
https://sampforum.blast.hk/showthread.php?tid=55261


Re: MySQL Question important. - Vince - 25.02.2013

I wonder why you are using slots in the first place. Just load the data from the database when you need it. Copying the data to variables in the gamemode serves no purpose at all.


Re: MySQL Question important. - PaulDinam - 25.02.2013

but if I won't load into a variables, there will be no way to delete an SMS in exact slot


Re: MySQL Question important. - PaulDinam - 25.02.2013

bump


Re: MySQL Question important. - PaulDinam - 25.02.2013

someone?


Re: MySQL Question important. - Scenario - 25.02.2013

Quote:
Originally Posted by PaulDinam
Посмотреть сообщение
but if I won't load into a variables, there will be no way to delete an SMS in exact slot
... load just the SMS ID into a variable?