Jump to content

Do Once script


yetibear

Recommended Posts

Hi yall

 

Trying to get a script to run once,

 

Have a staffing ledger in my dwelling mod to hire staff

 

Hiring them works, taking the gold from the inventory works. But if you click again it removes the money again.

 

How do I stop it from happening or remove the option from the ledger after hiring those particular members of staff.

Have put the script below. if anyone can help I really would appreciate it. Its the last bug I've got and the mod has taken months to make.

 

Scriptname KarackStaffLedger extends ObjectReference

int Function GetItemCount(form akItem) native
Function RemoveItem(Form akitemToRemove, int aicount = 1, bool abSilent = false, ObjectReference akOtherContainer = None) native

Message property MyMessage Auto
MiscObject property Gold001 auto

Actor property DayInt auto
Actor property NightInt auto
Actor property Jailor auto

Actor property DayOut auto
Actor property NightOut auto
Actor property Ranger auto

Actor property Librarian auto
Actor property Runemaster auto
Actor property Herbalist auto
Actor property Smith auto

Actor property Farmer auto
Actor property Animalhandler auto
Actor property Runemage auto

 

Event OnActivate(ObjectReference akActionRef)
Menu()
EndEvent

 

Function menu(int aiButton = 0)
aiButton = MyMessage.show()

If aiButton == 0

ElseIf aiButton == 1 ;internal guards
If (game.GetPlayer().GetItemCount(gold001) >= 1500)
game.GetPlayer().RemoveItem(gold001, 1500)
DayInt.enable()
NightInt.enable()
Jailor.enable()
ElseIf debug.messagebox ("You need 1500 gold to hire these staff members")
EndIf

ElseIf aiButton == 2 ;External guards
If (game.GetPlayer().GetItemCount(gold001) >= 2000)
game.GetPlayer().RemoveItem(gold001, 2000)
DayOut.enable()
NightOut.enable()
Ranger.enable()
ElseIf debug.messagebox ("You need 2000 gold to hire these staff members")
EndIf

ElseIf aiButton == 3 ;Merchants
If (game.GetPlayer().GetItemCount(gold001) >= 3500)
game.GetPlayer().RemoveItem(gold001, 3500)
Librarian.enable()
Runemaster.enable()
Herbalist.enable()
Smith.enable()
ElseIf debug.messagebox ("You need 3500 gold to hire these staff members")
EndIf

Elseif aibutton == 4 ;Aids
If (game.GetPlayer().GetItemCount(gold001) >= 2500)
game.GetPlayer().RemoveItem(gold001, 2500)
Farmer.enable()
Animalhandler.enable()
Runemage.enable()
ElseIf debug.messagebox ("You need 2500 gold to hire these staff members")
EndIf
EndIf

Endfunction

Edited by yetibear
Link to comment
Share on other sites

I'm just a noob scripter, but I think your function variable is re-initialized each function call and there's nothing to change the IF block behavior.

 

You might add a flag variable outside the function definition and change it within the IF/ELSEIF blocks to reflect the actions taken. You can then decide what to do if the action has already been performed.

Link to comment
Share on other sites

I'm not even a noob scripter, I think I could class myself as a delinquent and still think it was a compliment.

 

I don't know what you mean, I pieced this script together from watching and reading other script tutorials. I like to make mods but I can't do the scripting, just thought it was time to take my mods to the next level. before I try custom items in them. If possible can you direct me to a tutorial or example of how its done.

Link to comment
Share on other sites

What you could probably do in your case is add conditions to the buttons in your message box. No scripting needed. So for example you could add a condition to the button that lets the player buy the interior guards using the GetDisabled == 1 condition, set to run on one of your guards. That way the button would only be displayed if the guards weren't enabled already.

 

You can also use IsEnabled/IsDisabled in a script to achieve the same ends, but it's less elegant because you ideally shouldn't show the player a button they can't click. But you may want to use them to make it so that if all upgrades have been purchased, the menu message is no longer shown.

 

The general methods of having a "do once" script are either to use states, or a Boolean variable or property.

Edited by DreamKingMods
Link to comment
Share on other sites

Thanks for that.

 

I'll give it a blast,

 

first with the script option isEnabled/disabled and try to put a message attached like "you already employed these staff".

 

if there is a better or easier way please let me know.

 

Thanks again,

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...