Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Zener
Wanderer


Joined: 31 May 2004
Posts: 54
Location: USA

PostPosted: Fri Jul 02, 2004 2:43 pm   

Script Help
 
I am seeking to write up a script, or of course use something someone might happen to post.

What I want is a #VAR (Items, for example) that contains 40-60 "items" which can be added/removed by typing ADDITEM itemname and REMITEM itemname. I also want to be able to "pick" or "draw" an item from that list by typing DRAWITEM or PICKITEM which will then randomly pick 1 item from the @ITEMS list and remove it from the list. I do want to be able to have multiple instances of an item in the list, but I don't want all 3 removed if 1 is picked from the list.

Also, is there a way to, I guess I could say "shuffle", the @ITEMS list and then "pick" the items in order by typing DRAWITEM or PICKITEM.

This may seem confusing but what I want is something like this.

@ITEM (Contains)

Emaculate Long Sword
Ice Shard
Ice Shard (Notice repeat)
Ice Shard (Notice repeat)
Balanced Short Sword
Ring of Luck
Ring of Luck (Notice repeat)
Sturdy Helm
Boots of Stealth
Boots of Stealth (Notice repeat)
Boots of Stealth (Notice repeat)
A Cotton Tissue
item
item
item
item

ect... up to 60 items.

Then I could simply type ADDITEM "Bracer of Immunity" and it would place Bracer of Immunity at the bottom of the list in @ITEMS.

Now this is where it might get hard, or not possible. I would like to be able to "mix up" the items, maybe by typing in "jumblelist" or something easy. Then the list would be completely randomized.

Then I could type PICKITEM or DRAWITEM and it would #SHOW the 1st item in the @ITEMS list.

What I am trying to do is make a sort of game where people battle using items that they can collect or buy from me, of course I will have limitations and rules for it. But yeah I wont give too much away.

Any help appreciated, any more info needed, just ask.

~Zener
Reply with quote
Zener
Wanderer


Joined: 31 May 2004
Posts: 54
Location: USA

PostPosted: Fri Jul 02, 2004 2:49 pm   
 
Oh by the way, for when I type ADDITEM "itemname", I'd like it to #ECHO You remove "itemname" from the list. Same for REMITEM "itemname".

Also, when I type PICKITEM or DRAWITEM it #SHOW You pick "itemname". and then emote has picked an item from their list.

I will be probably be needing more help later if I can get this working with things like playing the items, hopefully not though!

Thanks again!

~Zener
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Fri Jul 02, 2004 4:19 pm   
 
This is pretty much untested, but I think it'll do just what you want it to. By using the %delitem and %additem functions instead of their respective commands, duplicates are allowed and treated seperately. I don't know of any way to jumble up a list, but it's easy to randomly select one of the items in your list, which is what the drawitem alias does.

Note that in the "remitem" alias, if you don't give an argument (i.e. you just type "remitem"), then it'll remove the last randomly choses item. Also, if you try to remove an item that's not on the list, it'll kick out an error.

quote:

#CLASS {Items}
#VAR Items {}
#ALIAS Additem {#NOOP %additem(%-1,@Items);#SH %-1 added to items list.}
#ALIAS Remitem {#IF (!%1) {%delitem(%item(@Items,@Drawrand),@Items)} {#IF (%ismember(%-1,@Items)) {#NOOP %delitem(%-1,@Items);#SH %-1 removed from items list.} {#SH Error! %-1 is not in your items list!}}}
#VAR Drawrand {}
#ALIAS Drawitem {#VAR Drawrand %rand(1,%numitems(@Items));#SH You pick %item(@Items,@Drawrand).;emote has picked an item from his list.}
#CLASS 0

Reply with quote
Zener
Wanderer


Joined: 31 May 2004
Posts: 54
Location: USA

PostPosted: Fri Jul 02, 2004 4:57 pm   
 
Ok that's pretty nifty!

One problem, I "need" to be able to jumble up the list as well as keep the list in a certain order.

@ITEMS

ItemA(Copy1)
ItemA(Copy2)
ItemB
ItemC(Copy1)
ItemC(Copy2)
ItemC(Copy3)
ItemD
ItemE
ItemF
ItemG(Copy1)
ItemG(Copy2)
ItemG(Copy3)
ItemH(Copy1)
ItemH(Copy2)

-- Type: Jumble --

@ITEMS

ItemH(Copy2)
ItemC(Copy2)
ItemA(Copy1)
ItemC(Copy1)
ItemE
ItemH(Copy1)
ItemF
ItemG(Copy1)
ItemB
ItemA(Copy2)
ItemC(Copy3)
ItemG(Copy2)
ItemD
ItemG(Copy3)

-- Type: PICKITEM -- (After "Jumble")

#SHOW You pick ItemH (Then ItemH is removed from the list, but not the 2nd ItemH)

-- Type: PICKITEM -- (After Picking ItemH)

#SHOW You pick ItemC (Then ItemC is removed from the list, but not the 2nd or 3rd ItemC)



If this is possible, it would be great if someone can show me how.

~Zener
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jul 02, 2004 5:32 pm   
 
%additem and %delitem merely return a value, they don't actually alter the variable. It must be combined with the #VARIABLE command to actually change the variable.

You can add any #SAY, #SHOW, and #ECHO commands and any emotes you want yourself. I've included the first one you requested as an example.
quote:
Oh by the way, for when I type ADDITEM "itemname", I'd like it to #ECHO You remove "itemname" from the list.

#AL ADDITEM {#VAR ITEMS {%additem("%-1", @ITEMS)};#ECHO You remove ~"%-1~" from the list.}
#AL REMITEM {#VAR ITEMS {%delitem("%-1", @ITEMS)}}
#AL PICKITEM {#VAR pickitem {%item( @ITEMS, %1)};#DELN ITEMS %1}
#AL DRAWITEM {#VAR drawitem {%item( @ITEMS, %random( 1, %numitems( @ITEMS)))};#VAR ITEMS {%delitem( @drawitem, @ITEMS)}}
#AL SHUFFLEITEM {#VAR items2 {};#WHILE %numitems( @ITEMS) {DRAWITEM;#VAR items2 {%additem( @drawitem, @items2)}};#VAR ITEMS {@items2}}

Usage:
ADDITEM Bracer of Immunity
REMITEM Ring of Luck
PICKITEM 7
DRAWITEM
SHUFFLEITEM

The first two require item names, the third requires a number, the last two should be used alone. I've made no effort to foolproof them.

EDIT: Corrected placement of } in PICKITEM.
Reply with quote
Zener
Wanderer


Joined: 31 May 2004
Posts: 54
Location: USA

PostPosted: Fri Jul 02, 2004 5:58 pm   
 
quote:
Originally posted by LightBulb

%additem and %delitem merely return a value, they don't actually alter the variable. It must be combined with the #VARIABLE command to actually change the variable.

You can add any #SAY, #SHOW, and #ECHO commands and any emotes you want yourself. I've included the first one you requested as an example.
quote:
Oh by the way, for when I type ADDITEM "itemname", I'd like it to #ECHO You remove "itemname" from the list.

#AL ADDITEM {#VAR ITEMS {%additem("%-1", @ITEMS)};#ECHO You remove ~"%-1~" from the list.}
#AL REMITEM {#VAR ITEMS {%delitem("%-1", @ITEMS)}}
#AL PICKITEM {#VAR pickitem {%item( @ITEMS, %1);#DELN ITEMS %1}}
#AL DRAWITEM {#VAR drawitem {%item( @ITEMS, %random( 1, %numitems( @ITEMS)))};#VAR ITEMS {%delitem( @drawitem, @ITEMS)}}
#AL SHUFFLEITEM {#VAR items2 {};#WHILE %numitems( @ITEMS) {DRAWITEM;#VAR items2 {%additem( @drawitem, @items2)}};#VAR ITEMS {@items2}}

Usage:
ADDITEM Bracer of Immunity
REMITEM Ring of Luck
PICKITEM 7
DRAWITEM
SHUFFLEITEM

The first two require item names, the third requires a number, the last two should be used alone. I've made no effort to foolproof them.



I really need to learn what all this means.

Couple quick questions.

Could this be changed to allow PICKITEM "Bracer of Immunity" instead of specifying a number?

quote:
#AL PICKITEM {#VAR pickitem {%item( @ITEMS, %1);#DELN ITEMS %1}}



What exactly does this do?

quote:
#AL DRAWITEM {#VAR drawitem {%item( @ITEMS, %random( 1, %numitems( @ITEMS)))};#VAR ITEMS {%delitem( @drawitem, @ITEMS)}}


Will this always draw the 1st item on the list?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jul 02, 2004 10:49 pm   
 
"Could this be changed to allow PICKITEM "Bracer of Immunity" instead of specifying a number?" Yes. Quite easily.
#AL PICKITEM {#VAR pickitem {%-1};REMITEM %-1}

"Will this (DRAWITEM) always draw the 1st item on the list?" No.
It will choose one item at random.
Reply with quote
Zener
Wanderer


Joined: 31 May 2004
Posts: 54
Location: USA

PostPosted: Sat Jul 03, 2004 2:06 am   
 
Ok, is it possible to make it always choose the top item in the list? The way I am trying to get this to work is sort of like playing a card game or something where you have your own "decks", in this case a set of items, which would be in a list and that whenever a player types DRAWITEM they always draw the next item in their list, not just a random item. Since I will have items that allow a player to choose certain types or even specific items from their list, via PICKITEM.

By the way, so far testing what you posted before it's working fairly nice at the moment, except for the drawing a random item from the list when using DRAWITEM.

~Zener
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jul 03, 2004 6:30 am   
 
You asked for an aiias which would draw items at random. Don't complain about getting it.
"by typing DRAWITEM or PICKITEM which will then randomly pick 1 item from the @ITEMS list and remove it from the list"
The SHUFFLEITEM alias relies on DRAWITEM, so if you change DRAWITEM you will have to rewrite SHUFFLEITEM.

I already gave you an alias which would allow you to pick any item you wanted by number. You didn't like it and asked me to change it so you could pick items by name instead. I did that for you. Now you are unhappy about that and want an alias which can pick an item by number, but you want the number to always be 1. A moment's thought should have been enough for you to figure that out for yourself! Just change the original version of PICKITEM to use 1 instead of %1 and think up another alias name so you could have both versions (PICKNAME2 if you can't think of anything better).
Reply with quote
Zener
Wanderer


Joined: 31 May 2004
Posts: 54
Location: USA

PostPosted: Sun Jul 04, 2004 4:01 am   
 
quote:
Originally posted by LightBulb

You asked for an aiias which would draw items at random. Don't complain about getting it.
"by typing DRAWITEM or PICKITEM which will then randomly pick 1 item from the @ITEMS list and remove it from the list"
The SHUFFLEITEM alias relies on DRAWITEM, so if you change DRAWITEM you will have to rewrite SHUFFLEITEM.

I already gave you an alias which would allow you to pick any item you wanted by number. You didn't like it and asked me to change it so you could pick items by name instead. I did that for you. Now you are unhappy about that and want an alias which can pick an item by number, but you want the number to always be 1. A moment's thought should have been enough for you to figure that out for yourself! Just change the original version of PICKITEM to use 1 instead of %1 and think up another alias name so you could have both versions (PICKNAME2 if you can't think of anything better).



[8D]

LightBulb, let me start off by apologizing heh, when I get home from work I check this forum and I am extremely exhausted. I hadn't had much sleep recently so I am not really sure what I was thinking when I replied to your posts...but I see what you mean. Very Happy

By the way, I did type this in my first post.

quote:
Also, is there a way to, I guess I could say "shuffle", the @ITEMS list and then "pick" the items in order by typing DRAWITEM or PICKITEM.


Because I am willing to just deal with DRAWITEM/PICKITEM choosing a random item. But the way I want my game to work, I would prefer DRAWITEM to draw the 1st item in the list.

Anyways, thank you very much. It works beautifully.

~Zener
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net