SA-MP Forums Archive
OnPlayerWeaponShot - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerWeaponShot (/showthread.php?tid=540408)



OnPlayerWeaponShot - Rudy_ - 04.10.2014

Hey everyone.
I need a bit of help, Here i'm detecting if team_hunter shoots team_prop's (Object) which is Prop[i]. But in-game if hunter shoots the object it dosen't kills prop :/ I have no idea what's wrong

pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    foreach(new ii: Player)
    if(GetPlayerTeam(ii) == team_hunter)
    {
        if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
        {
            foreach(new i:Player)
            {
                if(GetPlayerTeam(ii) != team_prop) continue;
                if(hitid == Prop[i])
                {
                    SetPlayerHealth(i, 0);
                    SendClientMessage(i, -1, "Test");
                    break;
                }
            }
        }
    }
    return 1;
}

I've also tried this.


pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    switch (hittype)
    {
        case BULLET_HIT_TYPE_PLAYER_OBJECT:
        {
            foreach(new i:Player)
            foreach(new ii: Player)
            {
                if(GetPlayerTeam(i) == team_hunter) continue;
                if(GetPlayerTeam(ii) == team_prop) continue;
                if(hitid == Prop[ii])
                {
                    SetPlayerHealth(ii, 0);
                    SendClientMessage(ii, -1, "You have been killed");
                    break;
                }
            }
        }
    }
    return 1;
}



Re: OnPlayerWeaponShot - Stinged - 04.10.2014

Try this.
(Also, are you sure Prop[playerid] is an object id?)

pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(GetPlayerTeam(playerid) == team_hunter) // No need for a loop, as playerid is in OnPlayerWeaponShot
    {
        if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
        {
            foreach(new i : Player)
            {
                if(hitid == Prop[i]) // Are you sure Prop[MAX_PLAYERS] (Prop[i]) is assigned to an object?
                {
                    SetPlayerHealth(i, 0);
                    SendClientMessage(i, -1, "Test");
                    break;
                }
            }
        }
    }
    return 1;
}



Re: OnPlayerWeaponShot - ranme15 - 04.10.2014

BULLET_HIT_TYPE_PLAYER_OBJECT -> BULLET_HIT_TYPE_OBJECT


Re: OnPlayerWeaponShot - Rudy_ - 04.10.2014

Yes, Prop[i] is attached to the player.
Under onplayerdeath i've added
pawn Код:
DestroyObject(Prop[i]);
it destroys the attached object

Plus: The script above didn't worked.. :/

Edit:
Quote:
Originally Posted by ranme15
Посмотреть сообщение
BULLET_HIT_TYPE_PLAYER_OBJECT -> BULLET_HIT_TYPE_OBJECT
It's a player object


Re: OnPlayerWeaponShot - Eth - 04.10.2014

try this
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    foreach(new ii: Player)
    if(GetPlayerTeam(ii) == team_hunter)
    {
        if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
        {
            foreach(new i:Player)
            {
                if(GetPlayerTeam(ii) != team_prop) continue;
                if(hitid == Prop[i])
                {
                     for(new i2=0; i<MAX_PLAYER_ATTACHED_OBJECTS; i2++)
                    {
                    if(IsPlayerAttachedObjectSlotUsed(playerid, i2)) RemovePlayerAttachedObject(playerid, i2);
                    }
                    SetPlayerHealth(i, 0);
                    SendClientMessage(i, -1, "Test");
                    break;
                }
            }
        }
    }
    return 1;
}
you have to un attach the object b4 destroying it


Re: OnPlayerWeaponShot - IceCube! - 04.10.2014

Rudy_

Remember you are duplicating the object to allow it to be seen outside of the players normal VW? If your still using the method we discussed. This would mean however that you would need to detect damage to a duplicated object (normal object) on the enemies screen.


Re: OnPlayerWeaponShot - Rudy_ - 04.10.2014

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
Rudy_

Remember you are duplicating the object to allow it to be seen outside of the players normal VW? If your still using the method we discussed. This would mean however that you would need to detect damage to a duplicated object (normal object) on the enemies screen.
Right, But atm i haven't added the duplicate, it's visible for everyone atm (for testing), so it should have worked :/

I tried this but didn't worked

pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(GetPlayerTeam(playerid) == team_hunter) // No need for a loop, as playerid is in OnPlayerWeaponShot
    {
        if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
        {
            foreach(new i : Player)
            {
                if(hitid == Prop[i]) // Are you sure Prop[MAX_PLAYERS] (Prop[i]) is assigned to an object?
                {
                    for(new i2=0; i<MAX_PLAYER_ATTACHED_OBJECTS; i2++)
                    {
                        DestroyObject(Prop[i2]);
                        SetPlayerHealth(i, 0);
                        SendClientMessage(i, -1, "Test");
                        break;
                    }
                }
            }
        }
    }
    return 1;
}



Re: OnPlayerWeaponShot - IceCube! - 04.10.2014

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Try this.
(Also, are you sure Prop[playerid] is an object id?)

pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(GetPlayerTeam(playerid) == team_hunter) // No need for a loop, as playerid is in OnPlayerWeaponShot
    {
        if(hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
        {
            foreach(new i : Player)
            {
                if(hitid == Prop[i]) // Are you sure Prop[MAX_PLAYERS] (Prop[i]) is assigned to an object?
                {
                    SetPlayerHealth(i, 0);
                    SendClientMessage(i, -1, "Test");
                    break;
                }
            }
        }
    }
    return 1;
}
How didn't stinged code work? As it should kill the player as needed, but not destroy the object which is the only fault?

Does "Test" appear, or?

Stinged's code is also more efficent, have you tried debugging Stinged's code or even yours?


Re: OnPlayerWeaponShot - Eth - 04.10.2014

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
How didn't stinged code work? As it should kill the player as needed, but not destroy the object which is the only fault?

Does "Test" appear, or?

Stinged's code is also more efficent, have you tried debugging Stinged's code or even yours?
^
this
also the question is, did he attach the object or not?


Re: OnPlayerWeaponShot - Rudy_ - 05.10.2014

Quote:
Originally Posted by IceCube!
Посмотреть сообщение
How didn't stinged code work? As it should kill the player as needed, but not destroy the object which is the only fault?

Does "Test" appear, or?

Stinged's code is also more efficent, have you tried debugging Stinged's code or even yours?
No, it didn't appear the msg.. and didn't killed the player i shot with attached object.

Quote:
Originally Posted by Eth
Посмотреть сообщение
^
this
also the question is, did he attach the object or not?
Yes it was attached.