A good way to sort and present commands...
#9

It would be cool to start with generic verbs, such as "give, set, take, add, remove, ..".

The /give command, for example, could support various sorts of arguments:
  • /give <who> <what>
  • /give <id/name> <what>, <what>, ..
  • /give slice $200
  • /give slice infernus
  • /give slice hp, armour, deagle, grenade, $20000
Same with /set:
  • /set slice hp 200
  • /set slice armour 50
  • /set slice ammo mp5 5000
  • /set slice name slice9000
Optionally, without a player:
  • /set weather 20
  • /set gravity 0.06
I suppose you could have a generic function detecting what, for example:
(disclaimer: untested code)
pawn Code:
enum E_THINGS_TYPES {
    THING_TYPE_WEAPON,
    THING_TYPE_MONEY,
    THING_TYPE_VEHICLE,
    THING_TYPE_HEALTH,
    THING_TYPE_ARMOUR,
    THING_TYPE_JETPACK
};

stock GetThingFromString(const input[], &type, &thing) {
    new id;
   
    if (input[0] == '$') {
        type = THING_TYPE_MONEY;
        thing = strval(input[1]);
    } else if (!strcmp(input, "health")) {
        type = THING_TYPE_HEALTH;
        thing = strval(input[6]);
    } else if (!strcmp(input, "armour")) {
        type = THING_TYPE_ARMOUR;
        thing = strval(input[6]);
    } else if (!strcmp(input, "jetpack")) {
        type = THING_TYPE_JETPACK;
    } else if (GetWeaponIdFromString(input, id)) {
        type = THING_TYPE_WEAPON
        thing = id;
    } else if (GetVehicleIdFromString(input, id)) {
        type = THING_TYPE_VEHICLE
        thing = id;
    } else {
        // failed
        return 0;
    }
   
    // success
    return 1;
}

stock GivePlayerThing(type, thing) {
    switch (type) {
        case THING_TYPE_HEALTH: {
            SetPlayerHealth(playerid, float(thing));
        }
       
        // etc..
    }
}

// Usage:
new type, thing;

if (GetThingFromString(input, type, thing)) {
    switch (type) {
        // prevent some things
        // the best way is probably the other way around - only allow certain things
        case THING_TYPE_VEHICLE: {
            // ERROR: you're not allowed to spawn a vehicle
        }
       
        default: {
            GivePlayerThing(playerid, type, thing);
        }
    }
}
Reply


Messages In This Thread
A good way to sort and present commands... - by Scenario - 30.07.2013, 04:02
Re: A good way to sort and present commands... - by JimmyCh - 30.07.2013, 11:44
Re: A good way to sort and present commands... - by Vince - 30.07.2013, 12:38
Re: A good way to sort and present commands... - by Scenario - 30.07.2013, 15:04
Re: A good way to sort and present commands... - by MP2 - 30.07.2013, 15:47
Re: A good way to sort and present commands... - by Kar - 30.07.2013, 16:25
Re: A good way to sort and present commands... - by Vince - 30.07.2013, 16:30
Re: A good way to sort and present commands... - by Scenario - 30.07.2013, 17:03
Re: A good way to sort and present commands... - by Slice - 05.08.2013, 09:10
Re: A good way to sort and present commands... - by Slice - 05.08.2013, 12:35
Re: A good way to sort and present commands... - by legodude - 06.08.2013, 09:55
Re: A good way to sort and present commands... - by Slice - 06.08.2013, 10:05
Re: A good way to sort and present commands... - by RealCop228 - 06.08.2013, 15:07
Re: A good way to sort and present commands... - by Slice - 06.08.2013, 16:59
Re: A good way to sort and present commands... - by RealCop228 - 06.08.2013, 17:09
Re: A good way to sort and present commands... - by [XST]O_x - 06.08.2013, 20:11
Re: A good way to sort and present commands... - by Macluawn - 06.08.2013, 20:24
Re: A good way to sort and present commands... - by Lorenc_ - 09.08.2013, 07:43
Re: A good way to sort and present commands... - by PinkFloydLover - 10.01.2014, 07:01

Forum Jump:


Users browsing this thread: 6 Guest(s)