Command help..
#1

How can I go about making a command like:

/Enable Something 1, you can either enter 1 or 0 and it sets the value for "Something"

Something like:

pawn Код:
CMD:test(playerid, params[])
{
    if(isnull(params)) return 0;

    if(strcmp.. "something"..
    {
        if(isnull(what_here?)) return "Usage: /Test Something <0or1>"
        something = 1; or something = 0;
    }
}
Reply
#2

might need sscanf(my way).

pawn Код:
CMD:test(playerid, params[])
{
    if(isnull(params)) return 0;
    new Something[32];
    if(sscanf(params, "s[32]", Something)) return SendClientMessage(playerid, -1, "Usage: /Test [Something | Hello]");
    if(strcmp(Something, "Something", false) == 0)
    {
        new something;
        if(sscanf(params, "s[32]i", Something, something)) return SendClientMessage(playerid, -1, "Usage: /Test Something <[0 - 1]>");
    }
    if(strcmp(Something, "Hello", false) == 0)
    {
        new hello;
        if(sscanf(params, "s[32]i", Something, hello)) return SendClientMessage(playerid, -1, "Usage: /Test Hello <[0 - 1]>");
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by [L3th4l]
Посмотреть сообщение
How can I go about making a command like:

/Enable Something 1, you can either enter 1 or 0 and it sets the value for "Something"

Something like:

pawn Код:
CMD:test(playerid, params[])
{
    if(isnull(params)) return 0;

    if(strcmp.. "something"..
    {
        if(isnull(what_here?)) return "Usage: /Test Something <0or1>"
        something = 1; or something = 0;
    }
}
I dont know why you'd ever want to do something like this (perhaps im misunderstanding what you mean by "something"?). But i came up with an answer that should work for you.

Assuming we're on the same page, and you want to modify any variable in your script using a command, you'll have to use a function that relies on a physical name for dealing with variables. There are a ton of these types of functions out there (there are even 2 native ways to go about this!).
  • Pvars
  • Properties
  • Gvars (Gvar plugin)
  • Map (CSTL plugin)
Im going to use pvars in the example out of laziness. We dont have to check if they exist, or worry about deletion, so it makes the example a lot shorted and easier (though i suggest using GVars, as they arent bound by a playerid and support other sized arrays!). The implementation for all are very similar.

This example assumes you know and use sscanf (if you dont know it, tell me and i'll help...if you dont use it, shame on you!).

Код:
CMD:Test(playerid, params[])
{
    new
        str[52],
        val;

    if(!sscanf(params, "s[51]d", str, val))
    {
        SetPVarInt(playerid, str, val);
        return 1;
    }
    return 0;
}
This code was really just a quick example to show you HOW you could change variables while inside the game. When implementing for real world use, you should add a check to see if they're an admin (Or if the variable exists- if it doesnt, it will be created...not sure if you want that). Otherwise, if you DO use pvars for anything else, they can change your values. This includes admin level too if they could figure out the variable name :P.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)