This will be simple enough, but give you an idea of how to find and use items, and how to use them when a condition exists.
Here's how I go about writing scripts.
1 - What do I want to do
I list out the general overview of what I want to do. Just write it out.
I want to drink a cure potion whenever I get poisoned.
2 - Start to define what needs to happen, being a little more specific then the overview.
I want to monitor my status
If I get poisoned
Look for a cure potion
if it's found - drink it
if it's not found - stop the script
3 - Gather any information you might need.
Cure potion item type = NUF
4 - Start writing
;=================================================================
; Script Name: Cerveza's Cure Pot Drinker
; Author: Cerveza
; Version: 1.0
; Shard OSI / FS: OSI / FS OK
; Revision Date: 2/24/2009
; Purpose: Drink Cure Potion when poisoned
; Globals: None
;=================================================================
SUO:
repeat
if C in #charStatus
{
findItem NUF C_ , #backpackID
if #findKind = -1
halt
set #lobjectID #findID
set #ltargetKind 1
event macro 17 0
wait 5
}
until #CharGhost = YES
while #CharGhost = YES
wait 0
GoTo SUO
Now lets look at whats actually happening in this script.
If you read the
Basic Script Flow then you recognize the main loop "wrapper". If not then you really should read that before continuing here.
Line by line:
if C in #charStatus
#charStatus checks to see what status the char is in. C is for poisoned.
findItem NUF C_ , #backpackID
findItem will look for NUF (cure potion) in a container (C_ , ) with the ID of backpack (
#backpckID)
if #findKind = -1
if checks a condition of the last item found, which is NUF for cure potions, the attribute -1 indicates NO items were found.
halt
halt stops the script. Since this line immediately follows the
if line, it's only executed when the
if line is a true statement. So if you don't have any cure potions in your backpack (searched during the IF line) then this line is executed and the script stops. If a cure potion is found, the script skips this line and continues.
set #lobjectID #findID
set allows you to "push" specific information or create storage variables with information. In this case we want to make
#lobjectID the ID of the cure potion we found earlier. When we found it, it stored in
#findIDset #ltargetKind 1
This will set the
#ltargetKind to an object. THIS LINE IS VERY IMPORTANT. When you are telling the script how to deal with items, this HAS to be set. It's common to miss this and have scripts act bonkey.
event macro 17 0
event macro is a way of performing in game macros. In this case 17 0 means USE LAST ITEM, which we already set to the cure potion we found.
wait 5
wait will wait for 1/4 second before continuing. Another area that can cause scripts to fail is not putting waits, or putting wrong waits in scripts. Some things MUST have a wait or they will fail (dragging and dropping for example) and others MUST have a wait or they will cycle around too quickly and try to do the action twice (like this script, you drink a cure and before you are cured the script sees you poisoned and tries to drink another cure before the first one finishes it's action). Thats why we put in waits. As a general rule, make your waits bigger then you think you'll need. You can always trim them down to speed up the script, but troubleshooting a 1000 line script that's flakey because of waits that aren't long enough will make you quickly hate life.
So there you have it.
Check to see if your poisoned
If you get poisoned - Look for a cure potion
If you don't find one - QUIT
Set the Cure Potion as Last Item (because to get here you MUST have found one)
Set the Last Item type to Object
Use Last Item
Wait a bit to make sure you don't drink 2
There's your Drink Cure Pot script.