SA-MP Forums Archive
Faction Radio Chat Help - 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)
+--- Thread: Faction Radio Chat Help (/showthread.php?tid=626731)



Faction Radio Chat Help - Jonggol - 19.01.2017

Hi, i need help with this problem, i want to make faction radio chat. i try to make a shortcut like when some player use command like this "/fr @ ..." this will be give message like [RADIO] Player_Name: Badge ....
@ is a shortcut to display player badge.

Example command:
Код:
/f(action)r(adio) [text] 
/fr @ copy that.
Input must be like:
Код:
[RADIO] Rank Player_Name: Badge copy that.
I try to make some code like this.
Код:
CMD:fr(playerid, params[])
{
    new text[128];
    
    if(PlayerData[playerid][pFaction] == -1) return SendErrorMessage(playerid, "You must in faction member to use this command");
    if (GetFactionType(playerid) == FACTION_GANG) return SendErrorMessage(playerid, "Family doesn't have faction radio.");
    if(sscanf(params,"s[128]",text)) return SendSyntaxMessage(playerid, "/f(action)r(adio) [text]");
    if(strval(text) > 128) return SendErrorMessage(playerid,"Text too long.");

    if(strfind(text, "@", true, text[0]))
    {
        SendFactionMessage(PlayerData[playerid][pFaction], FactionData[PlayerData[playerid][pFaction]][factionColor], "[RADIO] %s %s: %s.%03d %s", Faction_GetRank(playerid),ReturnName2(playerid, 0), GetInitials(Faction_GetRank(playerid)), PlayerData[playerid][pBadge], text[1]);
    }
    else
        SendFactionMessage(PlayerData[playerid][pFaction], FactionData[PlayerData[playerid][pFaction]][factionColor], "[RADIO] %s %s: %s", Faction_GetRank(playerid),ReturnName2(playerid, 0), text);
    return 1;
}
How to fix this?. this is two different image.




Re: Faction Radio Chat Help - Rufio - 19.01.2017

pawn Код:
CMD:fr(playerid, params[])
{
    new text[128];
   
    if(PlayerData[playerid][pFaction] == -1) return SendErrorMessage(playerid, "You must in faction member to use this command");
    if (GetFactionType(playerid) == FACTION_GANG) return SendErrorMessage(playerid, "Family doesn't have faction radio.");
    if(sscanf(params,"s[128]",text)) return SendSyntaxMessage(playerid, "/f(action)r(adio) [text]");
    if(strval(text) > 128) return SendErrorMessage(playerid,"Text too long.");

    if(text[0] == '@')
    {
        SendFactionMessage(PlayerData[playerid][pFaction], FactionData[PlayerData[playerid][pFaction]][factionColor], "[RADIO] %s %s: %s.%03d %s", Faction_GetRank(playerid),ReturnName2(playerid, 0), GetInitials(Faction_GetRank(playerid)), PlayerData[playerid][pBadge], text[1]);
    }
    else
        SendFactionMessage(PlayerData[playerid][pFaction], FactionData[PlayerData[playerid][pFaction]][factionColor], "[RADIO] %s %s: %s", Faction_GetRank(playerid),ReturnName2(playerid, 0), text);
    return 1;
}
Try this, not sure if it'll work.


Re: Faction Radio Chat Help - SyS - 19.01.2017

Код:
if(strfind(text, "@", true, text[0]))
https://sampwiki.blast.hk/wiki/Strfind

The red parameter is for position not for character so it should be 0 instead of text[0] or leave that parameter empty as the default value is 0.


Re: Faction Radio Chat Help - PrO.GameR - 19.01.2017

strfind returns the index of where it is found, and you clearly want to see if they use @ as first character, so why not just check the first character like Rufio suggested?
even if you want to check if it does hold an @, you should do
strfind(...) != -1


Re: Faction Radio Chat Help - Rufio - 19.01.2017

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
strfind returns the index of where it is found, and you clearly want to see if they use @ as first character, so why not just check the first character like Rufio suggested?
even if you want to check if it does hold an @, you should do
strfind(...) != -1

This, also to add on top of this, you can remove the brackets from if(text[0] == '@') to increase the readability just like you did with else. You don't need to put a bracket if you aren't going to execute more than one line of code. It is by no means an error, but it increases readability and looks better. It also slightly increases the optimization.


Re: Faction Radio Chat Help - SyS - 20.01.2017

Actually there is no need to use sscanf in in this case as params is string.Use isnull to check the param is empty and check the first letter of params is @ or not.