Detecting Fighting
#1

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
Reply
#2

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.
Reply
#3

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
Reply
#4

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

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!
Reply
#6

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;
Reply
#7

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.
Reply
#8

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

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.
Reply
#10

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..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)