DarkRp - Edit %s

I want to make it so that when someone is wanted it says “Blah is wanted by the police! (Officer Bob)”

The code just says “%s is wanted by the police!” So if I put “%s is wanted by the police! (Officer %s)” how will lua interpret %s?

Look in languages_sh.lua or something like that. It formats it and takes the first and second string for string.format.

As to speak, whatever is used in string.format will replace the %s. If you do what you suggest then I presume it would just use the first name unless you added a new string to the string.format.

[lua]string.format("%s is wanted by the police" , “Officer Bob”)[/lua]

Never used string.format myself, should work though.



What you suggested there will make it Officer Bob is wanted by the police: where as I believe he is trying to achieve the effect of:

[lua]string.format( “%s is wanted by the police (Officer %s)”, “wantedplayer”, “bob” );[/lua]

Wrote it in under a second, oh well. At least it would work as an example.

Yeah pretty much, I’m just somewhat familiar with DarkRP and I’m sure that it’s used like that (and similar to as you said).


But how does the base DarkRP Know what the %s is, I never saw it anywhere.

It’s a way for languages to recognize a string inside a string without having to use concatenation. Low level programming languages use it a lot.

You can usually identify them easily, for example,

%i is an integer, a number.
%.2f is a float with 2 decimals, ex. 4.15

DarkRP uses it inside the actual functions. What it does is like… Hmm…

If you have in the languages file say…
[lua]wanted = “%s has been wanted by police!”[/lua]

Then in the main.lua file (I presume) there will be a function say
[lua]function Wanted( pl, WantedPlayer )
// code

Imagine the WantedPlayer:Name() = Bob.

In that function there will be something such as:
[lua]Notify( pl, 1, 4, string.format( wanted, WantedPlayer:Name() ) );[/lua]

That will then notify the player:

Bob has been wanted by police!

They do this because they probably use that same string a lot in different functions - it saves time writing it out again and again.

Pretty simply put, %s is a format code for string, so when you put an %s in a string in the first argument of string.format(), whatever string is put in the second argument is what shows up in place of %s, and if you were to have more than one %s, then you would just add another string argument for however many %s there are.