[HELP] /Addscore
#1

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/addscore", cmdtext, true, 10) == 0)
    {
        new tmp[256];
        tmp = strtok ( cmdtext, idx );
        if ( !strlen ( tmp ) )
        {
            SendClientMessage(playerid, COLOR_RED, "USAGE: /addscore [ID]");
            return 1;
  }
        new score = GetPlayerScore(playerid);
        SetPlayerScore(playerid,score+1);
       
        new name[MAX_PLAYER_NAME], string[44];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s added 1 score extra to your account.",name); //sends that message only to the plyer who got the score... %s is meant to say the Playername + ID of who added the score to him
        SendClientMessageToAll(0xFFFF00AA, string);

        return 1;
    }
    return 0;
}
Example: Larsey123 added 1 score extra to your account
Reply
#2

What is it that you want help with exactly?
Reply
#3

never used strcmp and strtok, i'll give it a try.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/addscore", cmdtext, true, 10) == 0)
    {
        new tmp[256];
        tmp = strtok ( cmdtext, idx );
        if ( !strlen ( tmp ) )
        {
            SendClientMessage(playerid, COLOR_RED, "USAGE: /addscore [ID]");
            return 1;
  }
        new score = GetPlayerScore(tmp);
        SetPlayerScore(tmp,score+1);
       
        new name[MAX_PLAYER_NAME], string[49];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s(%d) added 1 score extra to your account.",name,playerid); //sends that message only to the plyer who got the score... %s is meant to say the Playername + ID of who added the score to him
        SendClientMessagel(tmp,0xFFFF00AA, string);

        return 1;
    }
    return 0;
}
Reply
#4

pawn Код:
if(strcmp(cmd, "/addscore", true) == 0)
    {
            new tmp[128];
            tmp = strtok(cmdtext, idx);
            if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /addscore [playerid]");
            if(IsPlayerConnected(strval(tmp)))
            {
                new score = GetPlayerScore(strval(tmp));
                SetPlayerScore(strval(tmp),score+1);

                new name[MAX_PLAYER_NAME], string[128];
                GetPlayerName(playerid, name, sizeof(name));
               
                format(string, sizeof(string), "%s added 1 score extra to your account.",name);
                SendClientMessage(strval(tmp), 0xFFFF00AA, string);
            }
            return 1;
    }
Reply
#5

pawn Код:
#include <a_samp>

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/addscore", cmdtext, true, 10) == 0)
    {
            new tmp[128];
            tmp = strtok(cmdtext, idx); //Line 8
            if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /addscore [playerid]");
            if(IsPlayerConnected(strval(tmp)))
            {
                new score = GetPlayerScore(strval(tmp));
                SetPlayerScore(strval(tmp),score+1);

                new name[MAX_PLAYER_NAME], string[128];
                GetPlayerName(playerid, name, sizeof(name));

                format(string, sizeof(string), "%s added 1 score extra to your account.",name);
                SendClientMessage(strval(tmp), 0xFFFF00AA, string);
            }
            return 1;
    }
    return 0;
}
ERROR:
pawn Код:
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\GiveScore.pwn(8) : error 017: undefined symbol "strtok"
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\GiveScore.pwn(8) : error 033: array must be indexed (variable "tmp")
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


2 Errors.
Reply
#6

strtok uses 256 size, but luckily i have a strtok that uses 128

pawn Код:
stock strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply
#7

1 ERROR Left :P

pawn Код:
C:\Users\Larsey123\Documents\SAMP Server\My server\filterscripts\GiveScore.pwn(8) : error 017: undefined symbol "idx"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Reply
#8

new idx; next to new tmp
Reply
#9

Код:
#include <a_samp>

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/addscore", cmdtext, true, 10) == 0)
    {
            new tmp[128}, idx;
            tmp = strtok(cmdtext, idx); //Line 8
            if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /addscore [playerid]");
            if(IsPlayerConnected(strval(tmp)))
            {
                new score = GetPlayerScore(strval(tmp));
                SetPlayerScore(strval(tmp),score+1);

                new name[MAX_PLAYER_NAME], string[128];
                GetPlayerName(playerid, name, sizeof(name));

                format(string, sizeof(string), "%s added 1 score extra to your account.",name);
                SendClientMessage(strval(tmp), 0xFFFF00AA, string);
            }
            return 1;
    }
    return 0;
}
Try that
Reply
#10

Quote:
Originally Posted by Tessar
Код:
new tmp[128}, idx;
Switch the } for ]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)