Killable Cows - Problem #2
#5

Hello! I was playing around with your script last night for a while, but ended up going to bed before giving you a reply, sorry! :S

Anyway, I found that the major problem causing the hits to not be registered is to do with your static definition of the "Distance" parameter during your use of the GetPosFromView here on line 74:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_FIRE && GetPlayerWeapon(playerid) != 0 && IsPlayerSpawned[playerid] == true)
    {
        new Float:X,
            Float:Y,
            Float:Z;
        GetPosFromView(playerid,80.0,X,Y,Z); // <---- THIS IS THE LINE I AM TALKING ABOUT
        for(new id = 0; id < MAX_COWS; id++)
        {
            if(ObjectToPoint(playerid,4.0,CowInfo[id][iObjectID],X,Y,Z) != 0)
            {
                if(CowInfo[id][IsDead] == 0)
                {
                    KillCow(id);
                }
            }
        }
    }
    return 0;
}
As far as I can tell, that value of 80.0 comes from nowhere. This means that detecting a hit on a cow is possible, but you would have to be exactly 80 meters away from the cow.
What you need to instead do is find the distance between the player and a cow, and then find the coordinates that the player is looking at for that particular distance, and then repeat for each cow (assuming that cows are going to be at different distances from the player).

The second issue is not as great, but it a delicate one! It refers to the "Distance" parameter, this time in your usage of the ObjectToPoint function here:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_FIRE && GetPlayerWeapon(playerid) != 0 && IsPlayerSpawned[playerid] == true)
    {
        new Float:X,
            Float:Y,
            Float:Z;
        GetPosFromView(playerid,80.0,X,Y,Z);
        for(new id = 0; id < MAX_COWS; id++)
        {
            if(ObjectToPoint(playerid,4.0,CowInfo[id][iObjectID],X,Y,Z) != 0) // <---- THIS IS THE LINE I AM TALKING ABOUT NOW
            {
                if(CowInfo[id][IsDead] == 0)
                {
                    KillCow(id);
                }
            }
        }
    }
    return 0;
}
The value of 4.0 is basically saying "the object you are checking has the size 4x4x4, so check anywhere inside a 4x4x4 box". Through trial and error, I attempted to work out the closest cubic dimensions of the cow object and came up with the value 2.6.

That's about the point I got up to! The script was working in a rough manner, the cows were dying when I pointed in their general direction at least! I came to the conclusion that the ObjectToPoint function itself is the next thing to look at; just a bit of fine tuning I think! Possibly to allow for objects that are not cubic (ie cows!).

One other thing I noticed through putting SendClientMessage debug messages throughout the OnPlayerKeyStateChange callback, is that a player can spam-click the fire button to hit cows instead of only being able to hit them when a bullet is actually shot. Also, holding down shoot to fire will only do one check to see if cows are hit, even if the weapon is firing multiple shots. These aren't major issues right now, but something to bear in mind for when you have hit detection perfect

Anyway, here is the code that I was left with after I had finished: http://pastebin.com/VmMDCVdX
I've just gone through it and tried to comment the changes I made and why I made them. I hope that it will help you further develop it!
Reply


Messages In This Thread
Killable Cows - Problem #2 - by Shadow_Gengar - 16.12.2010, 20:16
Re: Killable Cows - Problem #2 - by Benjo - 16.12.2010, 21:28
AW: Killable Cows - Problem #2 - by Shadow_Gengar - 17.12.2010, 12:13
AW: Killable Cows - Problem #2 - by Shadow_Gengar - 17.12.2010, 13:16
Re: Killable Cows - Problem #2 - by Benjo - 17.12.2010, 21:03

Forum Jump:


Users browsing this thread: 2 Guest(s)