Random messages with %s
#1

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.
Reply
#2

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);
Reply
#3

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
Reply
#4

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 .
Reply
#5

Antonio's method works, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)