OnPlayerDeath problem
#1

So far i have:

Код:
    new string[128];
    new NamePlayerID[MAX_PLAYER_NAME];
    new NameKillerID[MAX_PLAYER_NAME];
    GetPlayerName(playerid,NamePlayerID,sizeof(NamePlayerID));
    GetPlayerName(killerid,NameKillerID,sizeof(NameKillerID));
    format(string,sizeof(string),"*%s (%d) Died. Killed By: %s (%d).",NamePlayerID,playerid,NameKillerID,killerid);
    SendClientMessageToAll(0xAA3333AA,string);
This works perfectly for when I want it to show who died and who killed, but what I need is a separate message when someone dies without being killed by a person (lets say: died in a fire, or fell off a mountain, or just plain died, etc...) i want it to say:

Код:
%s (%d) Died.
WITHOUT a killer name and id (for when a person falls and died or dies from a fire)

or have a reason displayed beside it like so:

Код:
%s (%d) Died. Killed BY: %s (%d). (REASON HERE {Knife, MP5, Chainsaw, etc})
(Replace REASON HERE with %s)

Where the other %s and %d would be the player names and id.

Thanks.
Reply
#2

From the wiki: https://sampwiki.blast.hk/wiki/Weapons

I believe this should work. Just add a conditional to check if the reason is not a weapon. For example:
pawn Код:
if(reason >= 47) //Checks to see if they died from vehicle, helicopter blades, explosion, drowned, or fell
{
     format(string, sizeof(string), "%s (%d) Died." NamePlayerID, playerid);
     SendClientMessageToAll(0xAA3333AA, string);
}
else
{
//code you have
}
Try it out and let me know.
Reply
#3

I get this error

Код:
C:\Documents and Settings\Saif Muslim\Desktop\SA-MP 0.3b Server\gamemodes\lvtc3.pwn(849) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Documents and Settings\Saif Muslim\Desktop\SA-MP 0.3b Server\gamemodes\lvtc3.pwn(849) : warning 215: expression has no effect
C:\Documents and Settings\Saif Muslim\Desktop\SA-MP 0.3b Server\gamemodes\lvtc3.pwn(849) : warning 215: expression has no effect
C:\Documents and Settings\Saif Muslim\Desktop\SA-MP 0.3b Server\gamemodes\lvtc3.pwn(849) : error 001: expected token: ";", but found ")"
C:\Documents and Settings\Saif Muslim\Desktop\SA-MP 0.3b Server\gamemodes\lvtc3.pwn(849) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Saif Muslim\Desktop\SA-MP 0.3b Server\gamemodes\lvtc3.pwn(849) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
This is what I have all together:

pawn Код:
new string[128];
    new NamePlayerID[MAX_PLAYER_NAME];
    new NameKillerID[MAX_PLAYER_NAME];
    GetPlayerName(playerid,NamePlayerID,sizeof(NamePlayerID));
    GetPlayerName(killerid,NameKillerID,sizeof(NameKillerID));
    format(string,sizeof(string),"*%s (%d) Died. Killed By: %s (%d).",NamePlayerID,playerid,NameKillerID,killerid);
    SendClientMessageToAll(0xAA3333AA,string);

    if(reason >= 47) //Checks to see if they died from vehicle, helicopter blades, explosion, drowned, or fell
{
     format(string, sizeof(string), "%s (%d) Died." NamePlayerID, playerid); //LINE 849
     SendClientMessageToAll(0xAA3333AA, string);
}
else
{
//code you have
}
Reply
#4

Oops, typo. Put a comma between Died." and NamePlayerID on that line, like this:

pawn Код:
format(string, sizeof(string), "%s (%d) Died.", NamePlayerID, playerid);
Reply
#5

You will need this array of the weapon names:
pawn Код:
new aWeaponNames[][32] = {
    {"Unarmed (Fist)"}, // 0
    {"Brass Knuckles"}, // 1
    {"Golf Club"}, // 2
    {"Night Stick"}, // 3
    {"Knife"}, // 4
    {"Baseball Bat"}, // 5
    {"Shovel"}, // 6
    {"Pool Cue"}, // 7
    {"Katana"}, // 8
    {"Chainsaw"}, // 9
    {"Purple Dildo"}, // 10
    {"Big White Vibrator"}, // 11
    {"Medium White Vibrator"}, // 12
    {"Small White Vibrator"}, // 13
    {"Flowers"}, // 14
    {"Cane"}, // 15
    {"Grenade"}, // 16
    {"Teargas"}, // 17
    {"Molotov"}, // 18
    {"Empty Slot 1"}, // 19
    {"Empty Slot 2"}, // 20
    {"Empty Slot 3"}, // 21
    {"Colt 45"}, // 22
    {"Colt 45 (Silenced)"}, // 23
    {"Desert Eagle"}, // 24
    {"Normal Shotgun"}, // 25
    {"Sawnoff Shotgun"}, // 26
    {"Combat Shotgun"}, // 27
    {"Micro Uzi (Mac 10)"}, // 28
    {"MP5"}, // 29
    {"AK47"}, // 30
    {"M4"}, // 31
    {"Tec9"}, // 32
    {"Country Rifle"}, // 33
    {"Sniper Rifle"}, // 34
    {"Rocket Launcher"}, // 35
    {"Heat-Seeking Rocket Launcher"}, // 36
    {"Flamethrower"}, // 37
    {"Minigun"}, // 38
    {"Satchel Charge"}, // 39
    {"Detonator"}, // 40
    {"Spray Can"}, // 41
    {"Fire Extinguisher"}, // 42
    {"Camera"}, // 43
    {"Night Vision Goggles"}, // 44
    {"Infrared Vision Goggles"}, // 45
    {"Parachute"}, // 46
    {"Fake Pistol"} // 47
};
Then you can use it under OnPlayerDeath like so:
pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
   if( killerid != INVALID_PLAYER_ID )
   {
      new string[ 50 ], name[ MAX_PLAYER_NAME ];
      GetPlayerName( playerid, name, MAX_PLAYER_NAME );
      format( string, 50, "%s (%d) died. (%s)", name, playerid, aWeaponNames[ reason ] );
      SendClientMessageToAll( color, string );
   }
   return 1;
}
Reply
#6

Thanks, that fixed one of the problems, and I fixed the rest. But when I lit myself on fire, the death icon wasn't changed, how can I get different reasons for certain deaths? Like if I was standing in the fire and died, it would show the player on fire death icon and say
pawn Код:
%s (%d) Died In A Fire.
instead of
pawn Код:
%s (%d) Died.
Same with deaths like getting run over or knifed by someone, the messages would say
pawn Код:
%s (%d) Died. Killed By: %s (%d). (Run Over)
and

pawn Код:
%s (%d) Died. Killed By: %s (%d). (Knifed)
thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)