Adding prefix to a const string[] ? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Adding prefix to a const string[] ? (
/showthread.php?tid=144548)
Adding prefix to a const string[] ? -
dcmd_crash - 27.04.2010
Here are two functions I use frequently .. infact, to say the least I use them in all my Admin command .. and there's alot. So .. to make my life easier, I'd like to add a "prefix" of sorts to these that will be sent before the actual string.. here's the functions:
pawn Код:
stock MessageToMods(color,const string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 2) SendClientMessage(i, color, string);
}
return 1;
}
stock MessageToAdmins(color,const string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 3) SendClientMessage(i, color, string);
}
return 1;
}
Say I want to add the prefix "Admin Alert: " to them before the string itself .. is this how I would do it?
pawn Код:
stock MessageToAdmins(color,const string[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new str[128];
format(str, sizeof(str), "Admin Message: %s", string);
if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 3) SendClientMessage(i, color, str);
}
return 1;
}
Re: Adding prefix to a const string[] ? -
dice7 - 27.04.2010
const means It's a constant, which means that you cannot edit it. Just remove the 'const' out of the function header and you'll be able to edit it
Re: Adding prefix to a const string[] ? -
dcmd_crash - 27.04.2010
Just tested the function .. works perfectly lol. Thanks anyway
Re: Adding prefix to a const string[] ? -
Joe Staff - 27.04.2010
Quote:
Originally Posted by dice7
const means It's a constant, which means that you cannot edit it. Just remove the 'const' out of the function header and you'll be able to edit it
|
Correct, but you don't want to edit the string itself, because that could mess up other functions that use that string.
Your method works _❼_ but creating a variable in a loop is tremendously inefficient.
pawn Код:
stock MessageToAdmins(color,const string[])
{
new str[128];
format(str, sizeof(str), "Admin Message: %s", string);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 3) SendClientMessage(i, color, str);
}
return 1;
}
Re: Adding prefix to a const string[] ? -
dcmd_crash - 27.04.2010
Quote:
Originally Posted by Joe Staff
Quote:
Originally Posted by dice7
const means It's a constant, which means that you cannot edit it. Just remove the 'const' out of the function header and you'll be able to edit it
|
Correct, but you don't want to edit the string itself, because that could mess up other functions that use that string.
Your method works _❼_ but creating a variable in a loop is tremendously inefficient.
pawn Код:
stock MessageToAdmins(color,const string[]) { new str[128]; format(str, sizeof(str), "Admin Message: %s", string); for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i) == 1) if (PlayerInfo[i][Level] >= 3) SendClientMessage(i, color, str); } return 1; }
|
Lol, I think that was a mistake from my earlier days :P There's probably a whole load more in my gamemode that I need to iron out
Thanks for telling me