SA-MP Forums Archive
Not performing correctly (Commands) - 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: Not performing correctly (Commands) (/showthread.php?tid=580573)



[SOLVED]Not performing correctly (Commands) - Sime30 - 06.07.2015

Edit: Thanks SickAttack, Kaliber and Jefff for solving this problem. I have chosen the best solution to my problem. Use it if you need it.

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Problem was in <= MAX_PLAYER_NAME should be < MAX_PLAYER_NAME but here you go better
pawn Код:
InGameChatRemoveUnderscore(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i = strlen(name)-1; i > -1; i--)
        if(name[i] == '_')
            name[i] = ' ';

    return name;
}


Hi guys!

Haven't use samp servers for a while now and wanted to update my gamemode a bit.
The thing is, my commands stopped working(not all of them).

Things I remember I have done:
- Updated ZCMD to I-ZCMD
- Updated to PlayerPoolSize and VehiclePoolSize , new functions in 0.3.7


I reverted to ZCMD and some of the for(new... loops back to basic ones.


When I type this command, it returns me -Command not recognized-
pawn Код:
CMD:b(playerid, params[])
{
    new string[128];
    if(isnull(params)) return SCM(playerid,LIGHTBLUE,"Use: {FFFFFF}/b [text]");
    format(string, sizeof(string), "%s: (( %s ))",InGameChatRemoveUnderscore(playerid),params);
    ProxDetector(25.0, playerid, string, COLOR_WHITE);
    return 1;
}

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(!success) return SendClientMessage(playerid, LIGHTBLUE, "Las Vegas: Origins -{FFFFFF} Command not recognized, use {33CCFF}/help" );
    return 1;
}


forward ProxDetector(Float:radi, playerid, string[],color);
public ProxDetector(Float:radi, playerid, string[],color)
{
    if(PlayerInfo[playerid][Logged] == false) return 1;
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    foreach(Player,i)
    {
        if(IsPlayerInRangeOfPoint(i,radi,x,y,z) && GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i) && PlayerInfo[i][Logged] == true)
        {
            SendClientMessage(i,color,string);
        }
    }
    return 1;
}
For example, my command /makebiz works perfectly, while /givemoney will give me money, but will send me a message "Command not recognized".

Yeah, I really don't know what I have done hahaha. Maybe ZCMD, SSCANF2?

pawn Код:
CMD:givemoney(playerid, params[])
{
        if(PlayerInfo[playerid][AdminLevel] < HEAD_ADMIN) return SendClientMessage(playerid, COLOR_NICERED, "Denied!");
        new id,money;
        if(sscanf(params, "ui",id,money)) return SendClientMessage(playerid, LIGHTBLUE, "Use:{FFFFFF} /givemoney [ID Player] [Money]");
        if(PlayerInfo[id][Logged] == false) return SCM(playerid, COLOR_ERROR,"That player is Offline!");
        if(id == INVALID_PLAYER_ID)return SCM(playerid,COLOR_ERROR,"Wrong ID!");
        GiveHimMoney(id, money);
        new str[100];
        format(str,sizeof(str),"You gave{FFFFFF} %s  {00C0FF}$%d",InGameChatRemoveUnderscore(id), money);
        SendClientMessage(playerid,LIGHTBLUE,str);
        format(str,sizeof(str),"Admin {FFFFFF} %s gave you {00C0FF}$%d ",InGameChatRemoveUnderscore(playerid),money);
        SendClientMessage(id,LIGHTBLUE,str);
        return 1;
}



Re: Not performing correctly (Commands) - SickAttack - 06.07.2015

I assume the function/macro "SCM" is returning 0; therefore, that message shows up. Or it could be a flaw in one of the functions being called.


Re: Not performing correctly (Commands) - JaydenJason - 06.07.2015

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
I assume the function/macro "SCM" is returning 0; therefore, that message shows up.
I doubt that, I think SCM is just a redefinition of SendClientMessage
Код:
#define SCM SendClientMessage
Howeeeeever, I think that it would have to do something with the new zcmd include you have, have you tried to use the previous zcmd include and see if the commands still return the unknown command thing?


Re: Not performing correctly (Commands) - Sime30 - 06.07.2015

Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
I doubt that, I think SCM is just a redefinition of SendClientMessage
Код:
#define SCM SendClientMessage
Howeeeeever, I think that it would have to do something with the new zcmd include you have, have you tried to use the previous zcmd include and see if the commands still return the unknown command thing?
Yes, it's just a redefinition. Yes, I reverted it to the original Zeex's ZCMD and the problem persists.


Re: Not performing correctly (Commands) - SickAttack - 06.07.2015

Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
I doubt that, I think SCM is just a redefinition of SendClientMessage
Код:
#define SCM SendClientMessage
Howeeeeever, I think that it would have to do something with the new zcmd include you have, have you tried to use the previous zcmd include and see if the commands still return the unknown command thing?
Check the functions used in the command and post them here as well. Also you could remove that definition since you are already using SendClientMessage.


Re: Not performing correctly (Commands) - Sime30 - 06.07.2015

pawn Код:
CMD:b(playerid, params[])
{
    new string[128];
    if(isnull(params)) return SCM(playerid,LIGHTBLUE,"Use: {FFFFFF}/b [text]");
    format(string, sizeof(string), "%s: (( %s ))",InGameChatRemoveUnderscore(playerid),params);
    ProxDetector(25.0, playerid, string, COLOR_WHITE);
    return 1;
}
ProxDetector is above, and here is InGameChat...
pawn Код:
InGameChatRemoveUnderscore(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i; i <= MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}
The thing is, if I type /b, it shows the usage, but anything after that like /b test will show command not recognized.


Re: Not performing correctly (Commands) - Sime30 - 06.07.2015

Any thoughts about this?


Re: Not performing correctly (Commands) - SickAttack - 06.07.2015

The issue is caused by a flaw in "InGameChatRemoveUnderscore(playerid)".

pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <zcmd>

// DEFINES:

#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

// MAIN:

main()
{
    print("Development Mode: rp_name.amx");
}

// CALLBACKS:

public OnGameModeInit()
{  
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// COMMANDS:

CMD:b(playerid, params[])
{
    new string[144];
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /b (message).");

    format(string, sizeof(string), "%s: (( %s ))", ReplaceString("_", " ", PlayerName(playerid)), params);
    SendClientMessageToAll(-1, string);
    return 1;
}

// FUNCTIONS:

stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    return name;
}

stock ReplaceString(search[], replace[], source[])
{
    new string[256], length;
    for(new i = 0; i < strlen(source); i ++)
    {
        if(strlen(search) > 1 && i != (strlen(source) - 1))
        {
            new bool:match = false, start = i;
            for(new j = 0; j < strlen(search) && !match; j ++)
            {
                if(source[i] != search[j] && j == 0)
                {
                    string[length] = source[i];
                    match = true;
                }
                else
                {
                    if(source[i] == search[j]) i ++;
                    else match = true;
                }
            }

            if(match == true)
            {
                while(start <= i)
                {
                    string[length] = source[start];
                    length ++;
                    start ++;
                }
            }
            else
            {
                for(new j; j < strlen(replace); j ++)
                {
                    string[length] = replace[j];
                    length ++;
                }

                i = (start + (strlen(search) - 1));
            }
        }
        else
        {
            if(strlen(search) == 1 && source[i] == search[0])
            {
                for(new j; j < strlen(replace); j ++)
                {
                    string[length] = replace[j];
                    length ++;
                }
            }
            else
            {
                string[length] = source[i];
                length ++;
            }
        }
    }

    string[length] = EOS;
    return string;
}



Re: Not performing correctly (Commands) - Sime30 - 06.07.2015

@SickAttack

That done the trick. Just tested and it works as intended.
I don't know where did I get my code from, maybe some snippet from this forum. Anyway, I will change all my codes now to this and test. I will reply here for further information.


Thanks man


AW: Not performing correctly (Commands) - Kaliber - 06.07.2015

@SickAttack:

Your function ReplaceString is horrible

Just easy do this:

PHP код:
stock ReplaceString(const search[],const replace[], source[], size=sizeof source//© by Kaliber
{
    new 
i=strfind(source,search),tmp=strlen(search);
    if(
i==-1) return 0;
    for( ; 
i!=-1i=strfind(source,search,false,i+1))
    {
        
strdel(source,i,i+tmp),strins(source,replace,i,size);
    }
    return 
1;

Greekz