%d help
#1

I am attempting to make my first gamemode, which is going to be a deathmatch gamemode to learn, however after a respawn I would like it to tell you what your kill streak currently is, obviously it is going to be one, but I would like to figure out how to use %d to tell the player. If that made any sense at all...

Here is the code:

Код:
public OnPlayerSpawn(playerid)
{
	SendClientMessage(playerid, COLOR_RED, "Your objective is simple, find and kill all others.  It is every man for himself!");
	killstreak = 1;
	format("Your currently have a %d killstreak!", killstreak);
	SendClientMessage(playerid, COLOR_RED, killstreak);
	
	return 1;
}
The main problem I am having is the "format" part. I have looked everywhere I can not understand it, nor can I understand how the wiki stated it. I have been toying around with this for the past hour and a half and no luck. At one point the format part looked something like this:

Код:
format(killstreak, sizeof(killstreak), "Your currently have a %d killstreak!", killstreak);
But it looked retarded and was not working, so I botched it to my current creation.
Reply
#2

Use %i.
Reply
#3

Your code makes no sense. Where do you define 'killstreak'? Is it a string? Is it an integer?

You're trying to format an integer then display the integer in the format, which makes no sense at all.

Quote:
Originally Posted by Drebin
Посмотреть сообщение
Use %i.
No, that's a pointless suggestion. %i and %d are both placeholders for integers/digits.
Reply
#4

pawn Код:
public OnPlayerSpawn(playerid)
{
    new msg[128];//we  created new string that we will format
    SendClientMessage(playerid, COLOR_RED, "Your objective is simple, find and kill all others.  It is every man for himself!");
    killstreak = 1;
    format(msg,128,"Your currently have a %d killstreak!", killstreak);
    SendClientMessage(playerid, COLOR_RED, msg);
   
    return 1;
}
Reply
#5

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Your code makes no sense. Where do you define 'killstreak'? Is it a string? Is it an integer?

You're trying to format an integer then display the integer in the format, which makes no sense at all.



No, that's a pointless suggestion. %i and %d are both placeholders for integers/digits.
It was a variable on the top of the script.

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
pawn Код:
public OnPlayerSpawn(playerid)
{
    new msg[128];//we  created new string that we will format
    SendClientMessage(playerid, COLOR_RED, "Your objective is simple, find and kill all others.  It is every man for himself!");
    killstreak = 1;
    format(msg,128,"Your currently have a %d killstreak!", killstreak);
    SendClientMessage(playerid, COLOR_RED, msg);
   
    return 1;
}
Thanks it fixed the error.
Reply
#6

Don't you want to know why?
Reply
#7

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
Don't you want to know why?
I would love to, if one is willing to explain.
Reply
#8

You have to create new string variable as I did
pawn Код:
new msg[128];
Then format function is used with following params
Код:
(output[], len, const format[], {Float,_}:...)
In your function you don't have output and it's length. Length of output is that number after variable name (128 means 128 character spaces). You formatted message on good way but you didn't have output so it didn't have where to store that formatted message. Also in SendClientMessage you said to sent killstreak which is normal number. There you have to put formatted message like me
pawn Код:
SendClientMessage(playerid, COLOR_RED, msg);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)