SA-MP Forums Archive
Bite system - 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: Bite system (/showthread.php?tid=337408)



Bite system - [D]ry[D]esert - 26.04.2012

Hi Every one i tried to make bite system no error but script i mean Bite System does't work
Check
Код:
#define KEY_AIM (128)
then
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	new Float:health;
 	if(newkeys & KEY_AIM)
    {
        if(gTeam[playerid] == TEAM_ZOMBIES)
        {
            new victimid = GetClosestPlayer(playerid);
            GetPlayerHealth(victimid, health);
            if(gTeam[victimid] == TEAM_HUMANS)
            {
                if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
                {
	    			SetPlayerHealth(victimid, health - 6.0);
    				GameTextForPlayer(victimid, "~p~Biten", 1000, 3);
    				PlayerPlaySound(playerid, 1136, 0, 0, 0);
       				PlayerPlaySound(victimid, 1136, 0, 0, 0);
                }
            }
        }
    }
	return 1;
}



Re: Bite system - Ballu Miaa - 26.04.2012

One if statement was mismatched. newkeys == KEY_AIM should be there. Use the code below.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float:health;
    if(newkeys == KEY_AIM) // This was the error here.
       {
        if(gTeam[playerid] == TEAM_ZOMBIES)
        {
            new victimid = GetClosestPlayer(playerid);
            GetPlayerHealth(victimid, health);
            if(gTeam[victimid] == TEAM_HUMANS)
            {
                if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
                {
                    SetPlayerHealth(victimid, health - 6.0);
                    GameTextForPlayer(victimid, "~p~Biten", 1000, 3);
                    PlayerPlaySound(playerid, 1136, 0, 0, 0);
                    PlayerPlaySound(victimid, 1136, 0, 0, 0);
                }
            }
        }
    }
    return 1;
}



Re: Bite system - [D]ry[D]esert - 26.04.2012

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
One if statement was mismatched. newkeys == KEY_AIM should be there. Use the code below.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float:health;
    if(newkeys == KEY_AIM) // This was the error here.
       {
        if(gTeam[playerid] == TEAM_ZOMBIES)
        {
            new victimid = GetClosestPlayer(playerid);
            GetPlayerHealth(victimid, health);
            if(gTeam[victimid] == TEAM_HUMANS)
            {
                if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
                {
                    SetPlayerHealth(victimid, health - 6.0);
                    GameTextForPlayer(victimid, "~p~Biten", 1000, 3);
                    PlayerPlaySound(playerid, 1136, 0, 0, 0);
                    PlayerPlaySound(victimid, 1136, 0, 0, 0);
                }
            }
        }
    }
    return 1;
}
Does't work :\


Re: Bite system - Ballu Miaa - 26.04.2012

Quote:
Originally Posted by [D]ry[D]esert
Посмотреть сообщение
Does't work :\
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float:health;
    if(newkeys == KEY_AIM) // This was the error here.
       {
        if(gTeam[playerid] == TEAM_ZOMBIES)
        {
            new victimid = GetClosestPlayer(playerid);
            GetPlayerHealth(victimid, health);
            if(gTeam[victimid] == TEAM_HUMANS)
            {
                if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
                {
                    SetPlayerHealth(victimid, health - 6.0);
                    GameTextForPlayer(victimid, "~p~Biten", 1000, 3);
                    PlayerPlaySound(playerid, 1136, 0, 0, 0);
                    PlayerPlaySound(victimid, 1136, 0, 0, 0);
                }
            }
        }
    }
    return 1;
}



Re: Bite system - SuperViper - 26.04.2012

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
One if statement was mismatched. newkeys == KEY_AIM should be there. Use the code below.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float:health;
    if(newkeys == KEY_AIM) // This was the error here.
       {
        if(gTeam[playerid] == TEAM_ZOMBIES)
        {
            new victimid = GetClosestPlayer(playerid);
            GetPlayerHealth(victimid, health);
            if(gTeam[victimid] == TEAM_HUMANS)
            {
                if(GetDistanceBetweenPlayers(playerid,victimid) < 2)
                {
                    SetPlayerHealth(victimid, health - 6.0);
                    GameTextForPlayer(victimid, "~p~Biten", 1000, 3);
                    PlayerPlaySound(playerid, 1136, 0, 0, 0);
                    PlayerPlaySound(victimid, 1136, 0, 0, 0);
                }
            }
        }
    }
    return 1;
}
Wrong. Newkeys contains every key that's being pressed by the player. == will work if the only key that is being pressed by the player is that key, but & will work if the key is even one of the keys the player is pressing.

As for the poster, you could try using GetPlayerTargetPlayer which was added in 0.3d instead of GetClosestPlayer and try increasing the distance required between the players to about 3.


Re: Bite system - Ballu Miaa - 26.04.2012

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Wrong. Newkeys contains every key that's being pressed by the player. == will work if the only key that is being pressed by the player is that key, but & will work if the key is even one of the keys the player is pressing.

As for the poster, you could try using GetPlayerTargetPlayer which was added in 0.3d instead of GetClosestPlayer and try increasing the distance required between the players to about 3.
Allright. Thanks for the knowledge. I will keep that in mind. Can you give us the right and correct code for this?

Will help me to learn the usage of OnPlayerKeyStateChange. (3 Rep points added to SuperViper)


Re: Bite system - Rudy_ - 26.04.2012

what? newkeys is affected on everyone Keyboard button? i have "JUMP_KEY" and it"The script/code" only works with jump key..


Re: Bite system - Vince - 26.04.2012

Multiple keys pressed at the same time will still be saved in that single variable. Hence, pressing sprint and jump simultaneously will produce a different value than pressing either sprint or jump.


Re: Bite system - Rudy_ - 26.04.2012

So pressing Sprint and jump both at once won't work? it does for me...


Re: Bite system - Ballu Miaa - 27.04.2012

So someone can please fix the code above? Even i want to know what will be the correct code lol.