SA-MP Forums Archive
[SOLVED]Megaphone - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED]Megaphone (/showthread.php?tid=122426)



[SOLVED]Megaphone - JoeDaDude - 21.01.2010

Hi,

I was given this code for Megaphone,
And well, Its not working right :P

pawn Код:
dcmd_megaphone(playerid, params[])
{
        new
        string[128],
        message[104];

        if(sscanf(params, "s", message))
        {
            SendClientMessage(playerid, COLOR_RED, "Usage: /megaphone [message]");
        }
        else if(GetPlayerTeam(playerid) == TEAM_POLICESF) return SendClientMessage(playerid, COLOR_RED, "You are not a Cop");
        {
            format(string, sizeof(string), "Officer [%s]: %s!", GetPlayerNameEx(playerid), message);
            SendClientMessage(playerid, COLOR_YELLOW, string);
            for(new i = 0; i < MAX_PLAYERS; i++)
        {
            while(GetDistanceBetweenPlayers(playerid, i) < 7.0)
        {
            SendClientMessage(i, COLOR_YELLOW, string);
        }
    }
}
        return 1;
}
It just spams this on my chatbox,

Officer [Torran]: !

On every line of my chatbox,
How to fix,


Re: Megaphone - JoeDaDude - 21.01.2010

Btw, I dont know wether it works if i type a message,
Because i just typed /megaphone


Re: Megaphone - TheGtaLover - 21.01.2010

Код:
if(strcmp(cmd, "/megaphone", true) == 0 || strcmp(cmd, "/m", true) == 0)
{
new tmpcar = GetPlayerVehicleID(playerid);
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[128];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/m)egaphone [megaphone chat]");
return 1;
}
if (gTeam[playerid] != 2)
{
SendClientMessage(playerid, COLOR_GRAD2, " you are not part of a team");
return 1;
}
if(!IsACopCar(tmpcar))
{
SendClientMessage(playerid, COLOR_GRAD2, " you are not in a police vehicle");
return 1;
}
format(string, sizeof(string), "[Officer %s:o< %s]", sendername, result);
ProxDetector(60.0, playerid, string,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW,COLOR_YELLOW);
printf("%s", string);
return 1;
}
just use that. works perfect, and its a megaphone from an rrp script. so yah, should work.
edit it to your own needs


Re: Megaphone - JoeDaDude - 21.01.2010

Cant be bothered, Id like to use the one i have,
All i need fixing is this spamming problem


Re: Megaphone - JoeDaDude - 21.01.2010

Also if i type /megaphone test
Nothing happens, Or if it does,
It just spams again, But with ! and Not my message,
And then i crash



Re: Megaphone - TheGtaLover - 21.01.2010

format(string, sizeof(string), "Officer [%s]: %s!", GetPlayerNameEx(playerid), message);

maybe change message to result..


Re: Megaphone - Miguel - 21.01.2010

Use if(condition) instead of while(condition). I just found out using while spams the chat.


Re: Megaphone - [HiC]TheKiller - 21.01.2010

Like SAWC said, while will check if something is in range of the point and if the condition doesn't change it will still send the message over and over. Using if passes the message once and only once per person if they are in the range of the player.


Re: Megaphone - JoeDaDude - 21.01.2010

Ok now,

If i type /megaphone,
it says the usage,

Then

Officer [Torran]: !

Twice

And if i say, /megaphone test

It says

Officer [Torran]: Test!

Twice??


Re: Megaphone - Miguel - 21.01.2010

pawn Код:
dcmd_megaphone(playerid, params[])
{
        new
        string[128],
        message[104];

        if(sscanf(params, "s", message))
        {
            SendClientMessage(playerid, COLOR_RED, "Usage: /megaphone [message]");
        }
        else if(GetPlayerTeam(playerid) == TEAM_POLICESF) return SendClientMessage(playerid, COLOR_RED, "You are not a Cop");
        {
            format(string, sizeof(string), "Officer [%s]: %s!", GetPlayerNameEx(playerid), message);
            SendClientMessage(playerid, COLOR_YELLOW, string); // take this line out
            for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(GetDistanceBetweenPlayers(playerid, i) < 7.0)
        {
            SendClientMessage(i, COLOR_YELLOW, string);
        }
    }
}
        return 1;
}
Remove that line.

For the first error, you'll have to change:
pawn Код:
else if(GetPlayerTeam(playerid) == TEAM_POLICESF) return SendClientMessage(playerid, COLOR_RED, "You are not a Cop");
For
pawn Код:
else if(GetPlayerTeam(playerid) != TEAM_POLICESF) return SendClientMessage(playerid, COLOR_RED, "You're not a cop");
else
{
  //command effect
}