PDA

View Full Version : taze command?


yvoms
11/10/2016, 11:42 PM
Does this seem correct or should i alter it?
I just want 50% chance to succesfully taze a player, maybe 60 percent, however i have no clue on how to accomplish that.


CMD:taze(playerid, params[])
{
new targetid;
if(sscanf(params,"u",targetid)) return SendClientMessage(playerid,-1,"{ff227a}[Syntax]:{ffffff} /taze [ID | Name]");
if(gTeam[playerid] != TEAM_COP | TEAM_FBI | TEAM_CIA | TEAM_ARMY) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff}This command is restricted to the LEO classes.");
new time = tickcount() - 60000;
if(time < TimerInfo[playerid][CMD_TAZE]) return SendClientMessage(playerid, -1, "{ff0000}[Error]: {ffffff}Please wait before using this command again.");
TimerInfo[playerid][CMD_TAZE] = tickcount();
if(targetid == playerid) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff} You can not taze yourself.");
if(GetPlayerWantedLevel(targetid) < 4) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff} This player's wanted level is to low to be tazed.");
if(GetDistanceBetweenPlayers(playerid, targetid) <= 5) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff} This player is not close enough to be tazed.");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[Error]:{ffffff} This Player is not connected.");
if(GetDistanceBetweenPlayers(playerid, targetid) <= 6)
{
if(TimerInfo[playerid][CMD_TAZE] == 0)
{
new Tazert = random(2);
if(Tazert == 1)
{
TogglePlayerControllable(targetid, 0);
stunned[targetid] = 1;
SetTimerEx("stuntimer", STUNNED_TIME*1000, 0, "i", targetid);
}
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "You failed to taze the dude");
}
}
return 1;
}

forward stuntimer(targetid);
public stuntimer(targetid)
{
stunned[targetid] = 0;
TogglePlayerControllable(targetid, 1);
SendClientMessage(targetid, COLOR_WHITE, "You have recovered from the tazer-shock");
}

Just wish to know if this is the correct way to use a taze command, with a random chance on succes.

Eoussama
12/10/2016, 12:05 AM
It would have been cooler if it was based on a gun shoot instead of a command,
so you would shoot someone with a specific gun (silenced pistol seems perfect), and then he would be tazed)

azzerking
12/10/2016, 12:51 AM
Quick Question

Why are you calling if(GetDistanceBetweenPlayers(playerid, targetid) <= 5) twice within the same function? that's an un-needed call.

Possible Solution

Use random and set it to 9 ( 0 - 9 ), then use a switch statement and for cases 0 .. 6 make it taze the player and thats really it.


new Tazert = random( 9 );

switch( Tazert )
{
case 0 .. 6:
{
TogglePlayerControllable( targetid, 0 );
stunned[ targetid ] = 1;
SetTimerEx( "stuntimer", STUNNED_TIME * 1000, 0, "i", targetid );
}

default:
{
SendClientMessage( playerid, COLOR_WHITE, "You failed to taze the dude" );
}
}


Hopefully, this is enough for you to understand the process.

HeLiOn_PrImE
12/10/2016, 12:57 AM
You can make the character perform that shaking animation that a corpse performs when you shoot it.
Also, as said below, why make this a command?
Link this to the 9mm pistol, fix the damage, and you got yourself a normal tazer.

If you still want to use the pistol, make the user type in a command every time he wants to taze someone.
He types the command and for the next shot, the pistol acts as a tazer.

yvoms
12/10/2016, 12:33 PM
Its a Cnr DM server, not really roleplay :P

yvoms
14/10/2016, 01:37 AM
I've tried the following code

CMD:taze(playerid, params[])
{
new targetid;
if(sscanf(params,"u",targetid)) return SendClientMessage(playerid,-1,"{ffaaaa}[Server]:{ffffff} /taze [ID | Name]");
if(gTeam[playerid] != TEAM_COP || gTeam[playerid] == TEAM_FBI || gTeam[playerid] == TEAM_CIA || gTeam[playerid] == TEAM_ARMY) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff}This command is restricted to the LEO class.");
new time = tickcount() - 60000;
if(time < TimerInfo[playerid][CMD_TAZE]) return SendClientMessage(playerid, -1, "{ff0000}[Error]: {ffffff}Please wait before using this command again.");
TimerInfo[playerid][CMD_TAZE] = tickcount();
if(targetid == playerid) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff} You can not taze yourself.");
if(GetPlayerWantedLevel(targetid) < 4) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff} This player's wanted level is to low to be tazed.");
if(GetDistanceBetweenPlayers(playerid, targetid) >= 5) return SendClientMessage(playerid, COLOR_WHITE, "{ff0000}[Error]: {ffffff} This player is not close enough to be tazed.");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[Error]:{ffffff} This Player is not connected.");
if(TimerInfo[playerid][CMD_TAZE] == 0)
{
new Tazert = random( 9 );
switch( Tazert )
{
case 0 .. 6:
{
TogglePlayerControllable( targetid, 0 );
stunned[ targetid ] = 1;
SetTimerEx( "stuntimer", STUNNED_TIME * 1000, 0, "i", targetid );
}

default:
{
SendClientMessage(playerid, COLOR_WHITE, "You failed to taze the dude" );
}
}
}
return 1;
}

However it does not seem to do anything, i gave it a few tweaks here and there.

azzerking
14/10/2016, 01:43 AM
Solution

Its not working because your doing this,

TimerInfo[playerid][CMD_TAZE] = tickcount();


and then your checking if

if(TimerInfo[playerid][CMD_TAZE] == 0)


This will never work, tickcount requires a parameter be passed so it can store the value by a reference.

I believe what your looking for is:

GetTickCount()


Also GetTickCount will never equal 0 for you or any player. So using this

if(TimerInfo[playerid][CMD_TAZE] == 0)


will never work, unless you manually set the value to 0.

yvoms
14/10/2016, 01:59 AM
/* Date/time functions
*
* (c) Copyright 2001-2005, ITB CompuPhase
* This file is provided as is (no warranties).
*/
#if defined _time_included
#endinput
#endif
#define _time_included
#pragma library Time

native gettime(&hour=0, &minute=0, &second=0);
native getdate(&year=0, &month=0, &day=0);
native tickcount(&granularity=0);

How can it never equal 0?

azzerking
14/10/2016, 02:01 AM
Information

Because that function returns the amount of time your server has been alive / running. Do you think your server will also be running for 0 milliseconds?

Test it and you will find out, print the return of tickcount and you will see.

yvoms
14/10/2016, 02:05 AM
I'm doing this the exact same way at few other commands,
I have the timer stored in a enum on command execution, however
For the taze its not working, its not returning anything but the errors.
I.e Not close enough, restricted to cops, but if it should actually perform the Taze,
It goes blank.


Fixed.

azzerking
14/10/2016, 02:07 AM
Information

Trust me, check this: tickcount (https://wiki.sa-mp.com/wiki/Function:tickcount).

You must be doing something else in your other functions for this to work.

yvoms
14/10/2016, 02:21 AM
Anyway, it's not playing the animation, any idea why that could be?
Its the cower animation on the floor, is it because i'm toggleplayercontrolable after i set the anim?

azzerking
14/10/2016, 02:28 AM
Information

Yes, if you call TogglePlayerControllable while using an animation it will break the animation. You could set a timer and force the player to keep doing the animation until the required time is met.