When player kill another player get MSG"You killed [NAME]" -I got problems with that script
#1

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(playeridkilleridreason)
{
    new 
wstring[128];
    new 
lstring[128];
    
SendDeathMessage(killeridplayeridreason);
    
PlayerInfo[killerid][pKills]++;
    
PlayerInfo[playerid][pDeaths]++;
    new 
aname[MAX_PLAYER_NAME];
    new 
dname[MAX_PLAYER_NAME];
    
GetPlayerName(playeridanamesizeof(aname));
    
GetPlayerName(killeriddnamesizeof(dname));
    
SetPlayerScore(killeridGetPlayerScore(killerid) + 1);
    
format(wstring,sizeof(wstring),"~g~ You killed %d !",aname);
    
GameTextForPlayer(killeridwstring20005);
    
format(lstring,sizeof(lstring),"~r~ %d killed you !",dname);
    
GameTextForPlayer(playeridlstring20005);
    return 
1;

Reply
#2

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;
}
Reply
#3

I tried your code in my previous thread, but it doesnt works too ;(
Reply
#4

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.
Reply
#5

Nope it doesnt print msg in console/server log
It just says "You killed [Random number like 98]"
Reply
#6

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.
Reply
#7

Ok, i am gonna test ur script and edit my post
Reply
#8

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.
Reply
#9

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.
Reply
#10

I am using the script of Konstantinos, and works , i cant+rep you cos i have 0 rep Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)