Somethings not working....
#1

Hello guys, I just came back to samp and started scripting again Although i was making a command but it didnt seem to work..


Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	dcmd(msg, 3, cmdtext);
	return 0;
}

dcmd_msg(playerid, params[])
{
	new
		input[21],
		string[60];
	if (sscanf(params, "s", input)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /msg [msg]");
	else
	{
		Msg[playerid] = input[0];
		Created[playerid] = 1;
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	new string[60];
	if(Created[playerid] == 1)
	{
		format(string,sizeof(string), "%s", Msg[playerid]);
		GameTextForPlayer(playerid, string, 5000, 6);
	}
	return 1;
}
mmhmm, anyone know whats wrong with the code? What im simply saying here is that when i set my msg and then kill my self (IG) it only shows the first letter of the msg when it should show the whole msg...
I knew how to do this before but now i forgot, hmm

-Lorenc
Reply
#2

I don't think you need "input[0]", try it with just "input"
Reply
#3

Well you are only getting the first letter beacuse of the [0] change it to something like..
pawn Код:
Msg[playerid] = strlen(input);
(I have been off a few weeks so I might do something wrong here but try it )
Reply
#4

Quote:
Originally Posted by randomkid88
Посмотреть сообщение
I don't think you need "input[0]", try it with just "input"
Nah, in doubt it will work..
Код:
must be assigned to an array
Quote:
Originally Posted by Fj0rtizFredde
Посмотреть сообщение
Well you are only getting the first letter beacuse of the [0] change it to something like..
pawn Код:
Msg[playerid] = strlen(input);
(I have been off a few weeks so I might do something wrong here but try it )
That dont work too... it shows one character and adds a I......
Reply
#5

First of all, please consider using zcmd.

Also, you don't need to use sscanf to retrieve one string. Use strlen in dcmd (isnull in zcmd):

pawn Код:
dcmd_msg(playerid, params[])
{
    new
        input[21],
        string[60];
    if (strlen(params)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /msg [msg]"); // Check cmd length
    else
    {
        Msg[playerid] = input[0];
        Created[playerid] = 1;
    }
    return 1;
}
The reason that you're only getting the first letter of your message is simply because you're retrieving the first cell (which is the first letter). Also I fail to see why you've created variable 'Created', you can just format the string to say "Nothing" and use strcmp to check whether it says nothing. There's no need at all to create another player array (you're wasting 2000 bytes of memory).

Use strmid to put your message in to a string.

Personally, I would find that using a PVar string would be more sufficient for this operation, seeing as you're setting a string (despite the fact that PVars are a bit slower than regular arrays), I've provided an efficient example below:

pawn Код:
CMD:msg(playerid, params[]) { // zcmd
    if(isnull(params)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /msg [msg]"); // Check command

    // Going by the string you set in OnPlayerDeath, a 60 character limit.
    if(strlen(params) < 61) SetPVarString(playerid, "pMsg", params); // Check length, if exceeds 60, message won't set
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason) {
    new string[60];

    if(GetPVarType(playerid, "pMsg") != 0) { // Check if PVar type is not 0. If it is, a message is not set.
        GetPVarString(playerid, "pMsg", string, sizeof(string)); // Retrieve the PVar string
        GameTextForPlayer(playerid, string, 5000, 6); // Send your gametext out.
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by Calgon
Посмотреть сообщение
First of all, please consider using zcmd.

Also, you don't need to use sscanf to retrieve one string. Use strlen in dcmd (isnull in zcmd):

pawn Код:
dcmd_msg(playerid, params[])
{
    new
        input[21],
        string[60];
    if (strlen(params)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /msg [msg]"); // Check cmd length
    else
    {
        Msg[playerid] = input[0];
        Created[playerid] = 1;
    }
    return 1;
}
The reason that you're only getting the first letter of your message is simply because you're retrieving the first cell (which is the first letter). Also I fail to see why you've created variable 'Created', you can just format the string to say "Nothing" and use strcmp to check whether it says nothing. There's no need at all to create another player array (you're wasting 2000 bytes of memory).

Use strmid to put your message in to a string.

Personally, I would find that using a PVar string would be more sufficient for this operation, seeing as you're setting a string (despite the fact that PVars are a bit slower than regular arrays), I've provided an efficient example below:

pawn Код:
CMD:msg(playerid, params[]) { // zcmd
    if(isnull(params)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /msg [msg]"); // Check command

    // Going by the string you set in OnPlayerDeath, a 60 character limit.
    if(strlen(params) < 61) SetPVarString(playerid, "pMsg", params); // Check length, if exceeds 60, message won't set
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason) {
    new string[60];

    if(GetPVarType(playerid, "pMsg") != 0) { // Check if PVar type is not 0. If it is, a message is not set.
        GetPVarString(playerid, "pMsg", string, sizeof(string)); // Retrieve the PVar string
        GameTextForPlayer(playerid, string, 5000, 6); // Send your gametext out.
    }
    return 1;
}
I love dcmd Although converting it still dosent work but dw guys ill forget that addon... just was in mind.. -.- <(??)
Reply
#7

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
I love dcmd Although converting it still dosent work but dw guys ill forget that addon... just was in mind.. -.- <(??)
So I just wrote that HUGE post out for nothing? Thanks.

How can you love dcmd? It's horrible. zcmd is a lot more easier to use, you don't have to define the command length in OnPlayerCommandText and yet it's even more efficient, but whatever.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)