SA-MP Forums Archive
Detecting Fighting - 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: Detecting Fighting (/showthread.php?tid=325177)



Detecting Fighting - FreshRio - 12.03.2012

Hi,

Can anyone help me out with this small script?

Basically what It does Is If a player has been fighting in the last 20 seconds, they can't use any teleport commands.
I am using zcmd.


Thanks


Re: Detecting Fighting - Infamous - 12.03.2012

Assign a variable to your commands as default of 0 and under OnPlayerGiveDamage activate the variable once they have caused damage to a player.

If variables arn't your thing you could do the same with SetPlayerWantedLevel.


Re: Detecting Fighting - FreshRio - 13.03.2012

I understand the variable part but do you mind giving me an example of what I should include under OnPlayerGiveDamage?

And, would I need to set it to 0 under every command? Or can I just add it under OnPlayerCommandPerformed


Cheers


Re: Detecting Fighting - KingHual - 13.03.2012

Do you mean "fighting" like with fists or with every weapon?


Re: Detecting Fighting - ReneG - 13.03.2012

Here is a quick tutorial.


pawn Код:
new bool:IsFighting[MAX_PLAYERS] = false; // Sets a bool for each player and sets it to false automatically.

public OnPlayerGiveDamage(playerid,damageid,Float:amount,weaponid)
{
    if(playerid != INVALID_PLAYER_ID || damageid != INVALID_PLAYER_ID) // If both the players are online then
    {
        IsFighting[playerid] = true; // It sets their is fighting bool to true.
        // Now since they are fighting we are gonna need a cool down timer sow that they can use TP commands again.
        SetTimer("CanTeleport",30000,false); // Sets a timer of 30 seconds.
        return 1;
    }
    return 1;
}
forward CanTeleport(playerid);
public CanTeleport(playerid) // When that 30 seconds is up..
{
    IsFighting[playerid] = false; // Then make it so they can telelport again.
    return 1;
}

// Now let's make a command.

CMD:teleport(playerid,params[])
{
    if(IsFighting[playerid] == true) // If the player has fought within the last 30 seconds.
    {
        SendClientMessage(playerid,-1,"You are currently fighting an enemy and cannot teleport!");
        return 1;
    }
    else // If they are NOT fighting then it teleports them
    {
        SetPlayerPos(playerid,x,y,z); // You put your coordinates here
        SendClientMessage(playerid,-1,"You have teleported.");
        return 1;
    }
    return 1;
}
I hope you understood! Goodluck!


Re: Detecting Fighting - FreshRio - 13.03.2012

Thanks so much, although I believe you had made a small mistake,
damageid should be damagedid


And also, I get this warning message saying warning 225: unreachable code at the end of the Teleport Command on the line of return 1;


Re: Detecting Fighting - KingHual - 13.03.2012

Quote:
Originally Posted by FreshRio
Посмотреть сообщение
Thanks so much, although I believe you had made a small mistake,
damageid should be damagedid


And also, I get this warning message saying warning 225: unreachable code at the end of the Teleport Command on the line of return 1;
Remove the "return 1;" lines at the if statements, leave only the one at the last line, before the } bracket.


Re: Detecting Fighting - MP2 - 13.03.2012

I would personally use gettime() instead of a timer.


Re: Detecting Fighting - FreshRio - 13.03.2012

Quote:
Originally Posted by king_hual
Посмотреть сообщение
Remove the "return 1;" lines at the if statements, leave only the one at the last line, before the } bracket.

Yeah I just realised.

and It kind of fails with the timer part.


Re: Detecting Fighting - MP2 - 13.03.2012

Use gettime. No timer needed.

pawn Код:
new pDamage[MAX_PLAYERS];

// when a player DOES damage
pDamage[playerid] = gettime();

// to check if they did damage in the last 30 second
if((gettime()-pDamage[playerid]) < 30)
Not tested and written on iPhone so..