Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Scripting Help: Opening a chest only if you have joined a faction


mhahn123
 Share

Recommended Posts

Hello all,

Hopefully someone with scripting experience can lend a helping hand. I have created a mod that adds chests containing custom "starter" equipment to each of the various guilds. Fighters guild, mages guild, dark brotherhood, etc. No problem getting the stuff in game and everything works so far. I would like to attach a script to the chest which allows it to only be opened once you have joined the respective guild, if you have not joined or are not high enough rank a message box pops up and chest does not open.

I have tried reading through the basic tutorials here and in CS wiki. Tried to adapt scripts from a couple of other mods I found, but so far have only managed to get myself frustrated. Any help would be greatly appreciated.

Cheers.

Link to comment
Share on other sites

Something like the following should work pretty well. GetFactionRank returns -1 if the player is not in the facton, replace > 0 with > 4 if for example you want them to be at least rank 5. Just did this on my lunch at work, so it's not tested.


scn MyScriptName

Ref rUser


Begin OnActivate


Set rUser to GetActionRef ; Sets your reference var to whoever is activating the chest.

If rUser.GetFactionRank FightersGuild > 0 ; or whatever level you want to check for.
Activate ; opens the chest.
Else
MessageBox "Stealing from the Fighters' Guild? Not smart my friend."
Endif


End
[/code]

Post if you have any problems,

Good Luck.

WT

Link to comment
Share on other sites

Something like the following should work pretty well. GetFactionRank returns -1 if the player is not in the facton, replace > 0 with > 4 if for example you want them to be at least rank 5. Just did this on my lunch at work, so it's not tested.


scn MyScriptName


Ref rUser



Begin OnActivate



Set rUser to GetActionRef ; Sets your reference var to whoever is activating the chest.


If rUser.GetFactionRank FightersGuild > 0 ; or whatever level you want to check for.

	Activate ; opens the chest.

Else

	MessageBox "Stealing from the Fighters' Guild? Not smart my friend."

Endif



End

Post if you have any problems,

Good Luck.

WT

Thanks WT. I'll try it out and let you know how it works.

Link to comment
Share on other sites

Why not set ownership of each chest to Faction/Rank?

Thank you Hanaisse, it's a good tip. That is actually how I have them set right now. Which makes opening chest a crime if you don't meet the requirements, but doesn't stop you from doing it anyway. I was looking for a way to keep the items from being pilfered unless the PC was actually a member of the guild and at the appropriate rank.

Cheers

Link to comment
Share on other sites

Something like the following should work pretty well. GetFactionRank returns -1 if the player is not in the facton, replace > 0 with > 4 if for example you want them to be at least rank 5. Just did this on my lunch at work, so it's not tested.


scn MyScriptName


Ref rUser



Begin OnActivate



Set rUser to GetActionRef ; Sets your reference var to whoever is activating the chest.


If rUser.GetFactionRank FightersGuild > 0 ; or whatever level you want to check for.

	Activate ; opens the chest.

Else

	MessageBox "Stealing from the Fighters' Guild? Not smart my friend."

Endif



End

Post if you have any problems,

Good Luck.

WT

Hi WT,

Been playing with this for a while now and can't seem to get it to work. :coffee: The script compiles and saves fine. But once I create a test chest and drop it in game can't get past the message box dialogue. Tried changing GetFactionRank numerical values but still nothing. :crybaby: Any ideas? This looked really promising.

Link to comment
Share on other sites

That's odd, the logic of the IF statement looks alright. Try using this, it will show you what is getting detected for rank, should help us narrow down where the problem is.


scn MyScriptName

Ref rUser
Short sRank


Begin OnActivate


Set rUser to GetActionRef ; Sets your reference var to whoever is activating the chest.
Set sRank to rUser.GetFactionRank ;Store the rank in a var you can check
Message "Rank %.0f", sRank, 5 ;Displays whatever is stored in the var

If sRank > 0 ; or whatever level you want to check for.
Activate ; opens the chest.
Else
MessageBox "Stealing from the Fighters' Guild? Not smart my friend."
Endif


End
[/code]

Let me know what you find out.

WT

Link to comment
Share on other sites

Something like the following should work pretty well. GetFactionRank returns -1 if the player is not in the facton, replace > 0 with > 4 if for example you want them to be at least rank 5. Just did this on my lunch at work, so it's not tested.


scn MyScriptName


Ref rUser



Begin OnActivate



Set rUser to GetActionRef ; Sets your reference var to whoever is activating the chest.


If rUser.GetFactionRank FightersGuild > 0 ; or whatever level you want to check for.

	Activate ; opens the chest.

Else

	MessageBox "Stealing from the Fighters' Guild? Not smart my friend."

Endif



End

Post if you have any problems,

Good Luck.

WT

I got it! :thumbup: Your original "off the cuff" version actually worked fine with only a minor tweak. Changed the "GetFactionRank" line from > 0 to >= 0 and it works perfectly. I'm guessing since the guild faction rank starts at 0 for associate level, setting the criteria at a "greater than" status wouldn't work. In any case thank you very much for giving me a starting point to work from. You are all awesome for giving your help so freely. :D

P.S. You have full credits for the script when I eventually upload my first mod! Thanks again.

Cheers, Toxic.

Link to comment
Share on other sites

Just another idea - why not set the lock level to "Requires a key", and upon joining the faction, either give the player the key or unlock the chest?

This method prevents the player from cheating, and using the console to unlock the chest.

I used this many years ago in my Ancient Towers mod for this reason.

Link to comment
Share on other sites

This method prevents the player from cheating, and using the console to unlock the chest.

I used this many years ago in my Ancient Towers mod for this reason.

That is absolutely correct. Even with "requires a key" the PC can cheat using the console. A script cannot be cheated and forces the player to earn the items the old fashioned way. I actually got the idea for scripted chest from the "Blades Faction Mod" which allows the PC to rise up through the Blades and gives 3 new sets of Blades armor based on rank. The armors are locked in scripted chests, but his scripts were much too complex for a newbie like myself and just couldn't figure out how to adapt them to work for me. Now that I have at least a basic understanding of how scripting works it opens up a whole new dimension for me. Thanks once again to everyone who chimed in on this. I am now reading up on basic texturing and custom resource tutorials. This site is an incredible source of information which I will continue to explore for quite some time to come.

Edited by toxiclove
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...