bencebence Posted July 18, 2011 Share Posted July 18, 2011 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 EndI hope someone can solve this problem.Thanks in advance,bencebence Link to comment Share on other sites More sharing options...
WarRatsG Posted July 18, 2011 Share Posted July 18, 2011 (edited) 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 July 18, 2011 by WarRatsG Link to comment Share on other sites More sharing options...
bencebence Posted July 18, 2011 Author Share Posted July 18, 2011 All the same veins have same base object. The others just not activate when I hit them with my pick.VeinHP shouldn't reset every frame, so I think that is a problem.So what should I change to make it work? Link to comment Share on other sites More sharing options...
PrettyMurky Posted July 18, 2011 Share Posted July 18, 2011 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 thislet 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 StringMaplet Array [$String] := 'the health of the vein' Or alternativly, with a map: let String := GetEditorID thislet String := sv_Erase String 0 2let Number := ToNumber $String 1let Array := ar_construct Maplet Array [Number] := 'the health of the vein' Link to comment Share on other sites More sharing options...
bencebence Posted July 18, 2011 Author Share Posted July 18, 2011 Huh, I never really workd with arrays or StringMaps (This means I never saw one :S XD)Where should I place this, or what should I do with it? Link to comment Share on other sites More sharing options...
fg109 Posted July 18, 2011 Share Posted July 18, 2011 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 More sharing options...
MarkInMKUK Posted July 18, 2011 Share Posted July 18, 2011 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 More sharing options...
PrettyMurky Posted July 18, 2011 Share Posted July 18, 2011 The variables need to be declared as usual, so: string_var Stringarray_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 thislet String := sv_Erase String 0 2let 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 thislet String := sv_Erase String 0 2let VeinHP := Array [$String] Link to comment Share on other sites More sharing options...
PrettyMurky Posted July 18, 2011 Share Posted July 18, 2011 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! Link to comment Share on other sites More sharing options...
bencebence Posted July 18, 2011 Author Share Posted July 18, 2011 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 More sharing options...
Recommended Posts