05.08.2013, 09:10
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:
(disclaimer: untested code)
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
- /set slice hp 200
- /set slice armour 50
- /set slice ammo mp5 5000
- /set slice name slice9000
- /set weather 20
- /set gravity 0.06
(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);
}
}
}