taze command?
#1

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

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

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

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

Its a Cnr DM server, not really roleplay :P
Reply
#6

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

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

Код:
/* Date/time functions
 *
 * © 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?
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)