When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
bustern - 15.09.2013
I tried to make that, but when i kill someone it says"You killed 69" 69 is not the player's name
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
new wstring[128];
new lstring[128];
SendDeathMessage(killerid, playerid, reason);
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
new aname[MAX_PLAYER_NAME];
new dname[MAX_PLAYER_NAME];
GetPlayerName(playerid, aname, sizeof(aname));
GetPlayerName(killerid, dname, sizeof(dname));
SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
format(wstring,sizeof(wstring),"~g~ You killed %d !",aname);
GameTextForPlayer(killerid, wstring, 2000, 5);
format(lstring,sizeof(lstring),"~r~ %d killed you !",dname);
GameTextForPlayer(playerid, lstring, 2000, 5);
return 1;
}
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
Konstantinos - 15.09.2013
I thought I replied to your previous thread, but it got deleted? Anyways, you need to check if the killer is valid to use it as index (in arrays, otherwise it will crash your server). Also, to insert a string into format you need to use
%s. You used %d which is for integers.
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
SendDeathMessage(killerid, playerid, reason);
PlayerInfo[playerid][pDeaths]++;
if(killerid != INVALID_PLAYER_ID)
{
PlayerInfo[killerid][pKills]++;
new wstring[128], aname[MAX_PLAYER_NAME], dname[MAX_PLAYER_NAME];
GetPlayerName(playerid, aname, sizeof(aname));
GetPlayerName(killerid, dname, sizeof(dname));
SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
format(wstring,sizeof(wstring),"~g~ You killed %s !",aname);
GameTextForPlayer(killerid, wstring, 2000, 5);
format(wstring,sizeof(wstring),"~r~ %s killed you !",dname);
GameTextForPlayer(playerid, wstring, 2000, 5);
}
return 1;
}
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
bustern - 15.09.2013
I tried your code in my previous thread, but it doesnt works too ;(
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
Konstantinos - 15.09.2013
DO:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
print("OnPlayerDeath is being called..");
SendDeathMessage(killerid, playerid, reason);
PlayerInfo[playerid][pDeaths]++;
if(killerid != INVALID_PLAYER_ID)
{
PlayerInfo[killerid][pKills]++;
new wstring[128], aname[MAX_PLAYER_NAME], dname[MAX_PLAYER_NAME];
GetPlayerName(playerid, aname, sizeof(aname));
GetPlayerName(killerid, dname, sizeof(dname));
SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
format(wstring,sizeof(wstring),"~g~ You killed %s !",aname);
GameTextForPlayer(killerid, wstring, 2000, 5);
format(wstring,sizeof(wstring),"~r~ %s killed you !",dname);
GameTextForPlayer(playerid, wstring, 2000, 5);
}
return 1;
}
Does it print the message in the console/server log?
If you do not check if the killer is valid player can cause problems and the OnPlayerDeath callback not being called at all.
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
bustern - 15.09.2013
Nope it doesnt print msg in console/server log
It just says "You killed [Random number like 98]"
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
Konstantinos - 15.09.2013
Well, make sure again that the code you're using is the last I gave you. It makes no sense not to print the message but being called and send the gametext to a player. And like I said, you used %d instead of %s and that's why it did not print the name but a random number.
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
bustern - 15.09.2013
Ok, i am gonna test ur script and edit my post
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
Mattakil - 15.09.2013
In OnPlayerDeath:
pawn Код:
new kstring[100],
dstring[100];
format(dstring, sizeof(dstring), %s has killed you!, GetName(killerid));
format(dstring, sizeof(dstring), You killed %s!, GetName(playerid));
GameTextForPlayer(killerid, "~r~kstring", 5000, 5);
GameTextForPlayer(playerid, "~r~dstring", 5000, 5);
SOMEWHERE IN YOUR SCRIPT:
pawn Код:
stock GetName(playerid)
{
new
name[24];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
Note: The stock GetName is not really needed but it is quicker than typing all the stuff to do GetPlayerName.
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
Konstantinos - 15.09.2013
Quote:
Originally Posted by Mattakil
In OnPlayerDeath:
pawn Код:
new kstring[100], dstring[100]; format(dstring, sizeof(dstring), %s has killed you!, GetName(killerid)); format(dstring, sizeof(dstring), You killed %s!, GetName(playerid)); GameTextForPlayer(killerid, "~r~kstring", 5000, 5); GameTextForPlayer(playerid, "~r~dstring", 5000, 5);
SOMEWHERE IN YOUR SCRIPT:
pawn Код:
stock GetName(playerid) { new name[24]; GetPlayerName(playerid, name, sizeof(name)); return name; }
Note: The stock GetName is not really needed but it is quicker than typing all the stuff to do GetPlayerName.
|
Many mistakes. Declaring two string when 1 is enough.
format needs "" in the message, you forgot them. And you need to send the formatted string, but instead of that, it will show in red
kstring and
dstring.
And GetName is not recommended. It keeps calling GetPlayerName function when you can store the name once they connect and use it.
Re: When player kill another player get MSG"You killed [NAME]" -I got problems with that script -
bustern - 15.09.2013
I am using the script of Konstantinos, and works

, i cant+rep you cos i have 0 rep

Thanks