Quick request of a bug that closes local server
#1

Hello there, I've been testing this on local server, and whenever my friend does "/accepthelp" the server closes automatically, what's the issue, it's bugging me and I can't seem to find it.

Код:
if(strcmp(cmd, "/accepthelp", true) == 0)
	{
	new id, msgstring[150];
	tmp = strtok(cmdtext, idx);
	if(!strlen(tmp))
	{
	      SendClientMessage(playerid, COLOR_WHITE, "USAGE: /accepthelp [playerid]");
          return 1;
    }
	id = strvalEx(tmp);
	{
	    if(PlayerInfo[playerid][pHelper] >= 1)
	    {
	        if(IsPlayerConnected(id) &&  ActiveHelp[id] == 1)
	        {
				if(HelpAccepted[id] == 1)
				{
					  SendClientMessage(playerid, COLOR_GREY, "* This player's help request has already been taken!");
					  return 1;
				}
				if(ActiveHelp[id] == 0)
				{
					  SendClientMessage(playerid, COLOR_GREY, "* This player doesn't have an active help request!");
					  return 1;
				}
	            format(msgstring, sizeof(string), "You have accepted %s's help request.", GetName(id));
	            SendClientMessage(playerid, TEAM_AZTECAS_COLOR, msgstring);
	            format(msgstring, sizeof(string), "Community Advisor %s has taken your request and will be with you shortly.", sendername);
	            SendClientMessage(id, TEAM_AZTECAS_COLOR, msgstring);
	            format(msgstring, sizeof(string), "Community Advisor %s has taken %s's help request.", sendername, GetName(id));
	            SendHelperMessage(0x02CCCCFF, msgstring);
	            format(msgstring, sizeof(string), "[HELP TEXT:] %s", HelpText[id]);
	            SendClientMessage(playerid, COLOR_GREEN, msgstring);
	            SendClientMessage(playerid, COLOR_WHITE, "HINT: You are handling %s's request, you can use /hgoto, and /hgethere.");
	            SendClientMessage(playerid, COLOR_WHITE, "HINT: Use /reply [message] to talk to the help requester.");
	            SendClientMessage(id, COLOR_WHITE, "HINT: Use /reply [message] to talk with your advisor.");
	            IsHelping[playerid] = 1;
	            HelpAccepted[id] = 1;
	            HelpingWho[playerid] = GetName(id);
	            new CHANNEL = random(300);
	            HelperNewbieChannel[id] = CHANNEL;
	            HelperNewbieChannel[playerid] = CHANNEL;
	        }
	        else
	        {
	            SendClientMessage(playerid, COLOR_WHITE, "There are no active help requests from the player.");
	        }
	    }
	}
	return 1;
Reply
#2

The server crashes because of this line:
pawn Код:
SendClientMessage(playerid, COLOR_WHITE, "HINT: You are handling %s's request, you can use /hgoto, and /hgethere.");
Never use specifiers directly in SendClientMessage(ToAll). If you want to custom the message, format it like the previous.

Review that line
pawn Код:
HelpingWho[playerid] = GetName(id);
if you're trying to copy strings, that is not the way.
pawn Код:
#if !defined strcpy
    #define strcpy(%0,%1) strcat((%0[0] = EOS, %0), %1)
#endif
and then you just do:
pawn Код:
strcpy(HelpingWho[playerid], GetName(id), MAX_PLAYER_NAME);
All that assuming HelpingWho is string and by the way, having an ID might be a better idea.
Reply
#3

Hey thanks for trying to help but I'm newbie and the things you mentioned are still to be taught. Can someone possibly fix the code above and re-post? That'd be great!
Reply
#4

PHP код:
if(strcmp(cmd"/accepthelp"true) == 0)
    {
    new 
idmsgstring[150];
    
tmp strtok(cmdtextidx);
    if(!
strlen(tmp))
    {
          
SendClientMessage(playeridCOLOR_WHITE"USAGE: /accepthelp [playerid]");
          return 
1;
    }
    
id strvalEx(tmp);
    {
        if(
PlayerInfo[playerid][pHelper] >= 1)
        {
            if(
IsPlayerConnected(id) &&  ActiveHelp[id] == 1)
            {
                if(
HelpAccepted[id] == 1)
                {
                      
SendClientMessage(playeridCOLOR_GREY"* This player's help request has already been taken!");
                      return 
1;
                }
                if(
ActiveHelp[id] == 0)
                {
                      
SendClientMessage(playeridCOLOR_GREY"* This player doesn't have an active help request!");
                      return 
1;
                }
                
format(msgstringsizeof(string), "You have accepted %s's help request."GetName(id));
                
SendClientMessage(playeridTEAM_AZTECAS_COLORmsgstring);
                
format(msgstringsizeof(string), "Community Advisor %s has taken your request and will be with you shortly."sendername);
                
SendClientMessage(idTEAM_AZTECAS_COLORmsgstring);
                
format(msgstringsizeof(string), "Community Advisor %s has taken %s's help request."sendernameGetName(id));
                
SendHelperMessage(0x02CCCCFFmsgstring);
                
format(msgstringsizeof(string), "[HELP TEXT:] %s"HelpText[id]);
                
SendClientMessage(playeridCOLOR_GREENmsgstring);
                    
format(msgstringsizeof(string), "HINT: You are handling %s's request, you can use /hgoto, and /hgethere."GetName(id));
                    
SendClientMessage(playeridCOLOR_WHITEmsgstring);
                
SendClientMessage(playeridCOLOR_WHITE"HINT: Use /reply [message] to talk to the help requester.");
                
SendClientMessage(idCOLOR_WHITE"HINT: Use /reply [message] to talk with your advisor.");
                
IsHelping[playerid] = 1;
                
HelpAccepted[id] = 1;
                
HelpingWho[playerid] = GetName(id);
                new 
CHANNEL random(300);
                
HelperNewbieChannel[id] = CHANNEL;
                
HelperNewbieChannel[playerid] = CHANNEL;
            }
            else
            {
                
SendClientMessage(playeridCOLOR_WHITE"There are no active help requests from the player.");
            }
        }
    }
    return 
1
This maybe work, if i'm not wrong
Reply
#5

Thanks, case solved!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)