How to add a /me to a command
#1

Hello,

I got a cool fs of a tazer but when i /tazer it sends a message to yourself( SendClientMessage(playerid,GREEN,"Your tazer has been un-holsterd"); )

I want to change it to: /me Un-Holsters his/her tazer.

How to do that? is there a code for like SendClientMessage ?

Please help me!

Thank you,

Braynboyj
.
Reply
#2

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/me", true, 3)) // 3 is the length of /me
    {
        if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /me [action]");
        new str[128];
        GetPlayerName(playerid, str, sizeof(str));
        format(str, sizeof(str), "* %s %s", str, cmdtext[4]);
        SendClientMessageToAll(0xFFFF00AA, str);
        return 1;
    }
    return 0;
}
ZCMD
pawn Код:
COMMAND:me(playerid, params[])
{
     if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /me [action]");
     new str[128];
     GetPlayerName(playerid, str, sizeof(str));
     format(str, sizeof(str), "* %s %s", str, cmdtext[4]);
     SendClientMessageToAll(0xFFFF00AA, str);
     return 1;
}
Reply
#3

Can we see the tazer cmd then? Can't help you without.
Reply
#4

pawn Код:
CMD:me(playerid,params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, red, "Usage: /me [text]");
    new string[128], name[24], Float:x, Float:y, Float:z;
    GetPlayerName(playerid,name,24);
    GetPlayerPos(playerid,x,y,z);
    format(string,128,"%s %s",name,params);
    foreach(Player, i)
    {
        if(IsPlayerInRangeOfPoint(i, 10, x, y, z))
        {
            SendClientMessage(i,red, string);
        }
    }
    return 1;
}
If a player is within 10 units of playerid, he will see the string.
Use zcmd and foreach
Reply
#5

You could use a function from the GF script which is the "ProxDetecor" or make a callback that sends the message to all the players around him/her.

Try this:

Код:
forward SlashMe(playerid, string[], Float:x, Float:y, Float:z);

public SlashMe(playerid, string[], Float:x, Float:y, Float:z)
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerInRangeOfPoint(i, 5.0, x, y, z))
	    {
	        SendClientMessage(i, 0xCE6FD9FF, string);
	    }
	}
}

if(strcmp(cmd, "/tazer", true) == 0)
{
	if(IsPlayerConnected(playerid))
	{
		new pos[3], text[64], playername[MAX_PLAYER_NAME];
		GetPlayerName(playerid, playername, sizeof(playername)
		GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
	    // do something here
	    format(text, sizeof(text), "* %s unholsters their taze.", playername);
	    SlashMe(playerid, text, pos[0], pos[1], pos[2]);
	}
	return 1;
}
I didn't test the code though, hope it works.
Reply
#6

Whole code:
Код:
if(tazeronbelt[playerid] == 1)
            {
				tazeronbelt[playerid] = 0;
				SetPlayerAttachedObject(playerid, 0, 18642, 6, 0.06, 0.01, 0.08, 180.0, 0.0, 0.0);
				SendClientMessage(playerid,GREEN,"Your tazer has been un-holsterd");
			}
			else if(tazeronbelt[playerid] == 0)
			{
				tazeronbelt[playerid] = 1;
                RemovePlayerAttachedObject(playerid, 0);
                SendClientMessage(playerid,GREEN, "Your tazer has been holsterd");
			}
			else
			{
				SendClientMessage(playerid, GREEN, "You are not connected");
			}
		}
		else
		{
		    SendClientMessage(playerid, GREEN, "You are not a cop");
		}
		return 1;
	}
	return 1;
}
Reply
#7

btw its not a SDpistol tazer,
its like this one: https://sampforum.blast.hk/showthread.php?tid=194706

I just need to add a /me when people use /tazer thats all.
Reply
#8

Quote:
Originally Posted by Alvord
Посмотреть сообщение
You could use a function from the GF script which is the "ProxDetecor" or make a callback that sends the message to all the players around him/her.

Try this:

Код:
forward SlashMe(playerid, string[], Float:x, Float:y, Float:z);

public SlashMe(playerid, string[], Float:x, Float:y, Float:z)
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(IsPlayerInRangeOfPoint(i, 5.0, x, y, z))
	    {
	        SendClientMessage(i, 0xCE6FD9FF, string);
	    }
	}
}

if(strcmp(cmd, "/tazer", true) == 0)
{
	if(IsPlayerConnected(playerid))
	{
		new pos[3], text[64], playername[MAX_PLAYER_NAME];
		GetPlayerName(playerid, playername, sizeof(playername)
		GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
	    // do something here
	    format(text, sizeof(text), "* %s unholsters their taze.", playername);
	    SlashMe(playerid, text, pos[0], pos[1], pos[2]);
	}
	return 1;
}
I didn't test the code though, hope it works.
ProxDetector is slower than IsPlayerInRangeOfPoint since natives are faster.
Reply
#9

Here is the whole fs of it:

Код:
/*
||||||||||||||||||||||||||||||||||||||||||||||||||
||0.3C Tazer System                             ||
||Please do not re-release without my permission||
||Do not claim this as your own                 ||
||Enjoy!                                        ||
||||||||||||||||||||||||||||||||||||||||||||||||||
*/
#define FILTERSCRIPT
#include <a_samp>
#include <zcmd>
#define GREEN 0x21DD00FF
new tazeronbelt[MAX_PLAYERS];
new tazertimer[MAX_PLAYERS];
forward Float:GetDistanceBetweenPlayers(p1,p2); // Not created by me, Dont know who made this.
forward tazeroff(playerid);
forward usetazeragain(playerid);
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Tazer System Loaded");
	print("--------------------------------------\n");
	return 1;
}
#endif
public OnFilterScriptExit()
{
    print("\n--------------------------------------");
	print(" Tazer System Unloaded");
	print("--------------------------------------\n");
	return 1;
}
public OnPlayerConnect(playerid)
{
	tazeronbelt[playerid] = 1;
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	tazeronbelt[playerid] = 1;
	return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE)
    {
        if(tazeronbelt[playerid] == 0)
        {
            if(GetPlayerSkin(playerid) == 280 || GetPlayerSkin(playerid) == 281 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 283 || GetPlayerSkin(playerid) == 288 || GetPlayerSkin(playerid) == 284|| GetPlayerSkin(playerid) == 286|| GetPlayerSkin(playerid) == 285|| GetPlayerSkin(playerid) == 265|| GetPlayerSkin(playerid) == 266|| GetPlayerSkin(playerid) == 267|| GetPlayerSkin(playerid) == 287)
            {
                new tazervictim = GetClosestPlayer(playerid);
                new Float:health;
                if(GetPlayerSkin(tazervictim) == 280 || GetPlayerSkin(tazervictim) == 281 || GetPlayerSkin(tazervictim) == 282 || GetPlayerSkin(tazervictim) == 283 || GetPlayerSkin(tazervictim) == 288 || GetPlayerSkin(tazervictim) == 284)
				{
				    SendClientMessage(playerid, GREEN, "You cant tazer other cops");
				    return 1;
				}
				if(tazertimer[playerid] == 1)
				{
				    SendClientMessage(playerid, GREEN, "Please wait before tazing again");
				    return 1;
				}
                if(GetDistanceBetweenPlayers(playerid,tazervictim) < 2)
                {
                    ApplyAnimation(playerid,"KNIFE","knife_3",4.1,0,1,1,0,0,1);
                    TogglePlayerControllable(tazervictim, 0);
                    ApplyAnimation(tazervictim, "PED","FLOOR_hit_f", 4.0, 1, 0, 0, 0, 0);
                    GetPlayerHealth(tazervictim, health);
	                SetPlayerHealth(tazervictim, health - 2);
	                SendClientMessage(tazervictim, GREEN, "You have been tazed for 20 seconds");
	                SetTimerEx("tazeroff", 20000, false, "i", tazervictim);
	                SetTimerEx("usetazeragain", 9000, false, "i", playerid);
	                tazertimer[playerid] = 1;
				 }
			}
			return 1;
		}
	}
	return 1;
}
public usetazeragain(playerid)
{
	tazertimer[playerid] = 0;
	return 1;
}
public tazeroff(playerid)
{
    new tazervictim = GetClosestPlayer(playerid);
    TogglePlayerControllable(tazervictim, 1);
    SendClientMessage(playerid, GREEN, "You have been un-tazed");
    return 1;
}
CMD:tazer(playerid,params[])
{
    if(IsPlayerConnected(playerid))
    {
		if(GetPlayerSkin(playerid) == 280 || GetPlayerSkin(playerid) == 281 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 283 || GetPlayerSkin(playerid) == 288 || GetPlayerSkin(playerid) == 286|| GetPlayerSkin(playerid) == 284|| GetPlayerSkin(playerid) == 285|| GetPlayerSkin(playerid) == 287|| GetPlayerSkin(playerid) == 265|| GetPlayerSkin(playerid) == 266|| GetPlayerSkin(playerid) == 267)
        {
            if(tazeronbelt[playerid] == 1)
            {
				tazeronbelt[playerid] = 0;
				SetPlayerAttachedObject(playerid, 0, 18642, 6, 0.06, 0.01, 0.08, 180.0, 0.0, 0.0);
				SendClientMessage(playerid,GREEN,"Your tazer has been un-holsterd");
			}
			else if(tazeronbelt[playerid] == 0)
			{
				tazeronbelt[playerid] = 1;
                RemovePlayerAttachedObject(playerid, 0);
                SendClientMessage(playerid,GREEN,"Your tazer has been holsterd");

                
			}
			else
			{
				SendClientMessage(playerid, GREEN, "You are not connected");
			}
		}
		else
		{
		    SendClientMessage(playerid, GREEN, "You are not a cop");
		}
		return 1;
	}
	return 1;
}
stock GetClosestPlayer(playerid) // Not created by me, Dont know who made this.
{
    new Float:cdist, targetid = -1;
    for(new i; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i) && playerid != i && (targetid < 0 || cdist > GetDistanceBetweenPlayers(playerid, i)))
        {
            targetid = i;
            cdist = GetDistanceBetweenPlayers(playerid, i);
        }
    }
    return targetid;
}
public Float:GetDistanceBetweenPlayers(p1,p2) // Not created by me, Dont know who made this.
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
	{
		return -1.00;
	}
	GetPlayerPos(p1,x1,y1,z1);
	GetPlayerPos(p2,x2,y2,z2);
	return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
please copy it and fix it please for me and paste it as a reply,
Reply
#10

Quote:
Originally Posted by Mean
Посмотреть сообщение
ProxDetector is slower than IsPlayerInRangeOfPoint since natives are faster.
Uhmm... didn't I post 2 options? xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)