Simple command, DCMD

Simple dcmd command

DCMD is a fast command processor, and if favored because it is very easy to use, well atleast thats what i think :)

First off you need to define DCMD because it is not sa-mp made it was made by "", so above "main()" in your script add this

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

Now this is slightly different than normal commands, so i will show you how to make a /kill command. Under Onplayercommandtext add this

dcmd(kill,4, cmdtext);

All you need to change in this for any other command is the "kill" and the length, in this case "4".

So after you have done that your onplayercommandtext will look like this…

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(kick,4, cmdtext);
    return 0;
}

Pretty simple huh? well next thing is the actual command, this is done like this…

dcmd_kill(playerid, params[]) // just change "kill" to whatever you put for the first parameter in the onplayercommandtext bit
{
     #pragma unused params // Just tells the compiler that the params (parameters) is not used, i.e. in a /kill [ID] command you would remove this
     SetPlayerHealth(playerid,0.0); // kills em!
    return 1;
}

Put that anywhere under main() in your script, it is best to put them under onplayercommandtext in my oppinon.

So now my whole script looks like this

#include <a_samp>

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(kill,4, cmdtext);
    return 0;
}

dcmd_kill(playerid, params[])
{
     #pragma unused params
     SetPlayerHealth(playerid,0.0);
    return 1;
}

Now go and test it. The end.


Back | Home