Tazer by a weapon?
#1

Hey,

is it possible to make a tazer command be used by a weapon instead of a command?

Well, I know its possible but how can it be done?

Thanks
Reply
#2

pawn Код:
public OnPlayerKeyStateChange(playerid, oldkeys, newkeys)
{
    if((newkeys & KEY_FIRE) && GetPlayerWeapon == some weapon id)
    {
        //tazer cmd
    }
}
Reply
#3

Thanks!
Reply
#4

Error:
Код:
G:\Fusion RP Temp\gamemodes\v0.2.pwn(18968) : error 076: syntax error in the expression, or invalid function call
Line:
pawn Код:
if ((newkeys & KEY_FIRE) && GetPlayerWeapon == 24)
Reply
#5

GetPlayerWeapon(playerid)
Reply
#6

Yep stupid me, fixed it

Testing now.
Reply
#7

Ok, I've copied my tazer command but now I can taze across the map.

Is their away to change this
pawn Код:
new suspect = GetClosestPlayer(playerid);
to the person who has been shot, not the nearest?

Thanks again.

This is my code:

Код:
	if(newkeys & KEY_FIRE)
	{
	  if(GetPlayerWeapon(playerid == 23))
		{
		  new string[128];
		  new suspect = GetClosestPlayer(playerid);
			format(string, sizeof(string), "Tazed by %s for 60 seconds.", GetPlayerNameEx(playerid));
			SendClientMessage(suspect, COLOR_RED, string);
			format(string, sizeof(string), "You tazed %s 60 seconds.", GetPlayerNameEx(suspect));
			SendClientMessage(playerid, COLOR_WHITE, string);
			TogglePlayerControllable(suspect, 0);
			PlayerTazed[suspect] = 1;
			SetTimerEx("UntazePlayer", 60000, false, "i", suspect);
			PlayerPlayerActionMessage(playerid,suspect,15.0,"has just tazed");
		}
		return 1;
	}
	return 1;
I can get any weapon out and taze as well as anywhere across the map.
Reply
#8

This would be kinda hard to realize because of the desync, but it looks something like this

pawn Код:
new
    Float:health[MAX_PLAYERS],
    shot[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    GetPlayerHealth(playerid, health[playerid]);
    return 1;
}
public OnPlayerUpdate(playerid)
{
    new
        Float:temp;
    GetPlayerHealth(playerid, temp);
    if(health[playerid] > temp)
    {
        OnPlayerLooseHealth(playerid, temp, health[playerid]);
        GetPlayerHealth(playerid, health[playerid]);
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, oldkeys, newkeys)
{
    if((newkeys & KEY_FIRE) && GetPlayerWeapon(playerid) == some weapon id)
    {
        shot[playerid] = 1;
        SetTimerEx("ResetShot", 1500, 0, "d", playerid);
        return 1;
    }
}

OnPlayerLooseHealth(playerid, oldhealth, newhealth)
{
    for(new id = 0; id < MAX_PLAYERS; id++)
    {
        if(shot[id] == 1)
        {
            new
                Float:angle;
            GetPlayerFacingAngle(id, angle);
            if(IsPlayerFacingPlayer(id, playerid, 5.0))
            {
                //taze 'playerid'
                return 1;
            }
        }
    }
    return 1;
}

forward ResetShot(playerid);
public ResetShot(playerid)
{
    shot[playerid] = 0;
}
You can get IsPlayerFacingPlayer here
http://forum.sa-mp.com/index.php?topic=130630.0
Reply
#9

Ok thanks,

For this part
pawn Код:
OnPlayerLooseHealth(playerid, oldhealth, newhealth)
{
for(new id = 0; id < MAX_PLAYERS; id++)
{
if(shot[id] == 1)
{
new
Float:angle;
GetPlayerFacingAngle(id, angle);
if(IsPlayerFacingPlayer(id, playerid, 5.0))
{
//taze 'playerid'
return 1;
}
}
}
return 1;
}
Do I add my taze code from above?
Reply
#10

If shot a player with the tazer, using debug code under and where
pawn Код:
//taze 'playerid'
is, I've added debug tags,

These haven't shown up for me or the player being shot.
pawn Код:
forward OnPlayerLooseHealth(playerid, oldhealth, newhealth);
public OnPlayerLooseHealth(playerid, oldhealth, newhealth)
{
    for(new id = 0; id < MAX_PLAYERS; id++)
    {
        if(shot[id] == 1)
        {
            new
            Float:angle;
            GetPlayerFacingAngle(id, angle);
            if(IsPlayerFacingPlayer(id, playerid, 5.0))
            {
                SendClientMessage(playerid, COLOR_WHITE, "[DEBUG] You shall be tazed");
                SendClientMessage(id, COLOR_YELLOW, "[DEBUG] You shall be tazed");
                return 1;
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)