Formatting a string with an unknown number of parameters
#1

Hi guys. I am trying to make a simple /weapons command. It's function is to show you all the weapons that the player has through SendClientMessage. Now, the player might have 2, 3 or more weapons with him. How would I format my string such that all the weapons he has are included? What is the most efficient way of scripting this? Can someone enlighten me with an example or a detailed explanation on how to script this. Much appreciated!
Reply
#2

You could possibly use strcat to add to the string:
e.g.
strcat(MYSTRING,"This is a message",sizeof(MYSTRING));
Reply
#3

Yes, I see that that is a possible method to use, but works for only 2 weapons. But what if the player has 3 or more weapons? Is there a universal way to do it, rather than checking the number of weapons and using strcat?
Reply
#4

either keep formatting string and sendclientmessage after every format or use strcat to join 2 string then again that joined string with any other thing...

How can you keep fromatting string and sendclientmessage after it:

pawn Код:
format(string,sizeof(string)," Weapons: Weap1,weap2 etc..");// Will format the string according to the scripter
SendClientMessage(playerid,colour,string);// will send the last formatted string
format(string,sizeof(string),"Weapons: weap3 , Weap4 etc.."); // WIll reformat the string
SendClientMessage(playerid,colour,string);//Will send the last formatted string
format(string,sizeof(string)," Weapons: Weap1,weap2 etc..");
SendClientMessage(playerid,colour,string);
format(string,sizeof(string),"Weapons: weap5 , Weap6 etc..");
SendClientMessage(playerid,colour,string);
// And So On
As you are reformatting the string you are storing some new values in the string arrays formatting it and then you are sending the message so it is also a way to show the weapons
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)