Jump to content

Scripting Help


bencebence

Recommended Posts

Hey everybody!

I was making the finishing touches on my mining script, and I tried something out.

I put reference on all of the veins, then gave them "HP" so after 6 hits, the vein should be disabled.

I don't know if my problem is because of this or not, but now I can only mine from ONE vein. So there are lots of veins placed down, and it seems that the script applies only on ONE vein.

What is the problem?

Here is one of the vein's script.

Scriptname RaivenDwarfiteOre

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 ores in this rock!"
endif
end

Begin GameMode

set VeinHP to 1

If (VeinHP == 6 )
	DwarfiteVeinRef1.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef2.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef3.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef4.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef5.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef6.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef7.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef8.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef9.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef10.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef11.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef12.Disable
	Set VeinHP to 0
	Message "There are no more ores in the rock."
EndIf
If (VeinHP == 6 )
	DwarfiteVeinRef13.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 >= 25)
		player.additem DwarfiteOre 1
	elseif (chance <= 30 && chance >= 14 && bluntskill >= 25)
		player.additem JunkOre 1
	elseif (chance < 14 && bluntskill >= 25)
		message "You found nothing."
		set playhitsound to 1
	elseif (bluntskill < 25)
		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

I hope someone can solve this problem.

Thanks in advance,

bencebence

Link to comment
Share on other sites

When you say you can only mine one vein, is it because the others won't activate or do they disappear?

 

Are all the veins sharing a base object? If so, on first glance I would guess because the veins seem to be sharing hp.

Also, is veinhp supposed to be reset to 1 every frame? It looks like that is another thing happening

Edited by WarRatsG
Link to comment
Share on other sites

I haven't done too much with scripts on objects, but it seems like they are all sharing the same variable. If so, a solution can be found with an array. Either a StringMap, where:

 

let String := GetEditorID this

let String := sv_Erase String 0 2 ; this line is needed to prevent things getting mixed up if the user changes their load order.

let Array := ar_construct StringMap

let Array [$String] := 'the health of the vein'

 

Or alternativly, with a map:

 

let String := GetEditorID this

let String := sv_Erase String 0 2

let Number := ToNumber $String 1

let Array := ar_construct Map

let Array [Number] := 'the health of the vein'

Link to comment
Share on other sites

Instead of doing all that stuff with arrays, first try changing

 

        If (VeinHP == 6 )
               DwarfiteVeinRef1.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef2.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef3.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef4.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef5.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef6.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef7.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef8.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef9.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef10.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef11.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef12.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf
       If (VeinHP == 6 )
               DwarfiteVeinRef13.Disable
               Set VeinHP to 0
               Message "There are no more ores in the rock."
       EndIf

 

to

 

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

Link to comment
Share on other sites

Erm ... correct me if I'm wrong, but if the routine you first posted is the one which fails, you are defining a short called VeinHP, with a totally unknown initial value. Surely if that value is being passed to the routine, you either need to use the global variable name, and not redefine it, or define the local variable as equal to the global variable at the start of the routine.
Link to comment
Share on other sites

The variables need to be declared as usual, so:

 

string_var String

array_var Array

 

Would go at the top of your script.

 

I'd stick the let 'Array := ar_construct StringMap' line inside a DoOnce block somewhere. To be safe, you might be better off declaring the array in a quest script, just in case variables on Objects reset at any time. Then when you want to set vein's HP:

 

let String := GetEditorID this

let String := sv_Erase String 0 2

let Array [$String] := 'What you want to set it to'

 

Or if you want to reference it, ( you can't use arrays in 'if's so you need to set a standard short to the value first, or use the 'eval' command)

 

let String := GetEditorID this

let String := sv_Erase String 0 2

let VeinHP := Array [$String]

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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