You're doing good for just learning to script, Bootlicker! At least you're not making many of the common mistakes, and you're using the commands properly.
What you need to work on now is the logic of the script. Remember that it's just a machine and it only does exactly what you tell it to, down to the "t". If you can imagine following the script, exactly the way the engine follows it, it helps to see where problems are.
Here's what you said the script should do:
Quote: "I want it so that when i enter a trigger zone and press enter a HUD pops up, then when I either leave that zone or press enter again the HUD disappears. Then for it to loop again incase I want to go back."
That's perfect! But, sadly, the engine can't read english!
I'll step through your description and write a script as I go, so you can see how to apply your english to a script.
Quote: "I want it so that when i enter a trigger zone and press enter a HUD pops up"
I'll borrow the HUD loading line from Blackfox's script, then we'll turn the above quote into a line of script!
:state=0:hudreset,hudx=80,hudy=79,hudimagefine=gamecore\huds\Purity\message.png,hudname=hudone,hudhide=1,hudmake=display,state=1
:state=1,plrwithinzone=1,scancodekeypressed=28:hudshow=hudone,state=2
The way you use states can be a little better, but so far you're doing good. Remember that it's not always necessary to use a state, and if you can avoid using a state while keeping good logic, you should do so.
Next line:
Quote: ", then when I either leave that zone or press enter again the HUD disappears."
This one will require a few lines, since you have two different things to check for (Leaving the zone and pressing the key again(Which will require two lines in itself))
:state=2,scancodekeypressed=0:state=3
:state=3,scancodekeypressed=28:hudfadeout=hudone,state=1
:plrwithinzone=0:hudfadeout=hudone,state=1
When the script reaches state 2, the hud is already shown, but we need to wait for the player to STOP pressing the key before we check if the key has been pressed again. So once "scancodekeypressed=0" happen, we go to state 3 and wait for the keypress to hide the HUD.
The last line takes care of itself and doesn't even need a state! If the player isn't in the zone, we fade out the HUD and go back to state 1. This should happen no matter WHAT state the script is in.
Quote: "Then for it to loop again incase I want to go back."
Well, this one is already taken care of! By going back to state 1 when we hide the HUD, it will "loop".
So, we end up with the following script!
;Artificial Intelligence Script
;Header
desc = Hud pops up
;Triggers
:state=0:hudreset,hudx=80,hudy=79,hudimagefine=gamecore\huds\Purity\message.png,hudname=hudone,hudhide=1,hudmake=display,state=1
:state=1,plrwithinzone=1,scancodekeypressed=28:hudshow=hudone,state=2
:state=2,scancodekeypressed=0:state=3
:state=3,scancodekeypressed=28:hudfadeout=hudone,state=1
:plrwithinzone=0:hudfadeout=hudone,state=1
;End of Script
I hope this helps you to better learn scripting.
The one and only,
Only those who sow the seeds of their desires will reap their benefits later.
However, I have seeds of my own to tend to. I don't have time to be someone else's watering can.