SA-MP Forums Archive
Some problems. - 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: Some problems. (/showthread.php?tid=298428)



Some problems. - nogh445 - 20.11.2011

I'm working on a new script and I have some very simple cmds in like /ak, /deagle, /chainsaw, etc.

Now I get in game and this is what happens:






this is the script part:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/ak", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,30,10000);
        return 1;
    }
    if (strcmp("/m4", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,31,10000);
        return 1;
    }
    if (strcmp("/deagle", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,24,10000);
        return 1;
    }
    if (strcmp("/spas", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,27,10000);
        return 1;
    }
    if (strcmp("/chainsaw", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,9,1);
        return 1;
    }
    if (strcmp("/kill", cmdtext, true, 10) == 0)
    {
        SetPlayerHealth(playerid, 0);
        return 1;
    }
    if (strcmp("/sniper", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,34,10000);
        return 1;
    }
    if (strcmp("/abcdefghijklmnopqrstuvwxyz", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,38,10000);
        return 1;
    }
    if (strcmp("/airportdm", cmdtext, true, 10) == 0)
    {
		SetPlayerPos(playerid,1921.8000488281,-2292.6999511719,15);
        return 1;
    }
    if (strcmp("/9mm", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,22,10000);
        return 1;
    }
    if (strcmp("/shotty", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,25,10000);
        return 1;
    }
    if (strcmp("/mp5", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,29,10000);
        return 1;
    }
    if (strcmp("/rifle", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,33,10000);
        return 1;
    }
    return 0;
}
None of these work and there is no errors in pawno.


Re: Some problems. - Tanush123 - 20.11.2011

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/ak", cmdtext, true, 2) == 0)
    {
        GivePlayerWeapon(playerid,30,10000);
        return 1;
    }
    if (strcmp("/m4", cmdtext, true, 2) == 0)
    {
        GivePlayerWeapon(playerid,31,10000);
        return 1;
    }
    if (strcmp("/deagle", cmdtext, true, 6) == 0)
    {
        GivePlayerWeapon(playerid,24,10000);
        return 1;
    }
    if (strcmp("/spas", cmdtext, true, 4) == 0)
    {
        GivePlayerWeapon(playerid,27,10000);
        return 1;
    }
    if (strcmp("/chainsaw", cmdtext, true, 8) == 0)
    {
        GivePlayerWeapon(playerid,9,1);
        return 1;
    }
    if (strcmp("/kill", cmdtext, true, 4) == 0)
    {
        SetPlayerHealth(playerid, 0);
        return 1;
    }
    if (strcmp("/sniper", cmdtext, true, 6) == 0)
    {
        GivePlayerWeapon(playerid,34,10000);
        return 1;
    }
    if (strcmp("/abcdefghijklmnopqrstuvwxyz", cmdtext, true, 26) == 0)
    {
        GivePlayerWeapon(playerid,38,10000);
        return 1;
    }
    if (strcmp("/airportdm", cmdtext, true, 9) == 0)
    {
        SetPlayerPos(playerid,1921.8000488281,-2292.6999511719,15);
        return 1;
    }
    if (strcmp("/9mm", cmdtext, true, 3) == 0)
    {
        GivePlayerWeapon(playerid,22,10000);
        return 1;
    }
    if (strcmp("/shotty", cmdtext, true, 6) == 0)
    {
        GivePlayerWeapon(playerid,25,10000);
        return 1;
    }
    if (strcmp("/mp5", cmdtext, true, 3) == 0)
    {
        GivePlayerWeapon(playerid,29,10000);
        return 1;
    }
    if (strcmp("/rifle", cmdtext, true, 5) == 0)
    {
        GivePlayerWeapon(playerid,33,10000);
        return 1;
    }
    return 0;
}



Re: Some problems. - nogh445 - 20.11.2011

Hmm. Didn't seem to work. Could it be because of includes at the top?

I have one zcmd cmd and it works


Код:
COMMAND:v(playerid, params[])
{
    new vehicleid, color1, color2;
    if(!sscanf(params, "iii", vehicleid, color1, color2))
    {
        new vin;
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        vin=CreateVehicle(vehicleid, x, y, z, 0.0, color1, color2, -1);
        PutPlayerInVehicle(playerid, vin, 0);
    }else{
        SendClientMessage(playerid, COLOR_GREY, "ERROR: This command requires: /v [vehicleid][color1][color2]");
    }
    return 1;
}



Re: Some problems. - SmiT - 20.11.2011

You can't use zcmd like that with onplayercommandtext. However - https://sampforum.blast.hk/showthread.php?tid=276063


Re: Some problems. - nogh445 - 20.11.2011

The zcmd is at the bottom of my script. It is not near the OnPlayerCommandText


Re: Some problems. - Tanush123 - 20.11.2011

Wait nogh you could convert your strcmp cmds to zcmd because zcmd is more easier than strcmp


Re: Some problems. - Kostas' - 20.11.2011

A big mistake that I have seen thousand times.
Many people use it like this
pawn Код:
if (strcmp("/command", cmdtext, true, 10) == 0)
in many commands.
For example:
pawn Код:
if (strcmp("/ak", cmdtext, true, 10) == 0)

// Or

if (strcmp("/ak", cmdtext, true, 2) == 0)
Isn't 2 or 10. It's
pawn Код:
if (strcmp("/ak", cmdtext, true, 3) == 0)
".." / >1 || a >2 || k >3


Re: Some problems. - nogh445 - 20.11.2011

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
Wait nogh you could convert your strcmp cmds to zcmd because zcmd is more easier than strcmp
Could you show me how to do it. Like do the /ak one so i can see how it is done and then i can convert all of them.


Re: Some problems. - SmiT - 20.11.2011

Quote:
Originally Posted by nogh445
Посмотреть сообщение
Could you show me how to do it. Like do the /ak one so i can see how it is done and then i can convert all of them.
pawn Код:
if (strcmp("/ak", cmdtext, true, 2) == 0)
    {
        GivePlayerWeapon(playerid,30,10000);
        return 1;
    }
Would be:

pawn Код:
CMD:ak(playerid, params[])
{
    if ( isnull ( params ) ) GivePlayerWeapon( playerid, 30, 10000 );
    return 1;
}



Re: Some problems. - Tanush123 - 20.11.2011

Quote:
Originally Posted by SmiT
Посмотреть сообщение
pawn Код:
if (strcmp("/ak", cmdtext, true, 2) == 0)
    {
        GivePlayerWeapon(playerid,30,10000);
        return 1;
    }
Would be:

pawn Код:
CMD:ak(playerid, params[])
{
    if ( isnull ( params ) ) GivePlayerWeapon( playerid, 30, 10000 );
    return 1;
}
Well a easy way would be
pawn Код:
CMD:ak(playerid, params[])
{
    GivePlayerWeapon( playerid, 30, 10000 );
    return 1;
}