SA-MP Forums Archive
Simple Scripting - 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: Simple Scripting (/showthread.php?tid=560818)



Simple Scripting - Shank - 30.01.2015

Hello, I am relatively new to scripting and I've been playing around and trying new things to get this command to work but it seems a bit buggy. Code:
Код HTML:
CMD:dpm(playerid, text[])
	{
	new string[128];
	format(string, sizeof(string), "%s says: %s", text, text);
	SendClientMessage(playerid, COLOR_SAY, string);
		return 1;
	}
This is what happens:


I want it to be Message says: SecondMessage


Re: Simple Scripting - Schneider - 30.01.2015

Are you using zcmd? Can you explain what the command is supposed to do exactly?
Is it that if I type "/dpm Hello!" all the other players see: "Schneider says: Hello!" ?

In that case:
pawn Код:
CMD:dpm(playerid, params[])
{
    new playername[MAX_PLAYER_NAME];
    new string[128];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "%s says: %s", playername, params);
    SendClientMessageToAll(COLOR_SAY, string);
    return 1;
}



Re: Simple Scripting - CalvinC - 30.01.2015

And what is "SecondMessage"?
Currently you've set it to display the text you write in both strings.
pawn Код:
"%s says: %s", text, text);
I can try to explain, the above simply means:
"string1 says: string2", string1 = text, string2 = text (Text is set for both strings, and defined as what you write.)


Re: Simple Scripting - Shank - 30.01.2015

I want it to be like this:
/dpm Mynameisjoe Hisnameisjoe = Mynameisjoe says: Hisnameisjoe
It's kind of hard to explain but that's pretty much it.


Re: Simple Scripting - CalvinC - 30.01.2015

You need to create 2 different strings for that. And i would recommend using sscanf too.
pawn Код:
CMD:dpm(playerid, text[])
{
    new string[128], text1[64], text2[64];
    if(sscanf(params, "s[64]s[64]", text1, text2)) return SendClientMessage(playerid, -1, "USAGE: /dpm [text1] [text2]");
    format(string, sizeof(string), "%s says: %s", text1, text2);
    SendClientMessage(playerid, COLOR_SAY, string);
    return 1;
}



Re: Simple Scripting - Shank - 30.01.2015

sscanf crashes my server for some reason, I already tried using it and I have everything installed correctly.

Could you put it into regular form?


Re: Simple Scripting - CalvinC - 30.01.2015

Sorry, use this:
pawn Код:
if(sscanf(text, "s[64]s[64]", text1, text2)) return SendClientMessage(playerid, -1, "USAGE: /dpm [text1] [text2]");
Otherwise, are you sure this is correct, according to your command processor?:
pawn Код:
CMD:dpm(playerid, text[])



Re: Simple Scripting - FunnyBear - 30.01.2015

Use sscanf2

pawn Код:
CMD:dpm(playerid, params[])
{
    new
        text[128];

    if(sscanf(params, "s", text))
        return SendClientMessage(playerid, 0xFFFFFFFF, "/dpm [Message]" );
       
    new
        Text1[128],
        name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, name, sizeof(name));
    format(Text1, sizeof(Text1), "%s says: %s", name, text);
    SendClientMessageToAll( COLOR_SAY, Text1);
    return 1;
}