Distance kills
#1

Hello,

I tried to do something to know who kills with weapon type and with distance.
so I did like that:
At the top of script under main()

pawn Код:
forward Float:GetDistanceBetweenPlayers(p1,p2);
At the top under forward Float ....

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
        {" "}, // 19
        {" "}, // 20
        {" "}, // 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
};
At the end of my gamemode

pawn Код:
public Float:GetDistanceBetweenPlayers(p1,p2){
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
return -1.00;
}
GetPlayerPos(p1,x1,y1,z1);
GetPlayerPos(p2,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));

}
Then at OnPlayerDeath this:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
     
       
        if(killerid != INVALID_PLAYER_ID)
        {
        new pname[30];
        new string[95];
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You were killed by %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
        SetPlayerScore(playerid,(GetPlayerScore(playerid))-1);
        GivePlayerMoney(playerid, -500);
        SendClientMessage(playerid,COLOR_RED,"You lost 500$");
        SendClientMessage(playerid,COLOR_RED,"You lost 1pt score");
        }
        else
        (
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You killed %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(killerid, playerid, reason);
        SetPlayerScore(killerid,(GetPlayerScore(killerid))+1);
        GivePlayerMoney(killerid, 1000);
        SendClientMessage(killerid,COLOR_GREEN,"You earned 1000$");
        SendClientMessage(killerid,COLOR_GREEN,"You won 1pt score");
        }
        return 1;
}
OK when i compile i got this errors:

C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(508 -- 509) : error 017: undefined symbol "pname"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(508 -- 509) : error 001: expected token: ")", but found ";"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : error 017: undefined symbol "string"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : error 017: undefined symbol "string"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : error 029: invalid expression, assumed zero
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : fatal error 107: too many error messages on one line

Maybe I've to put a else if (..idk what here )

But there is not only this i guess ok thanks really hope it will be resolved !
Reply
#2

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
      
        
        if(killerid != INVALID_PLAYER_ID)
        {
        new pname[30];
        new string[95];
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You were killed by %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
        SetPlayerScore(playerid,(GetPlayerScore(playerid))-1);
        GivePlayerMoney(playerid, -500);
        SendClientMessage(playerid,COLOR_RED,"You lost 500$");
        SendClientMessage(playerid,COLOR_RED,"You lost 1pt score");
        }
        else 
        { //You had a ( instead of a {
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You killed %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(killerid, playerid, reason);
        SetPlayerScore(killerid,(GetPlayerScore(killerid))+1);
        GivePlayerMoney(killerid, 1000);
        SendClientMessage(killerid,COLOR_GREEN,"You earned 1000$");
        SendClientMessage(killerid,COLOR_GREEN,"You won 1pt score");
        }
        return 1;
}
Reply
#3

Ohhh what a idiot error thanks

but still that errors:

C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(509) : error 017: undefined symbol "pname"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : error 017: undefined symbol "string"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : error 017: undefined symbol "string"
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : error 029: invalid expression, assumed zero
C:\Documents and Settings\xxxxx\Desktop\0.3b server\gamemodes\cvsm2.pwn(510) : fatal error 107: too many error messages on one line

EDIT: I'm not sure the distance will work
Reply
#4

You define them only IF killerid is not equal to INVALID_PLAYER_ID. I recommend defining the variables before the statements, but you can also define inside both (aka, add the same lines after "else {").
Reply
#5

I made that to test because I did in only "If" but
first: the distance doesn''t work then i got bugs when people kill each other there is the name alone then the name the [icon of weapon] and the player dead
some kills doesn t appear like helikill or kill by explosion
so i made like this to test .
Reply
#6

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
     
        new pname[MAX_PLAYER_NAME];
        new string[95];
        if(killerid != INVALID_PLAYER_ID) // weird shiiiittttt Should be if(killerid == INVALID_PLAYER_ID
        {
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You were killed by %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
        SetPlayerScore(playerid,(GetPlayerScore(playerid))-1);
        GivePlayerMoney(playerid, -500);
        SendClientMessage(playerid,COLOR_RED,"You lost 500$");
        SendClientMessage(playerid,COLOR_RED,"You lost 1pt score");
        }
        else
        { //You had a ( instead of a {
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You killed %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(killerid, playerid, reason);
        SetPlayerScore(killerid,(GetPlayerScore(killerid))+1);
        GivePlayerMoney(killerid, 1000);
        SendClientMessage(killerid,COLOR_GREEN,"You earned 1000$");
        SendClientMessage(killerid,COLOR_GREEN,"You won 1pt score");
        }
        return 1;
}
Should work..
Reply
#7

Really thank you.

I got no errors.
But now I'll test but I'm not sure that the distance will work.

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{


        if(killerid != INVALID_PLAYER_ID)
        {
        new pname[MAX_PLAYER_NAME];
        new string[95];
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You were killed by %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
        SetPlayerScore(playerid,(GetPlayerScore(playerid))-1);
        GivePlayerMoney(playerid, -500);
        SendClientMessage(playerid,COLOR_RED,"You lost 500$");
        SendClientMessage(playerid,COLOR_RED,"You lost 1pt score");
       
        }
        else
        {
        new pname[MAX_PLAYER_NAME];
        new string[95];
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You killed %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(killerid, playerid, reason);
        SetPlayerScore(killerid,(GetPlayerScore(killerid))+1);
        GivePlayerMoney(killerid, 1000);
        SendClientMessage(killerid,COLOR_GREEN,"You earned 1000$");
        SendClientMessage(killerid,COLOR_GREEN,"You won 1pt score");
       
        }
        return 1;
}
Maybe I've to put that too for the distance work?

new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
Reply
#8

Glad u got it working this far

To make the distance work you need to change if(killerid != INVALID_PLAYER_ID) to if(killerid == INVALID_PLAYER_ID)

And you need a other player to kill You.
Reply
#9

lol yes sure for the player xD

else if(killerid != playerid)

else is now else if no errors so i test
because i want to know the distance for the killed player and for the player who kills

i tested something if i fall down or i do /kill nothing appear in the right of screen (where we see kills)

EDIT: WTF when someone got killed by helikill or by explosion nothing appear

When someone got killed it shows him like if he was the killer but the weapon with he got killed appear like if he killed with and there is no killer who appear

+ we see the message with distance(work now with that: if(killerid != INVALID_PLAYER_ID) like before) when we got killed but not when we kill :S totally bugged the kill thing on the right of screen
Reply
#10

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
     
        new pname[MAX_PLAYER_NAME];
        new string[95];
        if(killerid != INVALID_PLAYER_ID) //
        {
        GetPlayerName(killerid,pname,30);
        format(string, sizeof(string),"* You were killed by %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
        SendClientMessage(playerid,COLOR_LIGHTGREEN, string);
format(string, sizeof(string),"* You killed %s(%d): Distance: %2.f | Weapon: %s",pname,killerid,GetDistanceBetweenPlayers(playerid,killerid),aWeaponNames[reason]);
SendClientMessage(killerid,COLOR_LIGHTGREEN, string);
        SendDeathMessage(killerid, playerid, reason);
        SetPlayerScore(playerid,(GetPlayerScore(playerid))-1);
        GivePlayerMoney(playerid, -500);
SetPlayerScore(killerid,(GetPlayerScore(killerid))+1);
        GivePlayerMoney(killerid, 1000);
        SendClientMessage(killerid,COLOR_GREEN,"You earned 1000$");
        SendClientMessage(killerid,COLOR_GREEN,"You won 1pt score");
        SendClientMessage(playerid,COLOR_RED,"You lost 500$");
        SendClientMessage(playerid,COLOR_RED,"You lost 1pt score");
        }
        else
        { //You had a ( instead of a {
        SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
        }
        return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)