Quick request of a bug that closes local server -
Geazy - 30.03.2016
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;
Re: Quick request of a bug that closes local server -
Konstantinos - 30.03.2016
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.
Re: Quick request of a bug that closes local server -
Geazy - 31.03.2016
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!
Re: Quick request of a bug that closes local server -
oMa37 - 31.03.2016
PHP код:
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);
format(msgstring, sizeof(string), "HINT: You are handling %s's request, you can use /hgoto, and /hgethere.", GetName(id));
SendClientMessage(playerid, COLOR_WHITE, msgstring);
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;
This maybe work, if i'm not wrong
Re: Quick request of a bug that closes local server -
Geazy - 31.03.2016
Thanks, case solved!