Posts: 265
Threads: 59
Joined: Sep 2013
Hello everyone, I am going to lose my mind figuring out how to use these strings! I've been formatting a name string for the last 25 minutes, and I failed everytime ending up with the string being shot outta my PC.
So anyways, how can I create a similar message:
pawn Код:
Welcome to XXX(servname) %s! Enjoy your stay!
And if anyone could explain to me the strings thing, I'd be greatfull!
Thanks ahead.
Posts: 265
Threads: 59
Joined: Sep 2013
Quote:
Originally Posted by DanishHaq
Ok, so strings need to be used only when you're going to use variables in that string, i.e. for something like "Hello", you wouldn't need a string because it doesn't contain a variable and you can use SendClientMessage for that, but for something like "Hello %s, welcome to the server!", you'd need to use a string because it has a variable. Here's an example of what I think you're trying to do:
pawn Код:
public OnPlayerConnect(playerid) { new cname[MAX_PLAYER_NAME], cstring[100]; // the max_player_name is actually 24, and the cstring is set to 100 because that's how many characters you'd need, it's different in all cases GetPlayerName(playerid, cname, sizeof(cname)); // this will get the player name, with the sizeof 24 characters format(cstring, sizeof(cstring), "Welcome to XXX(servname) %s! Enjoy your stay!", cname); /* now, this is the bit you want to understand, ok, so here we're setting the string by telling the script to format it first, and then we're using the variable of the cstring that we made earlier, in the speech marks we have our text that we want, and the %s is a string which we'll be using, strings are letters & numbers remember. Ok, so after that, we have a comma and then cname, that will tell the script that the %s was in fact the variable of cname. */ SendClientMessage(playerid, 0xFFFFFFFF, cstring); // sends the message return 1; }
Read below too, that explains to you how to do the server name string, with a define too. I don't know if you wanted this or that, but read us both haha.
|
Thank you.