Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- *
- * Command to create eq 'sets'
- *
- * 2003-Nov-13: Morpher, initial
- * 2004-Jul-05: Morpher, brief option
- *
- */
- #include <commands.h>
- #include <daemons.h>
- #include <std.h>
- inherit DAEMON;
- #define ARMOR_VARS
- #include <armor.h>
- #define LIMIT_EQ (50)
- #define LIMIT_SETS ( 5)
- int cmd_eqset(string str)
- {
- object plr;
- int i,j;
- string a1, a2, *ae, cmd, *ta, tmp;
- object *tao;
- mapping eqset;
- ae = keys(armor_expand);
- plr = this_player();
- if (plr -> query_ghost())
- {
- return notify_fail("Your ghostly hands just pass through the objects..\n");
- }
- if (!mapp(plr->query("cmd_eqset")))
- {
- plr->set("cmd_eqset", ([ "brief" : "off",
- "created" : time(),
- "sets" : ([]),
- "version" : 2 ]) );
- }
- eqset = plr->query("cmd_eqset");
- if (eqset["version"] == 1)
- {
- eqset["brief"] = "off";
- eqset["version"] = 2;
- plr->set("cmd_eqset", eqset);
- eqset = plr->query("cmd_eqset");
- }
- if (!stringp(str)) str = "list";
- if (sscanf(str,"%s %s %s",cmd,a1,a2) != 3) // lazy parsing(tm)
- { // should use get_args() parser but it would need tuning...
- a2 = "";
- if (sscanf(str,"%s %s",cmd,a1) != 2)
- {
- a1 = "";
- cmd = str;
- }
- }
- a1 = a1[0..31];
- switch( cmd )
- {
- case "add" :
- if (sizeof(a2))
- {
- if (!mapp(eqset["sets"][a1]))
- {
- if (sizeof(eqset["sets"]) < LIMIT_SETS)
- {
- eqset["sets"][a1] = ([]);
- tell(plr, "Eqset "+a1+" added.\n", MSG_COMMAND);
- } else {
- tell(plr, "You can only have "+LIMIT_SETS+" eqsets.\n", MSG_COMMAND);
- return 1;
- }
- }
- switch(a2)
- {
- case "all" :
- tao = items_all(plr);
- break;
- case "noeq":
- tao = items_inv(plr);
- break;
- case "eq" :
- tao = items_eq (plr);
- break;
- default:
- tao = ({ present(a2,plr) });
- tao -= ({ 0 });
- break;
- }
- if ((i = sizeof(tao)))
- {
- j = 0;
- while (i--)
- {
- if (sizeof(eqset["sets"][a1]) < LIMIT_EQ)
- {
- if (!tao[i]->query("no_save") && (tmp = tao[i]->query_save_data_id()) != "0-0")
- {
- if (!mapp(eqset["sets"][a1][tmp]))
- {
- eqset["sets"][a1][tmp] = ([ "short" : tao[i]->query_short() ]);
- tell(
- plr,
- sprintf("Added %s to eqset %s.\n",
- tao[i]->query_short(),
- a1),
- MSG_COMMAND);
- j = 1;
- }
- }
- } else {
- tell(plr, "Eqset "+a1+" is full.\n", MSG_COMMAND);
- }
- }
- plr->set("cmd_eqset", eqset);
- if (!j)
- {
- tell(plr, "No item found to add to eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- } else {
- tell(plr, "No item found to add to eqset "+a1+".\n", MSG_COMMAND);
- return 1;
- }
- }
- break;
- case "brief" :
- eqset["brief"] = eqset["brief"] == "on" ? "off" : "on";
- plr->set("cmd_eqset", eqset);
- switch ( eqset["brief"] )
- {
- case "on" : tell(plr, "Eqset brief mode on.\n" , MSG_COMMAND); break;
- case "off": tell(plr, "Eqset brief mode off.\n", MSG_COMMAND); break;
- }
- return 1;
- case "del" :
- case "delete" :
- if (sizeof(a2))
- {
- if (mapp(eqset["sets"][a1]))
- {
- if (a2 == "all")
- {
- map_delete(eqset["sets"],a1);
- tell(plr, "Eqset "+a1+" deleted.\n", MSG_COMMAND);
- plr->set("cmd_eqset", eqset);
- return 1;
- } else {
- if (present(a2,plr))
- {
- tmp = present(a2,plr)->query_save_data_id();
- if (mapp(eqset["sets"][a1][tmp]))
- {
- tell(plr, "Item "+eqset["sets"][a1][tmp]["short"]+" deleted from eqset "+a1+".\n", MSG_COMMAND);
- map_delete(eqset["sets"][a1],tmp);
- plr->set("cmd_eqset", eqset);
- } else {
- tell(plr, "Item "+a2+" is not in eqset "+a1+".\n", MSG_COMMAND);
- }
- } else {
- tell(plr, "No item found to delete from eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- return 1;
- }
- }
- break;
- case "wear" :
- if (sizeof(a1))
- {
- if (a2 != "noremove")
- {
- if (stringp(plr->query_temp("cmd_eqset")))
- {
- cmd_eqset("remove "+plr->query_temp("cmd_eqset"));
- }
- }
- if (mapp(eqset["sets"][a1]))
- {
- tao = map_array(
- keys(eqset["sets"][a1]),
- (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
- items_all(plr));
- tao -= ({ 0 });
- tao = sort_array (tao, (: member_array($1->query("type"),$(ae))-member_array($2->query("type"),$(ae)) :));
- tao = filter_array(tao, (: CMD_WEAR->cmd_wear($1,1,$2) :), plr); // hrr...
- if (sizeof(tao))
- {
- if (eqset["brief"] == "on")
- {
- tell(plr, "You wear eqset "+a1+".\n", MSG_COMMAND);
- } else {
- tell(plr, "You wear "+items_array_text(sort_array(tao->query_short(),1))+" (eqset "+a1+").\n", MSG_COMMAND);
- }
- } else {
- tell(plr, "No items worn from eqset "+a1+".\n", MSG_COMMAND);
- }
- plr->set_temp("cmd_eqset", a1);
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- break;
- case "rem" :
- case "remove" :
- if (sizeof(a1))
- {
- if (mapp(eqset["sets"][a1]))
- {
- tao = map_array(
- keys(eqset["sets"][a1]),
- (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
- items_all(plr));
- tao -= ({ 0 });
- tao = filter_array(tao, (: CMD_REMOVE->cmd_remove($1,1,$2) :), plr); // hrr...
- if (sizeof(tao))
- {
- if (eqset["brief"] == "on")
- {
- tell(plr, "You remove eqset "+a1+".\n", MSG_COMMAND);
- } else {
- tell(plr, "You remove "+items_array_text(sort_array(tao->query_short(),1))+". (eqset "+a1+").\n", MSG_COMMAND);
- }
- } else {
- tell(plr, "No items unworn from eqset "+a1+".\n", MSG_COMMAND);
- }
- plr->set_temp("cmd_eqset", 0);
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- break;
- case "view" :
- if (sizeof(a1))
- {
- if (mapp(eqset["sets"][a1]))
- {
- ta = map_array(
- keys(eqset["sets"][a1]),
- (: member_array($1,$2) == -1 ? $(eqset["sets"][a1])[$1]["short"] + " (?)" : $(eqset["sets"][a1])[$1]["short"] :),
- items_all(plr)->query_save_data_id());
- if (sizeof(ta))
- {
- tell(plr, "Eqset "+a1+" has following items: "+items_array_text(sort_array(ta,1))+".\n", MSG_COMMAND);
- } else {
- tell(plr, "There is no items in eqset "+a1+".\n", MSG_COMMAND);
- }
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- break;
- case "validate":
- if (sizeof(a1))
- {
- if (mapp(eqset["sets"][a1]))
- {
- ta = map_array(
- keys(eqset["sets"][a1]),
- (: member_array($1,$2) == -1 ? $1 : "" :),
- items_all(plr)->query_save_data_id());
- ta = filter_array(ta, (: sizeof($1) :) );
- if ( (i = sizeof(ta)) )
- {
- while (i--)
- {
- tell(plr, "Item "+eqset["sets"][a1][ta[i]]["short"]+" deleted from eqset "+a1+".\n", MSG_COMMAND);
- map_delete(eqset["sets"][a1],ta[i]);
- }
- plr->set("cmd_eqset", eqset);
- }
- tell (plr, "Eqset "+a1+" validated.\n", MSG_COMMAND);
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- break;
- case "keep" :
- if (sizeof(a1))
- {
- if (mapp(eqset["sets"][a1]))
- {
- tao = map_array(
- keys(eqset["sets"][a1]),
- (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
- items_all(plr));
- tao -= ({ 0 });
- if (sizeof(tao))
- {
- tao->set("keep",1);
- tell(plr, "You put "+items_array_text(sort_array(tao->query_short(),1))+" in keep (eqset "+a1+").\n", MSG_COMMAND);
- } else {
- tell(plr, "You have no items from eqset "+a1+".\n", MSG_COMMAND);
- }
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- break;
- case "nokeep" :
- if (sizeof(a1))
- {
- if (mapp(eqset["sets"][a1]))
- {
- tao = map_array(
- keys(eqset["sets"][a1]),
- (: member_array($1,$2->query_save_data_id()) != -1 ? $2[member_array($1,$2->query_save_data_id())] : 0 :),
- items_all(plr));
- tao -= ({ 0 });
- if (sizeof(tao))
- {
- tao->set("keep",0);
- tell(plr, "You remove "+items_array_text(sort_array(tao->query_short(),1))+" from keep (eqset "+a1+").\n", MSG_COMMAND);
- } else {
- tell(plr, "You have no items from eqset "+a1+".\n", MSG_COMMAND);
- }
- } else {
- tell(plr, "There is no eqset "+a1+".\n", MSG_COMMAND);
- }
- return 1;
- }
- break;
- case "loc" :
- case "location":
- // lets think about this later as there must be buggy containers...
- break;
- case "list" :
- ta = sort_array(keys(eqset["sets"]),-1);
- i = sizeof(ta);
- if (i)
- {
- tell(plr, "You have following eq sets defined:\n", MSG_COMMAND);
- while (i--)
- {
- tell(
- plr,
- sprintf(" %s with %d items.\n",
- ta[i],
- sizeof(eqset["sets"][ta[i]])));
- }
- } else {
- tell(plr, "No eqsets defined.\n", MSG_COMMAND);
- }
- return 1;
- break;
- }
- if (sizeof(a2))
- {
- tell(plr, "Command "+a1+" has no argument.\n", MSG_COMMAND);
- } else {
- tell(plr, "Required argument malformed or missing.\n", MSG_COMMAND);
- }
- return 1;
- }
- string help()
- {
- return @LT
- Command: eqset
- Usage:
- 1. eqset add <setname> <item>
- <setname> is any name you want to use to id the set (no spaces)
- <item> is either the name of an item to add to the set, or
- all - which adds all items you have
- eq - which adds all items you have equipped
- noeq - which adds all items in your inventory
- 2. eqset del <setname> <item>
- This deletes <item> from the given <setname>
- 3. eqset del <setname> all
- This deletes the entire eqset by the given name
- 4. eqset wear <setname>
- This will make you wear all the items in the eqset, it will remove
- the current eqset first.
- 5. eqset wear <setname> noremove
- This will make you wear the eqset given, but it will NOT remove the
- old set first.
- 6. eqset remove <setname>
- This will make you remove all items in the eqset
- 7. eqset list
- This will list the names of all eqsets you have created
- 8. eqset view <setname>
- This shows you what items are in the given eqset.
- 9. eqset validate <setname>
- Removes items you no longer have (carried) from set.
- 10. eqset keep <setname>
- Put items in eqset to keep.
- 11. eqset nokeep <setname>
- Remove items in eqset from keep.
- 12. eqset brief (toggle)
- Show minimal information when wearing/unwearing.
- Each player can define a maximum of 5 sets and each set can contain only
- 50 items. Note that added items are uniquely identified and thus even if
- you have bunch of 'identical' looking items this command will be able to
- differentiate them.
- LT;
- }
Advertisement
Add Comment
Please, Sign In to add comment