Customcraft: Random Functions

Welcome to this week’s edition of Customcraft!  For you newcomers, this is a weekly column dedicated to item creation tips with the WoW RP add-on, Gryphonheart Items—or GHI for short.  This week’s feature are for those that want to add a bit of spice to life.  Want to create an item that—while it may have a chance of working, there’s also a possibility of having it backfire, or doing a completely different effect altogether?  Well friends, you’ve come to the right place, as we’ll be delving into the various random functions that GHI can offer!

GHI Creation Menu—Right Click Actions

When creating an item in GHI, there is already a feature built-in called Random Expressions (which is circled in a pink box above).

If you select that add it, you’ll be greeted with the following window:

customcraft02-randexpress

With this window, you’ll be able to make up to at least six different emotes and says.   If you’re looking to do something relatively simple such as emoting actions such having different things happening to your item (ie: it explodes, vanishes, morphing into strange, ethereal substances, etc. etc.) then you need not look further than this option.

However, its limitations with this feature is clear: it can only be used for emotes and speech.  What if you wanted to do something more complex such as… add a buff/debuff in there as well?  What about adding sounds effects?  Or even if you wanted to have some control on how “random” the actions are?  (Such as, you want a 60% chance of x happening, a 30% chance of y happening, and a 10% chance of z happening).  Good thing for us, that this is indeed very possible to do.  Although it requires you going into Script Editor to do so, it’s actually not very difficult at all.

The important thing to remember about LUA scripting, is that everything works in the form of “if, then” statements.  It basically works as so:

If x then
Action
elseif y then
Action
else
Action
end

Simple, isn’t it?  There’s a bit more of it such as setting the local parameters, but that’s how LUA scripting works in a nutshell.  I’ve found that writing out pseudo-script like that helps me with getting on the right track as far as coding goes.

Anyhoo, going back on topic now.  This is a random script code that I sort of whipped up quickly when helping someone on the GHI forums about a month ago.  But it can be easily modified to suit your needs.

local r = random(100);
if r <= 35 then
Emote(“successfully uses the %L!  Zap!”)
elseif r >=36 and r <=94 then
Emote(“tries to use the %L… and nothing happens!  D’oh!”)
else
Emote(“‘s %L explodes in a blaze of fire and smoke!  Oops.”)
end

What’s different here compared to what was done in the Random Expressions is that we have some control over the random factor.  There are three different outcomes in this script.  Basically, it’s a /random 100 and if the number winds up being 35 or below, then the user would see the first outcome (item use successful!).  If the number is equal or greater to 36 AND less or equal to 94, then the user would see the second outcome (nothing would happen).  If the number does not meet either of those criteria, then the user would see the last outcome (the item would backfire).

And yes, it’s possible to add other things in there as well.  Let’s modify this script a little to add in sound effect if the item is successful, and a sound effect + debuff when the item backfires.

local r = random(100);
if r <= 35 then
Emote(“successfully uses the %L!  Zap!”)
PlaySoundFile(“Sound\\Doodad\\ID_Forge_Zap02.wav”)
elseif r >=36 and r <=94 then
Emote(“tries to use the %L… and nothing happens!  D’oh!”)
else
Emote(“‘s %L explodes in a blaze of fire and smoke!  Oops.”)
PlaySoundFile(“Sound\\Doodad\\Hellfire_Raid_FX_Explosion02.wav”)
ApplyGHIBuff(“Kaboom!”,”Well, that didn’t work as planned…”,”Interface\\Icons\\INV_Gizmo_SuperSapperCharge”,0,”HARMFUL”,”PHYSICAL”,3600,0)
end

Now when it plays, there are accompanying sound effects for both successes and failures, as well as a debuff in result of the item exploding.  We’ll look more into buffs and debuffs in a future segment.

Hope you’ve enjoyed this segment of Customcraft!

Advertisements

~ by compassstudies on August 7, 2009.

3 Responses to “Customcraft: Random Functions”

  1. Wow, this stuff is really useful, I’m glad I found your blog!

  2. I am a new GHI user but I have been pouring the pilus forums for two days now. I know very little about code but am otherwise a quick learner.

    I am attempting to create a few ambiguous gizmos and gadgets that loop random sounds from a list of sounds I have already pre-selected. These items are for my engineer who I role play as a toymaker. Ideally, I want a continuous gear-turning sound in the background (I’m using the Add New Sound item for that one) and then have the item produce different random mechanical noises intermittently with each click. I don’t want the same noises every click; I want them selected from a bank in the script.

    As of this post, I have only been able to sequence the sounds with the delay feature to come in at certain times. But the sequence of the noises stays the same with each activation. How do I randomize the selection each time the item is right clicked?

    I also want there to be a duration of about a minute or two before the loop of random mechanical noises ends followed by a Confusion buff that the player receives, having been baffled by this ambiguous device. I read your post on delayed buff activation but couldn’t see instructions for buff delay anywhere in your tutorial page. I tried the built in delay function with a buff script, but it didn’t work.

    Thank you in advance for your time and attention to my inquiry!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: