Random messages with %s - 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: Random messages with %s (
/showthread.php?tid=330661)
Random messages with %s -
MP2 - 02.04.2012
Gosh, I can't believe I need help with this.
I want random messages that have one string inserted in to them, which will be a random player's name - I am making my NPCs say random shit every few minutes. For example
pawn Код:
new npc_phrases[][] = {
"Blah Blah Blah %s.",
"Hello %s.",
"%s sucks."
};
// Then doing
format(text_to_send, sizeof(), "%s", npc_phrases[whatever], playername);
But it doesn't work, and just prints '%s' without the substitution.
Re: Random messages with %s -
DarkScripter - 02.04.2012
pawn Код:
new npc_phrases[][] = {
"Blah Blah Blah %s.",
"Hello %s.",
"%s sucks."
};
// Then doing
format(text_to_send, sizeof(text_to_send), "%s", npc_phrases[random(sizeof(npc_phrases))], playername);
Re: Random messages with %s -
[ABK]Antonio - 02.04.2012
Can try this out
pawn Код:
new npc_phrases[][] = {
"Blah Blah Blah %s.",
"Hello %s.",
"%s sucks."
};
// Then doing
new rand = random(sizeof(npc_phrases));
format(text_to_send, sizeof(text_to_send), npc_phrases[rand], playername);
I say maybe this on the basis of...
pawn Код:
#define PlayerPath "Something/%s.ini"
format(file, sizeof(file), PlayerPath, Name(playerid));
I know that works, not sure about what I posted above
Re: Random messages with %s -
[HiC]TheKiller - 02.04.2012
Why don't you just use strfind, find the %s and change it to the correct value? There are always other methods to approach this though
![Wink](images/smilies/wink.png)
.
Re: Random messages with %s -
MP2 - 02.04.2012
Antonio's method works, thanks.