Jump to content

Scripting Questions


Recommended Posts

I've created a feature in my mod where the player can build a base. In the process of building that base he constructs a generator that is used to power the lights. HOWEVER, the lights consume fuel that you must put in a tank if you want them to stay on. When the lights go out at night (well, when I figure out how to script it) bad things happen.

Problem is, it's all tied to a quest. The quest checks fuel supplies against lights on every 5 seconds. Once the fuel runs out the lights go off. However, it seems to be causing intermittent crashes and really doesn't need to be checking that often. The main point was to create a need to build a generator, to be reminded that electrical devices need power to run and that you must produce that energy somehow.

At some point, another quest will be created to upgrade to solar, etc. but for now... I need to fix this script. How would you change this so it checks less (or any other suggestion that might make it run more smoothly.


UNRELATED QUESTION: I know how to create dialogue and an npc. But how would you create a companion wheel for people in your faction that just allowed you to change their inventory (armor, etc.) As part of the base building you can create guards...but I'd like to make it possible for the player to change anyone in his faction's armor, weapons, etc.


MANY THANKS!

###MAIN QUEST SCRIPT. Right now. eac lights in each room, etc. are attached to an x marker. That marker is linked to an activator (a switch). If the generator is fixed and you have fuel, the lights come on. If not, you're alone in the dark.

scn BlackbriarPowerBaseQuestScript
int Fuel ; This is the total fuel units in stock
int FuelRqd ; This is the calculated amount that will be used in a single 5 second period
Begin GameMode
If Fuel
Else
return
Endif
set FuelRqd to 0
;Lghts1 uses 1 unit of Fuel/5sec
If BlackbriarLgts1.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts2 uses 1 unit of Fuel/5sec
If BlackbriarLgts2.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts3 uses 1 unit of Fuel/5sec
If BlackbriarLgts3.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts4 uses 1 unit of Fuel/5sec
If BlackbriarLgts4.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts5 uses 1 unit of Fuel/5sec
If BlackbriarLgts5.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts6 uses 1 unit of Fuel/5sec
If BlackbriarLgts6.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts7 uses 1 unit of Fuel/5sec
If BlackbriarLgts7.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts8 uses 1 unit of Fuel/5sec
If BlackbriarLgts8.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts9a uses 1 unit of Fuel/5sec
If BlackbriarLgts9a.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts10a uses 1 unit of Fuel/5sec
If BlackbriarLgts10a.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts11 uses 1 unit of Fuel/5sec
If BlackbriarLgts11.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Lghts12 uses 1 unit of Fuel/5sec
If BlackbriarLgts12.GetDisabled
Else
set FuelRqd to FuelRqd + 1
Endif
;Subtract the fuel used
set Fuel to Fuel - FuelRqd
;Turn off all power users when Fuel runs out.
If Fuel < 1
set Fuel to 0
BlackbriarLgts1.Disable
BlackbriarLgts2.Disable
BlackbriarLgts3.Disable
BlackbriarLgts4.Disable
BlackbriarLgts5.Disable
BlackbriarLgts6.Disable
BlackbriarLgts7.Disable
BlackbriarLgts8.Disable
BlackbriarLgts9a.Disable
BlackbriarLgts10a.Disable
BlackbriarLgts11.Disable
BlackbriarLgts12.Disable
Endif


######

ScriptName BlackbriarPowerLightScript
ref light
Begin OnActivate
if BlackbriarPowerBaseQuest.Fuel == 0
return
Endif
if light == 0
set light to GetLinkedRef
endif
if light.GetDisabled
light.Enable
else
light.Disable
endif
Activate
End

 

 

#################

scn BlackbriarFuelTank
Begin onActivate
If GetQuestRunning BlackbriarPowerBaseQuest
Else
StartQuest BlackbriarPowerBaseQuest
Endif
If player.GetItemCount BlackbriarAtwoodFUELOIL
player.removeItem BlackbriarAtwoodFUELOIL 1
set BlackbriarPowerBaseQuest.Fuel to BlackbriarPowerBaseQuest.Fuel + 500
Else
ShowMessage BlackbriarPowerNoBatteriesMsg
Endif
End
Edited by Guest
Link to comment
Share on other sites

Just change the quest delay to make it longer, default is 5 seconds, it can be much long or shorter if you like.

 

I don't see why this would cause crashes, but I just quickly skimmed it.

Link to comment
Share on other sites

Yeah, I had the game crash randomly when I had a quest script set to check too often (I think it was like 0.01 seconds or something, hahaha!), so if you set the delay to something a bit higher it should work. I think.

 

 

 

 

UNRELATED QUESTION: I know how to create dialogue and an npc. But how would you create a companion wheel for people in your faction that just allowed you to change their inventory (armor, etc.) As part of the base building you can create guards...but I'd like to make it possible for the player to change anyone in his faction's armor, weapons, etc.

 

I'm not sure if it's possible with the wheel if they're not currently hired per se, but if you give them a dialogue topic like "I have some better equipment for you" with OpenTeammateContainer in the result script (like the vanilla "let's trade equipment" dialogue prompt does) I think you should be able to do what you want.

Link to comment
Share on other sites

You can check it with a different frequency if you want, but running on default delay time has already an impercetible workload, I believe it is already good as it is. What would worry me is the CTD, I don't see a reason why it could be related to the delay time, nor I can notice anything on the script that could lead to that

Link to comment
Share on other sites

Thank you both for the feedback :) I really have so much to learn when it comes to scripting.... it takes me hours to put together what you all do in 2.2 seconds. So, thank you for the feedback! A follow up question:

1. Would I just give every one of the npc's in the player's faction that dialogue line? Let me rephrase: I know how to make dialogue for a specific character - how do you make it for the whole faction?

Link to comment
Share on other sites

You can check it with a different frequency if you want, but running on default delay time has already an impercetible workload, I believe it is already good as it is. What would worry me is the CTD, I don't see a reason why it could be related to the delay time, nor I can notice anything on the script that could lead to that

THE CTD worries me...and almost every time it happens, it is after I turn on the lights. :/

 

Also: another unrelated question: I'm also working on a syringe of medicine that has a couple of possible effects if you use it: 1. It heals you completely of any wounds (and resurrects you/NPC if "dead"), 2.Does nothing at alll and 4. Brings you back as a zombie/ghoul that can infect others. Can't seem to get it to work right though...

 

 

##

 

scn BlackbriarReviverScript
short sRand
ref rTarget
begin Gamemode
set rTarget to player.GetCombatTarget
Set sRand to GetRandomPercent
If player.IsSneaking==1 && rTarget.Getdead && player.getitemcount BlackbriaReviver >= 1 && sRand >= 10
playsound NPCHumanUsingPsycho
rTarget.Disable
rTarget.PlaceAtMe BlackbriarZombieLevel4
player.removeItem BlackbriaReviver 1
player.additem BlackbriaReviverEMPTY 1
elseif player.IsSneaking==1 && rTarget.Getdead && player.getitemcount BlackbriaReviver >= 1
playsound NPCHumanUsingPsycho
rTarget.Resurrect
player.removeItem BlackbriaReviver 1
player.additem BlackbriaReviverEMPTY 1
endIf
end

 

Link to comment
Share on other sites

If the siringue is an ingestible, the best deal to use a gamemode would be attaching that script on a spell, casted (CIOSed...)by the ingestible. Instead, if you simply are attaching the script to the ingestible, then you should use an onactivate.

 

Whatever approach you take, the script is assuming that rTarget exists, but instead it would be required to check if it exists first.

It also assumes that npc is either an actor or a creature. You are creating a zombie, so maybe you want only actors, at that point you should use conditional statement that checks if GetType 42 / 45 is true.

 

Last, but this is personal, since you're using functions like Equip and PlaceAtMe, staging it in more frames wouldn't be bad, so I personally wouldn't use an OnActivate but I would stick with the spell in gamemode, with a duration of at least 1 second, or undefined (dispelled by the script when it has finished)

Edited by Fallout2AM
Link to comment
Share on other sites

​TL;DR

Try this for your CTDs:

scn BlackbriarPowerLightScript

ref light

Begin OnActivate

	if BlackbriarPowerBaseQuest.Fuel == 0
		Return
	endif
	
	set light to GetLinkedRef

	if light
		if light.GetDisabled
			light.Enable
		else
			light.Disable
		endif
	endif
	
	Activate
End
Link to comment
Share on other sites

  • Recently Browsing   0 members

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