SA-MP Forums Archive
What's wrong in this? - 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: What's wrong in this? (/showthread.php?tid=639634)



What's wrong in this? - ProBro - 20.08.2017

I'm trying to make a Taser.
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
 if(gPlayerClass[playerid] == Policeman)
	 {
	    if(issuerid != INVALID_PLAYER_ID && weaponid == 23)
	    {
	         ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
	    }
	 }
    return 1;
}
It's not working.


Re: What's wrong in this? - TheCman - 20.08.2017

You likely want to check the gPlayerClass of the issuer, not the target. That also implies you want to move the INVALID_PLAYER_ID check in that condition too.


Re: What's wrong in this? - ProBro - 20.08.2017

Quote:
Originally Posted by TheCman
Посмотреть сообщение
You likely want to check the gPlayerClass of the issuer, not the target. That also implies you want to move the INVALID_PLAYER_ID check in that condition too.
Okay, I didn't understand (lol)


Re: What's wrong in this? - TheCman - 20.08.2017

Err...
PHP код:
public OnPlayerTakeDamage(playeridissueridFloatamountweaponidbodypart)
{
    if(
        
issuerid != INVALID_PLAYER_ID &&
        
gPlayerClass[issuerid] == Policeman &&
        
weaponid == 23
    
)
        
ApplyAnimation(playerid"CRACK""crckdeth2"4.010000);

    return 
1;

Something like that.


Re: What's wrong in this? - ProBro - 21.08.2017

bumping this thread to draw attention\n
Not working


Re: What's wrong in this? - Ebisu - 21.08.2017

First check if you have any other scripts loaded that are using "OnPlayerTakeDamage" function, Only use it in one script
2nd, sometimes the animation dosen't work correctly so try this.
PHP код:
public OnPlayerTakeDamage(playeridissueridFloatamountweaponidbodypart)
{
        if(
gPlayerClass[killerid] == Policeman)
        {
        if(
issuerid != INVALID_PLAYER_ID && weaponid == 23)
        {
                 
ClearAnimations(playerid);
                 
ApplyAnimation(playerid"CRACK""crckdeth2"4.010000);
                 
ApplyAnimation(playerid"CRACK""crckdeth2"4.010000);
                 
ApplyAnimation(playerid"CRACK""crckdeth2"4.010000);
        }
        }
        return 
1;




Re: What's wrong in this? - Kane - 21.08.2017

I recommend using OnPlayerWeaponShot for what you're doing.

https://sampwiki.blast.hk/wiki/OnPlayerWeaponShot

Код:
Return Values:
      0 - Prevent the bullet from causing damage.
Is something you should also do for tasers.

An example:

PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    if(
hittype == BULLET_HIT_TYPE_PLAYER)
   {
         if(
gPlayerClass[playerid] == Policeman && weaponid == 23)
         {
            
ApplyAnimation(hitid"CRACK""crckdeth2"4.010000);
            
//Just to ensure it works, we'll send a message to the playerid:
           
SendClientMessage(playerid, -1"You hit someone with your taser.");
           return 
0// player wont take damage.
         
}
    }
    return 
1;

I also recommend making a variable for tasers when the player uses the /taser command OR however it's issued.

I don't know if it's possible in your script for that class player to just be wielding an ordinary Silenced Pistol but it's a suggestion.