bencebence Posted July 5, 2011 Share Posted July 5, 2011 Hey everybody!I'd need some help.I'm working on Raiven's Mining Village too, and I made a mining script. But something is not right with it. I hope someone can point on the problem and help me.Thanks in advance:bencebence And here is the script:Scriptname RaivenMineScript short bluntskill short chance Begin OnActivate set bluntskill to player.getactorvalue blunt set chance to getrandompercent if (player.getequipped MiningPick == 1 & IsKeyPressed 44 == 1) ;Z key player.playgroup AttackPower 1 if (bluntskill/2 > chance) playsound wpnblockblunt player.additem IroneOre 1 else playsound wpnhitblunt message "You found nothing." endif if (bluntskill/3 > chance) playsound wpnblockblunt player.additem Gem0SilverNugget 1 else playsound wpnhitblunt message "You found nothing." if (bluntskill/4 > chance) playsound wpnblockblunt player.additem Gem0GoldNugget 1 else playsound wpnhitblunt message "You found nothing." if (bluntskill/5 > chance) playsound wpnblockblunt player.additem glassore 1 else playsound wpnhitblunt message "You found nothing." if (bluntskill/6 > chance) playsound wpnblockblunt player.additem EbonOre 1 else playsound wpnhitblunt message "You found nothing." endif if (chance == 10) playsound wpnblockblunt player.additem Coal 1 message "You found a flawed topaz." elseif (chance == 84) playsound wpnblockblunt player.additem gem2topazflawed 1 message "You found a flawed topaz." elseif (chance == 85) playsound wpnblockblunt player.additem gem2topaz 1 message "You found a topaz." elseif (chance == 86) playsound wpnblockblunt player.additem gem2topazflawless 1 message "You found a flawless topaz." elseif (chance == 87) playsound wpnblockblunt player.additem gem3rubyflawed 1 message "You found a flawed ruby." elseif (chance == 88) playsound wpnblockblunt player.additem gem3ruby 1 message "You found a ruby." elseif (chance == 89) playsound wpnblockblunt player.additem gem3rubyflawless 1 message "You found a flawless ruby." elseif (chance == 90) playsound wpnblockblunt player.additem gem4sapphireflawed 1 message "You found a flawed sapphire." elseif (chance == 91) playsound wpnblockblunt player.additem gem4sapphire 1 message "You found a sapphire." elseif (chance == 92) playsound wpnblockblunt player.additem gem4sapphireflawless 1 message "You found a flawless sapphire." elseif (chance == 93) playsound wpnblockblunt player.additem gem5emeraldflawed 1 message "You found a flawed emerald." elseif (chance == 94) playsound wpnblockblunt player.additem gem5emerald 1 message "You found am emerald." elseif (chance == 95) playsound wpnblockblunt player.additem gem5emeraldflawless 1 message "You found a flawless emerald." elseif (chance == 96) playsound wpnblockblunt player.additem gem6diamondflawed 1 message "You found a flawed diamond." elseif (chance == 97) playsound wpnblockblunt player.additem gem6diamond 1 message "You found a diamond." elseif (chance == 98) playsound wpnblockblunt player.additem gem6diamondflawless 1 message "You found a flawless diamond." endif player.playgroup Idle 1 else message "You must equip a Mining Pick to mine the rock." endif end Link to comment Share on other sites More sharing options...
David Brasher Posted July 6, 2011 Share Posted July 6, 2011 Problem that needs troubleshooting:something is not right with it. You may wish to explicitly state what the undesirable behavior is that the script exhibits. Link to comment Share on other sites More sharing options...
fg109 Posted July 6, 2011 Share Posted July 6, 2011 (edited) I agree with David. Explaining the problem when you're looking for help would get you help a lot easier. Although just looking at the script, I think I know what the problem is. OnActivate blocks only run when you activate the object. Grabbing an object is not the same thing as activating it. There's also a lot more that's wrong with the script, but that's the first thing that pops out at me. Edited July 6, 2011 by fg109 Link to comment Share on other sites More sharing options...
bencebence Posted July 6, 2011 Author Share Posted July 6, 2011 @fg109 Then which Begin line should I use? In Construction Set, it tells me these errors: - Invalid if/endif block structure on line 112. - Script 'RaivenMineScript', line 9: Mismatched parantheses Continue playing? Link to comment Share on other sites More sharing options...
MarkInMKUK Posted July 6, 2011 Share Posted July 6, 2011 (edited) Correct me if I'm wrong - but with a high enough blunt skill, couldn't you obtain several items with one hit? Your endif's seem to be applied a little haphazardly too. The way they told us in programming class when I was still punching cards to program was: Start with the LEAST likely occurrence, test for it, then fall through if it didn't happen. Otherwise you fulfil SEVERAL of the IF statements and get the result for the lot. So you'd end up with: if (bluntskill/6 > chance) playsound wpnblockblunt player.additem EbonOre 1 else if (bluntskill/5 > chance) playsound wpnblockblunt player.additem glassore 1 else if (bluntskill/4 > chance) playsound wpnblockblunt player.additem Gem0GoldNugget 1 else if (bluntskill/3 > chance) playsound wpnblockblunt player.additem Gem0SilverNugget 1 else if (bluntskill/2 > chance) playsound wpnblockblunt player.additem IroneOre 1 else playsound wpnhitblunt message "You found nothing." endif or at least something similar to that. If I haven't drastically misrepresented what you were doing in the script above, assuming you have a blunt skill > 6*chance: 16% chance of EbonOre4% chance of GlassOre (20%-16%)5% chance of Gold (25%-20%)8% chance of Silver (33%-25%)17% chance of Iron (50%-33%)50% chance of nothing Is that what you intended? Also, from a speed point of view. try replacing if (bluntskill/n > chance)with if (bluntskill > chance*n)as multiplication is far faster than division in most cases You COULD, to make life clearer, define up a series of constants such as chance_iron=2 and then useif (bluntskill > chance*chance_iron) - doesn't change the code but makes life SO much easier to debug. Edited July 6, 2011 by MarkInMKUK Link to comment Share on other sites More sharing options...
bencebence Posted July 6, 2011 Author Share Posted July 6, 2011 So, should I cut the script into different parts to be more simple? Link to comment Share on other sites More sharing options...
bencebence Posted July 6, 2011 Author Share Posted July 6, 2011 So at the begining something like this?Scriptname RaivenMineScript short bluntskillshort chanceshort chanceIronshort chanceSilvershort chanceGoldshort chanceGlassshort chanceEbony Begin OnActivate set bluntskill to player.getactorvalue blunt set chance to getrandompercent set chanceIron to 20 set chanceSilver to 35 set chanceGold to 50 set chanceGlass to 70 set chanceEbony to 85 Link to comment Share on other sites More sharing options...
MarkInMKUK Posted July 6, 2011 Share Posted July 6, 2011 (edited) If I were coming to the script to debug in later, then I'd find that FAR easier to follow, yes. Re-read the previous post as I was editing it to add probabilities in too. Check you can't use constants instead of shorts - they're only used by the compiler and thus don't take up variable space. Edited July 6, 2011 by MarkInMKUK Link to comment Share on other sites More sharing options...
bencebence Posted July 6, 2011 Author Share Posted July 6, 2011 Alright now the script looks like this:Scriptname RaivenMineScript short bluntskill short chance short chanceIron short chanceSilver short chanceGold short chanceGlass short chanceEbony Begin OnActivate set bluntskill to player.getactorvalue blunt set chance to getrandompercent set chanceIron to 20 set chanceSilver to 35 set chanceGold to 50 set chanceGlass to 70 set chanceEbony to 85 if (player.getequipped MiningPick == 1 && IsKeyPressed 44 == 1 ;Z key) player.playgroup AttackPower 1 if (bluntskill > chance*chanceIron) playsound wpnblockblunt player.additem IroneOre 1 else if (bluntskill/3 > chance*chanceSilver) playsound wpnblockblunt player.additem Gem0SilverNugget 1 else if (bluntskill/4 > chance*chanceGold) playsound wpnblockblunt player.additem Gem0GoldNugget 1 else if (bluntskill/5 > chance*chanceGlass) playsound wpnblockblunt player.additem glassore 1 else if (bluntskill/6 > chance*chanceEbony) playsound wpnblockblunt player.additem EbonOre 1 else playsound wpnhitblunt message "You found nothing." endif if (chance == 10) playsound wpnblockblunt player.additem Coal 1 message "You found some coal." elseif (chance == 84) playsound wpnblockblunt player.additem gem2topazflawed 1 message "You found a flawed topaz." elseif (chance == 85) playsound wpnblockblunt player.additem gem2topaz 1 message "You found a topaz." elseif (chance == 86) playsound wpnblockblunt player.additem gem2topazflawless 1 message "You found a flawless topaz." elseif (chance == 87) playsound wpnblockblunt player.additem gem3rubyflawed 1 message "You found a flawed ruby." elseif (chance == 88) playsound wpnblockblunt player.additem gem3ruby 1 message "You found a ruby." elseif (chance == 89) playsound wpnblockblunt player.additem gem3rubyflawless 1 message "You found a flawless ruby." elseif (chance == 90) playsound wpnblockblunt player.additem gem4sapphireflawed 1 message "You found a flawed sapphire." elseif (chance == 91) playsound wpnblockblunt player.additem gem4sapphire 1 message "You found a sapphire." elseif (chance == 92) playsound wpnblockblunt player.additem gem4sapphireflawless 1 message "You found a flawless sapphire." elseif (chance == 93) playsound wpnblockblunt player.additem gem5emeraldflawed 1 message "You found a flawed emerald." elseif (chance == 94) playsound wpnblockblunt player.additem gem5emerald 1 message "You found am emerald." elseif (chance == 95) playsound wpnblockblunt player.additem gem5emeraldflawless 1 message "You found a flawless emerald." elseif (chance == 96) playsound wpnblockblunt player.additem gem6diamondflawed 1 message "You found a flawed diamond." elseif (chance == 97) playsound wpnblockblunt player.additem gem6diamond 1 message "You found a diamond." elseif (chance == 98) playsound wpnblockblunt player.additem gem6diamondflawless 1 message "You found a flawless diamond." endif player.playgroup Idle 1 else message "You must equip a Mining Pick to mine the rock." endif end Link to comment Share on other sites More sharing options...
MarkInMKUK Posted July 6, 2011 Share Posted July 6, 2011 (edited) You forgot to remove the bluntskill/n bits in the top section, but otherwise I find that far clearer. However, replacing (bluntskill/2 > chance) with (bluntskill > chance*20) isn't quite right - your chance of items SHOULD be what you were previously dividing by, not a % Does it still throw up a compile error? Edited July 6, 2011 by MarkInMKUK Link to comment Share on other sites More sharing options...
Recommended Posts