Bug with OnPlayerTakeDamage
#1

Hi, as I said in another recent thread of mine, I'm a novice at scripting.
The thing is that I'm trying to make a script by which Rustlers can kill players with just one single shot, like this:

[ame]http://www.youtube.com/watch?v=_MMi6ka2bNs[/ame]

However, I don't want it to affect everyone, but instead only pilots to kill each other. So I have a global boolean array that determines that a player is a pilot when he is in a plane or helicopter, and is not when he is killed by another player. I haven't pasted here the part of the script that sets that boolean as true or false, I don't think you will need it, so I'm just pasting the array declaration and the OnPlayerTakeDamage part:

pawn Код:
new bool:pilot[500];

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if( (GetPlayerVehicleID(issuerid) == 476) && (pilot[playerid] == true) )
    {
        new Float:health, Float:armour;
        GetPlayerHealth(playerid, health);
        GetPlayerArmour(playerid, armour);
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth( playerid, (health + armour - 100) );
        // This all means that if you are a pilot and you get hit by another
        //  player flying a Rustler, you will be greatly damaged: if you have
        //  no armour you will die instantly, and if you do have armour you will
        //  have it removed, and your health may be reduced depending on your
        //  previous armour value.
    }
    return 1;
}
But it doesn't work, and pilots keep taking normal damage from Rustlers, so what's the problem with this? Could it be that I'm declaring the armour and health variables as floats?
Reply
#2

GetVehicleID gets the ID in order from the script. So you would use GetVehicleModel instead.
Also, your bool. You are never setting it to true if a player enters a vehicle so it will never work.
Read the comments! I hope I helped.
pawn Код:
new bool:pilot[MAX_PLAYERS]; // How a bool is setup, automatically false.
public OnPlayerEnterVehicle(playerid,vehicleid,ispassenger)
{
    if(ispassenger == 0) // If they are not a passenger.
    {
        if(GetVehicleModel(playerid) == 476) // If they enter a Rustler
        {
            pilot[playerid] = true; // Then they are a pilot
            return 1;
        }
    }
    return 1;
}
public OnPlayerExitVehicle(playerid,vehicleid)
{
    // If they exit any vehicle
    pilot[playerid] = false; // Then they are no longer a pilot
    return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    // You added a lot of uneccesary paranthesis here. I fixed it.
    if(GetPlayerVehicleModel(issuerid) == 476 && pilot[playerid] == true) // If they are in a Rustler
    {
        // Floats for health and armour are not needed since you are just killing the player.
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, 0);
    }
    return 1;
}
Reply
#3

Thank you very much. I'm gonna try what you told me and I hope it will work.

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Also, your bool. You are never setting it to true if a player enters a vehicle so it will never work.
Actually I do have a piece of script that sets the boolean as true, in fact I have put it in OnPlayerUpdate instead of in OnPlayerEnterVehicle, so if I use an admin command to put a player in a plane, his boolean will be set as true in that case too. It's just that I didn't paste that part of my script here because I didn't think it would be necessary.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)