SA-MP Forums Archive
help in strcmp command - 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: help in strcmp command (/showthread.php?tid=620568)



help in strcmp command - bugmenotlol - 31.10.2016

i had a gate script but its not working in my server. so i decided to use a gate system fs so my gamemode uses default command that is strcmp so this fs is in zcmd


so i need to convert this to strmp

Код:
CMD:gate(playerid, params[])
{
    //  Gates
    new done;
    for(new idx=1; idx<MAX_GATES; idx++)
    {
        new Float:cur[3];
        if(GateInfo[idx][gModel])
        {
            GetDynamicObjectPos(GateInfo[idx][gGate], cur[0], cur[1], cur[2]);
            if(IsPlayerInRangeOfPoint(playerid, 8, cur[0], cur[1], cur[2]) || IsPlayerInRangeOfPoint(playerid, 8, GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ]) || IsPlayerInRangeOfPoint(playerid, 8, GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ]))
            {
                if(strlen(GateInfo[idx][gPassword]))
                {
                    if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, 0xFFFFFF00, "USAGE: /gate [password]");
                    if(strcmp(params, GateInfo[idx][gPassword])) return SendClientMessage(playerid, -1, "Invalid gate password.");
                    if(!GateInfo[idx][gStatus])
                    {
                        GateInfo[idx][gStatus] = 1;
                        MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ], GateInfo[idx][gSpeed], GateInfo[idx][gORX], GateInfo[idx][gORY], GateInfo[idx][gORZ]);
                        done=1;
                        break;
                    }
                    else
                    {
                        GateInfo[idx][gStatus] = 0;
                        MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ], GateInfo[idx][gSpeed], GateInfo[idx][gCRX], GateInfo[idx][gCRY], GateInfo[idx][gCRZ]);
                        done=1;
                        break;
                    }
                }
                else
                {
                    if(!GateInfo[idx][gStatus])
                    {
                        GateInfo[idx][gStatus] = 1;
                        MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ], GateInfo[idx][gSpeed], GateInfo[idx][gORX], GateInfo[idx][gORY], GateInfo[idx][gORZ]);
                        done=1;
                        break;
                    }
                    else
                    {
                        GateInfo[idx][gStatus] = 0;
                        MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ], GateInfo[idx][gSpeed], GateInfo[idx][gCRX], GateInfo[idx][gCRY], GateInfo[idx][gCRZ]);
                        done=1;
                        break;
                    }
                }
            }
        }
    }
    if(!done) SendClientMessage(playerid, -1, "You aren't near a gate you can open.");
    return 1;
}



Re: help in strcmp command - bugmenotlol - 31.10.2016

will give rep if its correct i tried to convert but it shows undefined symbol parama


Re: help in strcmp command - Threshold - 31.10.2016

Why not just convert your gamemode commands from strcmp to zcmd?


Re: help in strcmp command - bugmenotlol - 31.10.2016

there is lot commands to convert
so it is easy to convert just 1 command instead of 500 commands


Re: help in strcmp command - Threshold - 31.10.2016

With the replacement function in pawno (CTRL + H), it's pretty easy to replace them all. All you have to do after that is just worry about commands with parameters, but I'd be looking at trying to use ZCMD instead of Strcmp.

Then again, I'm not the one to tell you how to run your server, no matter how inefficient the methods are.

Obviously the first step in converting from ZCMD to Strcmp is to change 'CMD:' to 'strcmp' and relocate the command itself.
PHP код:
CMD:gate(playeridparams[]) 
Becomes:
PHP код:
if(strcmp(cmdtext"/gate"true5) == 0
Then you basically replace 'params' with 'cmdtext[7]', which is the contents of 'cmdtext' from index 7 and onwards.

PHP код:
    if(strcmp(cmdtext"/gate"true5) == 0)
    {
        
//  Gates
        
new done;
        for(new 
idx 1idx MAX_GATESidx++)
        {
            new 
Float:cur[3];
            if(
GateInfo[idx][gModel])
            {
                
GetDynamicObjectPos(GateInfo[idx][gGate], cur[0], cur[1], cur[2]);
                if(
IsPlayerInRangeOfPoint(playerid8cur[0], cur[1], cur[2]) || IsPlayerInRangeOfPoint(playerid8GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ]) || IsPlayerInRangeOfPoint(playerid8GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ]))
                {
                    if(
GateInfo[idx][gPassword][0] != EOS)
                    {
                        if(
strlen(cmdtext) < 7) return SendClientMessage(playerid0xFFFFFF00"USAGE: /gate [password]");
                        if(
strcmp(cmdtext[7], GateInfo[idx][gPassword])) return SendClientMessage(playerid, -1"Invalid gate password.");
                    }
                    if(!
GateInfo[idx][gStatus]) MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ], GateInfo[idx][gSpeed], GateInfo[idx][gORX], GateInfo[idx][gORY], GateInfo[idx][gORZ]);
                    else 
MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ], GateInfo[idx][gSpeed], GateInfo[idx][gCRX], GateInfo[idx][gCRY], GateInfo[idx][gCRZ]);
                    
GateInfo[idx][gStatus] = !GateInfo[idx][gStatus];
                    
done 1;
                    break;
                }
            }
        }
        if(!
doneSendClientMessage(playerid, -1"You aren't near a gate you can open.");
        return 
1;
    } 
Made a few alterations to the command and removed some redundant code.

EDIT: And why does 'idx' start at 1 by the way?


Re: help in strcmp command - bugmenotlol - 31.10.2016

Quote:
Originally Posted by Threshold
Посмотреть сообщение
With the replacement function in pawno (CTRL + H), it's pretty easy to replace them all. All you have to do after that is just worry about commands with parameters, but I'd be looking at trying to use ZCMD instead of Strcmp.

Then again, I'm not the one to tell you how to run your server, no matter how inefficient the methods are.

Obviously the first step in converting from ZCMD to Strcmp is to change 'CMD:' to 'strcmp' and relocate the command itself.
PHP код:
CMD:gate(playeridparams[]) 
Becomes:
PHP код:
if(strcmp(cmdtext"/gate"true5) == 0
Then you basically replace 'params' with 'cmdtext[7]', which is the contents of 'cmdtext' from index 7 and onwards.

PHP код:
    if(strcmp(cmdtext"/gate"true5) == 0)
    {
        
//  Gates
        
new done;
        for(new 
idx 1idx MAX_GATESidx++)
        {
            new 
Float:cur[3];
            if(
GateInfo[idx][gModel])
            {
                
GetDynamicObjectPos(GateInfo[idx][gGate], cur[0], cur[1], cur[2]);
                if(
IsPlayerInRangeOfPoint(playerid8cur[0], cur[1], cur[2]) || IsPlayerInRangeOfPoint(playerid8GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ]) || IsPlayerInRangeOfPoint(playerid8GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ]))
                {
                    if(
GateInfo[idx][gPassword][0] != EOS)
                    {
                        if(
strlen(cmdtext) < 7) return SendClientMessage(playerid0xFFFFFF00"USAGE: /gate [password]");
                        if(
strcmp(cmdtext[7], GateInfo[idx][gPassword])) return SendClientMessage(playerid, -1"Invalid gate password.");
                    }
                    if(!
GateInfo[idx][gStatus]) MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gOX], GateInfo[idx][gOY], GateInfo[idx][gOZ], GateInfo[idx][gSpeed], GateInfo[idx][gORX], GateInfo[idx][gORY], GateInfo[idx][gORZ]);
                    else 
MoveDynamicObject(GateInfo[idx][gGate], GateInfo[idx][gCX], GateInfo[idx][gCY], GateInfo[idx][gCZ], GateInfo[idx][gSpeed], GateInfo[idx][gCRX], GateInfo[idx][gCRY], GateInfo[idx][gCRZ]);
                    
GateInfo[idx][gStatus] = !GateInfo[idx][gStatus];
                    
done 1;
                    break;
                }
            }
        }
        if(!
doneSendClientMessage(playerid, -1"You aren't near a gate you can open.");
        return 
1;
    } 
Made a few alterations to the command and removed some redundant code.

EDIT: And why does 'idx' start at 1 by the way?
command not showing its show unknown command


Re: help in strcmp command - bugmenotlol - 31.10.2016

is it easy to convrrt to dcmd ??
and also can we use strcmp and dcmd together at a time ?


Re: help in strcmp command - Threshold - 31.10.2016

There's nothing wrong from what I can see in the code. Use the crashdetect plugin and see if you get any errors in your console when you use this command. You should avoid dcmd... if you're going to convert anything, convert it to ZCMD or YCMD.


Re: help in strcmp command - bugmenotlol - 31.10.2016

will all commands work if we use dcmd and strcmp together in a script ??


Re: help in strcmp command - Threshold - 31.10.2016

Well dcmd uses OnPlayerCommandText directly, so yes, you can. But again... I wouldn't recommend it. Chances are you're not going to listen to me anyway because you think it's much easier to just use dcmd, even though ZCMD is the easiest solution.