[SQL] Changename command
#1

Hi! Can i request for /changename command that will change my name and update also my SQL table? Thanks!
Reply
#2

pawn Код:
new query[150];

strcat(query, "UPDATE `user_table` SET `name` = '");
strcat(query, new_name);
strcat(query, "' WHERE `name` = '");
strcat(query, old_name);
strcat(query, "'");

// run a query
Naming is self explanatory, plus learn SQL from here maybe: http://www.tutorialspoint.com
Reply
#3

Quote:
Originally Posted by Gammix
Посмотреть сообщение
pawn Код:
new query[150];

strcat(query, "UPDATE `user_table` SET `name` = '");
strcat(query, new_name);
strcat(query, "' WHERE `name` = '");
strcat(query, old_name);
strcat(query, "'");

// run a query
Naming is self explanatory, plus learn SQL from here maybe: http://www.tutorialspoint.com
5 x strcat wtf
PHP код:
new query[150];
format(query,sizeof query,"UPDATE `user_table` SET `name` = '%s' WHERE `name` = '%s'",new_name,old_name); 
Reply
#4

Thank you both of you! Now I have another problem in my /g command

Here's my script

Quote:

CMD:g(playerid, params[])
{
new s_gchat[145], gchat[145], t_gchat[145], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));

if (sscanf(params, "s[145]", gchat)) return SendClientMessage(playerid, -1, "{FFFFFF}Usage: {00FF00}/g <text>");
if (gchat_timer[playerid] < gettime())
{
if (!Player[playerid][Title])
{
gchat_timer[playerid] = gettime() + GCHAT_TIME;
format(s_gchat, sizeof(s_gchat), "(( [%d] Level %d Player %s: %s ))", GetPlayerIdFromName(playername), Player[playerid][Score], GetName2(playerid), gchat);
SendClientMessageToAll(COLOR_ORANGE, s_gchat);
return 1;
}
else
{
gchat_timer[playerid] = gettime() + GCHAT_TIME;
format(s_gchat, sizeof(s_gchat), "(( [%d] %s %s: %s ))", GetPlayerIdFromName(playername), Player[playerid][Title], GetName2(playerid), gchat);
SendClientMessageToAll(COLOR_ORANGE, s_gchat);
return 1;
}
}
else
{
format(t_gchat, sizeof(t_gchat), "You must wait %i seconds before speaking again in this channel.", gchat_timer[playerid] - gettime());
SendClientMessage(playerid, COLOR_GREY, t_gchat);
return 1;
}
}

I have my title system in my server, now when i try to add title in my character, it will show like this

Quote:

(([0] Test_Name: Hello))

instead of this
Quote:

(([0] Title Test Name: Hello))

And my problem is if the Title Row is empty, its shows blank space instead to this

Quote:

(([0] Level 1 Player Test Name: Hello))

Is there wrong with my script? Thanks!
Reply
#5

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
5 x strcat wtf
PHP код:
new query[150];
format(query,sizeof query,"UPDATE `user_table` SET `name` = '%s' WHERE `name` = '%s'",new_name,old_name); 
I have seen quiet people saying strcat is faster than format, and it is but only at certain situations. You are 2x faster with format than mine strcat, that is pretty interesting for me, because i never tested the speed comparison before (format: 25, strcat: 50).
Reply
#6

@eikzdej:
Try this:
PHP код:
CMD:g(playerid,params[])
{
    new 
string[145],nachricht[100],playername[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,playername,sizeof(playername));
    if(
sscanf(params,"s[100]",nachricht))return SendClientMessage(playerid,-1,"Usage: {00FF00}/g <text>");
    if(
gchat_timer[playerid] < gettime())
    {
        if(!
strlen(Player[playerid][Title]))
        {
            
gchat_timer[playerid] = gettime() + GCHAT_TIME;
            
format(string,sizeof string,"(( [%d] Level %d Player %s: %s ))",playerid,Player[playerid][Score],playername,nachricht);
            
SendClientMessageToAll(COLOR_ORANGE,string);
            return 
1;
        }
        else
        {
            
gchat_timer[playerid] = gettime() + GCHAT_TIME;
            
format(string,sizeof string,"(( [%d] %s %s: %s ))",playerid,Player[playerid][Title],playername,nachricht);
            
SendClientMessageToAll(COLOR_ORANGE,string);
            return 
1;
        }
    }
    else
    {
        
format(string,sizeof string,"You must wait %i seconds before speaking again in this channel.",gchat_timer[playerid] - gettime());
        
SendClientMessage(playerid,COLOR_GREY,string);
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by Mencent
Посмотреть сообщение
@eikzdej:
Try this:
PHP код:
CMD:g(playerid,params[])
{
    new 
string[145],nachricht[100],playername[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,playername,sizeof(playername));
    if(
sscanf(params,"s[100]",nachricht))return SendClientMessage(playerid,-1,"Usage: {00FF00}/g <text>");
    if(
gchat_timer[playerid] < gettime())
    {
        if(!
strlen(Player[playerid][Title]))
        {
            
gchat_timer[playerid] = gettime() + GCHAT_TIME;
            
format(string,sizeof string,"(( [%d] Level %d Player %s: %s ))",playerid,Player[playerid][Score],playername,nachricht);
            
SendClientMessageToAll(COLOR_ORANGE,string);
            return 
1;
        }
        else
        {
            
gchat_timer[playerid] = gettime() + GCHAT_TIME;
            
format(string,sizeof string,"(( [%d] %s %s: %s ))",playerid,Player[playerid][Title],playername,nachricht);
            
SendClientMessageToAll(COLOR_ORANGE,string);
            return 
1;
        }
    }
    else
    {
        
format(string,sizeof string,"You must wait %i seconds before speaking again in this channel.",gchat_timer[playerid] - gettime());
        
SendClientMessage(playerid,COLOR_GREY,string);
    }
    return 
1;

Thanks, but still show empty blank space, i don't know the code that checks if the row is empty or not. Maybe someone can help me?

And Also, i already add (!strlen(Player[playerid][Title])) but it does not read this line,

Quote:

format(string,sizeof string,"(( [%d] Level %d Player %s: %s ))",playerid,Player[playerid][Score],playername,nachricht);

Reply
#8

bump
Reply
#9

bump?
Reply
#10

Help!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)