Jump to content

Energy Cell Charger - Need Help


kreekgod

Recommended Posts

i have been trying and trying to make this simple mod on my own, and i just cant do it

the scripts i write just dont work, they compile fine, but fail to do what i want them too, or anything at all
this might be due to near total lack of scripting/code writing ability

particularly in defining and modifying variables

 

anyway, this is what ive been trying to make

a simple item that can be carried in the inventory

when you have it in your inventory (it could be activated to toggle it on or off)

first, it takes away a drained energy cell, or drained microfusion cell, or drained electron charge pack

then, after a set amount of time (somewhere between 1 and 10 minutes) , it gives you back the corrisponding ammo on a 1-1 basis

then it will repeat untill you have no more depleted energy cells of any sort

the order of which cells get picked first should be, microfusion cells, energycells and then electron charge packs
it should charge 1 depleted cell at a time

the net effect is, it will slowly recharge your depleted energy cells over time, thus justifying the 1 - 1 ammo return over the recipie based 3 or 4 - 1

this is the script i have so far... it does not work, i have commented useing ;

scriptname krkcellchargescript

float timer ; i have no idea how these work
short cell ; i copied them from other scripts
int isactivated ; they are probally the main reason its not working


Begin onEquip ;item currently a consumeable, aparently this is the use return

player.additem krkcellcharger 1 ;this is supposed to give a replacement activator when you use and thus destory the first, it doesnt
if isactivated == 0
set isactivated to 1 ;first run turns on
set timer to 0 ;timer based script isnt working
Activate
else
set isactivated to 0 ; second run turns off
set timer to 0
endif
end


begin gamemode
If isactivated == 1
if timer < 60 ; timer should be set to 1 min this is for debugging, origonally it was 10 minutes

if timer < 1;
elseif Timer < 2 ; drained cell working order, mfc first then sec then ecp
if Player.GetItemCount DrainedMicrofusionCell > 0
player.RemoveItem DrainedMicrofusionCell 1
set cell to 1
elseif Player.GetItemCount DrainedSmallEnergyCell > 0
player.RemoveItem DrainedSmallEnergyCell 1
set cell to 2
elseif Player.GetItemCount DrainedElectronChargePack > 0
player.RemoveItem DrainedElectronChargePack 1
set cell to 3
else ; to reset the timer if you dont have any drained cells
set cell to 0
set timer to 0
Endif
Endif

Else
if cell == 1; ; after timer, return useable ammo based on depleted cell
player.AddItem AmmoMicrofusionCell 1
set cell to 0
elseif cell == 2
player.AddItem AmmoSmallEnergyCell 1
set cell to 0
elseif cell == 3
player.AddItem AmmoElectronChargePack 1
set cell to 0
endif
Set timer to 0 ;reset timer to start again
Endif
Endif
End


any help getting this to work would be apreciated

Link to comment
Share on other sites

This should do what you want:

1. Create a new Misc Item, set its ID to DrainedAmmoChargerItem. Set the rest of the options to whatever you like. This is going to be the actual charger item the player carries in his inventory.
2. Create a new Quest, set its ID to DrainedAmmoChargerQuest, put a check in the Start Game Enabled box, then set Script Processing Delay to 1.0
3. Create a new Script, set Script Type to Quest, and use this code:

scn	DrainedAmmoChargerQuestScript

float	fChargeTimer
ref	rDrainedItem
ref	rChargedItem

begin GameMode

	if player.GetItemCount DrainedAmmoChargerItem	; Verifies the player carries the charger item.
		if fChargeTimer == 0
			if player.GetItemCount DrainedMicrofusionCell
				set rDrainedItem to DrainedMicrofusionCell
				set rChargedItem to AmmoMicroFusionCell
				set fChargeTimer to 40
			elseif player.GetItemCount DrainedSmallEnergyCell
				set rDrainedItem to DrainedSmallEnergyCell
				set rChargedItem to AmmoSmallEnergyCell
				set fChargeTimer to 30
			elseif player.GetItemCount DrainedElectronChargePack
				set rDrainedItem to DrainedElectronChargePack
				set rChargedItem to AmmoElectronChargePack
				set fChargeTimer to 20
			endif
			if fChargeTimer		; Timer was set, meaning the player does carry a draind item - remove it.
				player.RemoveItem rDrainedItem 1 1
			endif
		elseif fChargeTimer > 0		; Timer is running.
			set fChargeTimer to fChargeTimer - GetSecondsPassed
		else		; Timer expired, charging is complete - add the charged item.
			set fChargeTimer to 0
			player.AddItem rChargedItem 1 1
		endif
	elseif fChargeTimer	; The charger item was removed while charging was in progress - give back drained item.
		set fChargeTimer to 0
		player.AddItem rDrainedItem 1 1
	endif

end

4. Finally, return to DrainedAmmoChargerQuest and from the Script dropbox, select DrainedAmmoChargerQuestScript.

Link to comment
Share on other sites

thanks alot for the help

this works very nicely, it does what i wanted, and i like that you can adjust the timer per item

this script also looks like it can be expanded or adapated to exchange other items, should the need ever arise

one thing though, it plays a little flat, i think it could do with a message informing you that something is eather being charged, or done being charged... however, too many messages might also get very annoying... perhaps ill take a look at it later
while im terrible at writing fresh code, i can sometimes adapt scripting after going through it... sometimes...

would you mind if i uploaded a working version for others to use? ill ofcorse give credit where its due, unless youd rather upload it yourself

Link to comment
Share on other sites

 

 

too many messages might also get very annoying...

I agree.

 

 

 

would you mind if i uploaded a working version for others to use? ill ofcorse give credit where its due, unless youd rather upload it yourself

It was your idea (which is great, btw), so it's only right that you should upload it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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