Jump to content

Scripting Help


bencebence

Recommended Posts

Ok yeah, Fg's solution is far simpler than mine, but god dammit, I like arrays! If you can't solve something with arrays, you just aren't using enough!

 

I love arrays too! But sometimes it's just not necessary (and add a lot of unneeded work) to use them.

 

Also one more thing. When I made my script like this I set persistent reference on all of the veins. I've just noticed that the only working veins was the first ones. Which had CopperVein1, CoalVein1. Can this be a problem, and if yes can I solve it?

(I'll remove the references from them, and hope that it'll work then.)

 

I don't think it matters what you have them named. Did you try the change I suggested before seeing if they all worked? Also, just a note. Your script only updates the HP when you activate the vein but you mine by attacking it. Attacking it doesn't activate the vein, so... Just mining won't reduce the HP of the vein.

Link to comment
Share on other sites

Alright, I checked it again, now that I've fixed it, and still, only that vein works, which I don't know, maybe the first I placed if I'm right.

So each vein Has one working, but only one, the others are just like, I'm hitting normal rocks... :S

What is the problem?

Here is the script maybe it has the problem;

Scriptname RaivenCopperOre

short bluntskill
short ready
short chance
short playhitsound

short VeinHp

Begin OnActivate
If VeinHP >= 1
	Set VeinHP to VeinHp + 1
Else
Message "There are no more ores in this rock!"
Endif
End

Begin GameMode

If (VeinHP == 8 )
	Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf

if (GetCrossHairRef == GetSelf) && (OnControlDown 4)
	if (Player.GetEquipped MiningPick)
		set ready to 1
	else
		Message "You must equip a Mining Pick to mine the rock."
	endif
endif
if (ready)
	set ready to 0
	set bluntskill to player.getactorvalue blunt
	set chance to getrandompercent

	if (chance > 30 && bluntskill >= 1)
		player.additem CopperOre 1
	elseif  (chance >= 14 && chance <= 30 && bluntskill >= 1)
		player.additem JunkOre 1
	elseif (chance < 14 && bluntskill >= 1)
		message "You found nothing."
		set playhitsound to 1
	elseif (bluntskill < 1)
		message "You don't have high enough blunt skill to mine this vein."
	endif
if (playhitsound == 1)
	playsound wpnhitblunt
	set playhitsound to 0
else
	playsound wpnblockblunt
endif
endif
End

Please if someone finds anything wrong, that can cause this problem, report it to me.

Thanks in advance,

bencebence

Link to comment
Share on other sites

Begin OnActivate
   If VeinHP >= 1
       Set VeinHP to VeinHp + 1
   Else
       Message "There are no more ores in this rock!"
   Endif
End

This way the count always increase when you activate the item, no matter if you have a Mining Pick. The vein will expire and you won't get a single ore

 

Begin GameMode
       
   If (VeinHP == 8 )
       Disable
       Set VeinHP to 0
       Message "There are no more ores in the rock."
   EndIf

   if (GetCrossHairRef == GetSelf) && (OnControlDown 4)
       if (Player.GetEquipped MiningPick)
           set ready to 1
       else
           Message "You must equip a Mining Pick to mine the rock."
       endif
   endif

   if (ready)
       set ready to 0
       set bluntskill to player.getactorvalue blunt
       set chance to getrandompercent

       if (chance > 30 && bluntskill >= 1)
           player.additem CopperOre 1
       elseif  (chance >= 14 && chance <= 30 && bluntskill >= 1)
  		player.additem JunkOre 1
       elseif (chance < 14 && bluntskill >= 1)
           message "You found nothing."
           set playhitsound to 1
       elseif (bluntskill < 1)
           message "You don't have high enough blunt skill to mine this vein."
       endif

       if (playhitsound == 1)
           playsound wpnhitblunt
           set playhitsound to 0
       else
           playsound wpnblockblunt
       endif
   endif
End

This should go in the "OnActivaton" block, without the first IF (when you activate it, you surely used that key, and your crosshair surely point at the item)

You can remove "chance <= 30" condition from the first ElseIf, since the If already check it with "chance > 30"

For the same reason you can remove "Chance < 14 in the second ElseIf; also you can use check for (bluntskill >=) before and avoid repeat it."

Since every skill of every race is minimum 5, I assume you will change "bluntskill>=1" ( ==> Always true).

 

IMO, none of these lines should go in "GameMode" block, since the core of the mod is the activation of an item.

By activating the vein, it can give you ore, give nothing, or expire. There's no reason for the mod to run continuously.

 

 

The resulting script (fixed and optimized) should be this:

 

Begin OnActivate

   If (VeinHP == 8 )
       Disable
       Set VeinHP to 0
   EndIf

   if (Player.GetEquipped MiningPick)              ; without a mining pick you can't do anything
       set bluntskill to player.getactorvalue blunt
       if (bluntskill >=1)                                         	; without enough skill...
           if (VeinHP >= 1)                                        ; if the ore is expired...
               set ready to 1
           else
               message "There are no more ores in the rock."
           endif
       else
           message "You don't have high enough blunt skill to mine this vein."
       endif
   else
       message "You must equip a Mining Pick to mine the rock."
   endif

   if (ready)
       set ready to 0
       set VeinHP to VeinHp + 1 	; I put this there because you can try to mine only with a pick and enough skill (so ready == 1)
       set chance to getrandompercent

       if (chance > 30)        ; If ready is 1 (required to reach to this line), then your blunt skill is surely enough. No reason to check again.
           player.additem CopperOre 1
       elseif  (chance >= 14)    ; if it reach this line, it is surely less than 30. No need to check again
           player.additem JunkOre 1
       else                                    ; Surely less than 14...
           message "You found nothing."
           set playhitsound to 1
       endif

       if (playhitsound == 1)
           playsound wpnhitblunt
           set playhitsound to 0
       else
           playsound wpnblockblunt
       endif
   endif
End

 

Edited by forli
Link to comment
Share on other sites

Hmpf, it seems that the script isn't work at all. My friend tested it, and when he hit with the pickaxe nothing happens at all, and when he interacts it, it says that there aren't any ores left. (he didn't interract it before)

I've take a lock at the code and I think there are 2 problems:

 

1) The way this code work, you have to activate the vein with the use key, not the attack key.

If you want the script to run when you hit the vein with your pick, you have to catch when your crosshair is pointed at the vein and you tap attack key or the game play the sound of the axe hitting something (not someone).

This explain me why you try to use the GameMode block (sorry, I didn't realize it before)

Well you should change the block into "GameMode" and change this code:

 

This

    if (Player.GetEquipped MiningPick)              ; without a mining pick you can't do anything
       set bluntskill to player.getactorvalue blunt
       if (bluntskill >=1)                                             ; without enough skill...
           if (VeinHP >= 1)                                        ; if the ore is expired...
               set ready to 1
           else
               message "There are no more ores in the rock."
           endif
       else
           message "You don't have high enough blunt skill to mine this vein."
       endif
   else
       message "You must equip a Mining Pick to mine the rock."
   endif

change into

   if (GetCrossHairRef == GetSelf) && (OnControlDown 4)
       if (Player.GetEquipped MiningPick)              ; without a mining pick you can't do anything
           set bluntskill to player.getactorvalue blunt
           if (bluntskill >=1)                                             ; without enough skill...
               if (VeinHP >= 1)                                        ; if the ore is expired...
               set ready to 1
               else
                   message "There are no more ores in the rock."
               endif
           else
               message "You don't have high enough blunt skill to mine this vein."
           endif
       else
           message "You must equip a Mining Pick to mine the rock."
       endif
   endif

 

 

2) VeinHP isn't initialized. So this variable can start at any value. You can't initialize it in the OnActivate block, neither in a loop in GameMode.

The script should initialize every vein in the cell when you first enter that cell.

Also you need an array to keep track of every cell you've visited. If you've already visited a cell, the veins are initialized already so they shouldn't be initialized again (mined/expired veins come back to full life, giving you infinite sessions every time you exit/re-enter that cell). I can't help you with the array, since I know nothing about them

 

 

EDIT: In the above post (in the spoiler) I've fixed some missing "endif". Also "Set bluntskill to Player.GatAV Blunt" was misplaced.

Edited by forli
Link to comment
Share on other sites

I just just fixed an issue with a script from a mod I have installed by replacing "Begin" with "begin", it's worth a shot. The script was very, very simple but didn't seem to be working at all.

 

Edit: Here's a link to the thread I posted about it if you care to take a look at the script.

Edited by MShoap13
Link to comment
Share on other sites

I just just fixed an issue with a script from a mod I have installed by replacing "Begin" with "begin", it's worth a shot. The script was very, very simple but didn't seem to be working at all.

 

Edit: Here's a link to the thread I posted about it if you care to take a look at the script.

Are you sure? Read this. It says "TES Script is not case sensitive".

This mean that the issue you talk about can't be related to the first capital letter.

Maybe you fixed it unwittingly and think that the capital letter is the cause.

Edited by forli
Link to comment
Share on other sites

I just just fixed an issue with a script from a mod I have installed by replacing "Begin" with "begin", it's worth a shot. The script was very, very simple but didn't seem to be working at all.

 

Edit: Here's a link to the thread I posted about it if you care to take a look at the script.

 

Are you sure? Read this. It says "TES Script is not case sensitive".

This mean that the issue you talk about can't be related to the first capital letter.

Maybe you fixed it unwittingly and think that the capital letter is the cause.

 

I'm absolutely positive that is what fixed said script. It's part of a mod that places map markers at the houses you can buy after you've purchased them. The main script that adds the marker is an altered version of the script that gives you the key and sets ownership of the property. That script didn't get a chance to run as at the time I purchased my house, another plugin, which was loaded after House Map Markers, had a different variation of that script.

 

The script I have posted on that thread is a backup in-case you'd already purchased your house before them mod was installed. I tried a number of things before replacing the capital "B" with a lower-case one and nothing added the marker for my IC house to the map. As soon as I changed only that one letter, the marker was added. Maybe this is a rare exception to the rule of case. :tongue:

Link to comment
Share on other sites

  • Recently Browsing   0 members

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