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
adamwalker
Apprentice


Joined: 12 Mar 2005
Posts: 195

PostPosted: Mon Jul 25, 2005 3:34 pm   

team attacking and variables, and %item
 
Hey, was wondering if anyone could help with this problem..

I have a variable that lists the animals following me (@animalentorage) which can have even upto 30 entries.

and an alias that orders those animals (animalattack)

often I want to order these animals at multiple people, not just one target. So i have a variable that looks like this


ORDER %item( @animalentorage, 1) ATTACK @TAR1
ORDER %item( @animalentorage, 2) ATTACK @TAR2
ORDER %item( @animalentorage, 3) ATTACK @TAR3
ORDER %item( @animalentorage, 4) ATTACK @TAR1
ORDER %item( @animalentorage, 5) ATTACK @TAR2
ORDER %item( @animalentorage, 6) ATTACK @TAR3
etc all the way upto 30 entries

this basically makes it so that tar1,2,3 get attacked by all the animals that follow me

but as you can see this is very messy, is there a way to reduce this and make it a bit less ... well... long!

and another problem is that even if i only have 4 animals it does the orders upto 30 which can get spammy..... so i want it to stop ordering once it reaches the end of @animalentorage

thanks

thanks[/code]
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Mon Jul 25, 2005 5:47 pm   
 
I've given it a bash...

I'm going to name the targets as target1, target2, target3 etc, just for simplicity
I've introduced a 'targetcount' variable, but removed the multiple target variables you've got at the moment
Code:
targetcount = 1
targets = target1|target2|target3
animalentourage = spider|mouse|cat|dog|pony|horse|wyvern|dragon
#alias animalattack {#forall {@animalentourage} {#if (@targetcount > %numitems(@targets)) {targetcount = 1};order %i attack %item(@targets,@targetcount);#add targetcount (1)};targetcount = 1}

When you type animalattack it'll send

order spider attack target1
order mouse attack target2
order cat attack target3
order dog attack target1
order pony attack target2
order horse attack target3
order wyvern attack target1
order dragon attack target2

This should be good for any number of targets (all listed in @targets as a stringlist) and any number of animals (as listed in @animalentourage)

Hope that's what you're after
Reply with quote
adamwalker
Apprentice


Joined: 12 Mar 2005
Posts: 195

PostPosted: Mon Jul 25, 2005 7:10 pm   
 
that works so well! ive modified it slightly to suit what i want. but its amazing! thankyou so much!!

one small last problem i have...


alias called tt

#var targets {}
#addi targets %1
#addi targets %2
#addi targets %3
#addi targets %4
#addi targets %5
#addi targets %6
#say Your targets are now @targets

so i can enter

TT joe rob bob tom
which makes @targets = joe|rob|bob|tom

but of course cos there are 6 #additems up there it actually becomes

@targets = joe|rob|bob|tom|

which means theres a blank entry at the end

so every 5th order %i attack will not have a target

any idea how to remove the blank space or prevent it?
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Mon Jul 25, 2005 8:08 pm   
 
Code:

#ALIAS tt {targets = %subregex( %trim( %-1), "\s+", "|")}


Trims any trailing spaces off the end, and converts any remaining spaces into a |, thus separating them for the stringlist. the subregex matches multiple spaces so it'll stop you getting empty entries anywhere.
Removes the limit to the number of targets too, and tidies it up a bit ;)
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
adamwalker
Apprentice


Joined: 12 Mar 2005
Posts: 195

PostPosted: Mon Jul 25, 2005 8:23 pm   
 
once again you have come up trumps with a great answer!

thanks again Guinn!
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Mon Jul 25, 2005 8:26 pm   
 
You're welcome. Was one of those ones I figured I might be able to use in future, so wanted to see if I could do it ;)
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
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