The forum has been set to read-only mode. For community discussion and questions, head over to our Discord: https://discord.taleoftwowastelands.com

Script for failed crafting

General help and troubleshooting.
Post Reply
nicholiathan
Posts: 8
Joined: Sat Jun 28, 2014 5:00 am

Script for failed crafting

Post by nicholiathan » Mon Jul 07, 2014 2:26 am

I'm trying to write a mod with some new crafting receipes and changes to a couple of consumables. One of the things I want to do is make a script to create primers for ammo reloading. Having done a cursory research it is apparently a very dangerous thing to endevour so I plan to add an item (Chance of Failure) to the players inventory when the craft is done. This item has a random chance to detonate. If it does detonate the primers created will be lost and an explosion will occur. This item then removes itself. Checking the script for ammo boxes having the Chance of Failure remove itself and removing the primers on failure is easy enough. Checking the scripts for explosive traps it appears that the command Do 50 or Do 5000 causes the explosion. I can't find any documentation on this though. Has anyone worked with making an item that blows up like this and any advise on how I can make this happen?



Gribbleshnibit8
Posts: 481
Joined: Sun Nov 04, 2012 2:06 am

Do is short for DamageObject,

Post by Gribbleshnibit8 » Mon Jul 07, 2014 3:10 am

Do is short for DamageObject, which uses the destruction stages of the traps, not what you want.


What you want to do is have a script that calculates the failure chance, and if a failure occurs, it would do something like [quote]player.placeatme ExplosionForm 1[/quote]which will place an explosion of name ExplosionForm at the player. 



nicholiathan
Posts: 8
Joined: Sat Jun 28, 2014 5:00 am

thank you for the rapid reply

Post by nicholiathan » Mon Jul 07, 2014 4:41 am

thank you for the rapid reply. If all goes well I'll be uploading soonish.



nicholiathan
Posts: 8
Joined: Sat Jun 28, 2014 5:00 am

I have two scripts that don't

Post by nicholiathan » Mon Jul 14, 2014 11:03 am

I have two scripts that don't work. I was fairly sure that I'd built them correctly but I'm not as familiar with NV script as I could be.


The first script is attached to a create a chance of catastrophic failure when making primers. When a batch of Primer Fuel or Primers is made the player creates the fuel or a primer and a Chance of Failure. The Chance of Failure has the 1st script attached to it. After testing several times I've never had a failure. Is my script wrong or my character just lucky?


ScriptName NIRBChanceOfFailurescript



; Generate explosion on random roll greater than average of player's Science & Exposives skill



int killme

int chancefailed

int randomnum

int count





BEGIN OnAdd Player

    ; only run the 1st time primer fuel is added to inventory, i.e. when crafted

    if ( killme < 1 )

        set killme to 1

    endif

END



begin GameMode

    if (killme == 1)

        ; chance of failure is average of Science and Explosives scores

        set chancefailed to player.getActorValue Science

        set chancefailed to chancefailed + getActorValue Explosives

        set chancefailed to chancefailed / 2

        set randomnum to GetRandomPercent



        if ( randomnum > chancefailed )

            ; this batch did not turn out well & explodes

            ; all primer fuel in the player's inventory is destroyed

            player.placeAtMe GrenadeFragExplosion 1

            set count to player.getItemCount NIRBPrimerFuel

            player.removeItem NIRBPrimerFuel count

        endIf



        ; either way remove the the cance of failure

        set killme to 2

        RemoveMe

    endif



end


The second script I'm having trouble with I thought was much simpler. I've modded Doctor's Bags to require 2 clean bandages, and a sterilized scalpel, a sterilized forceps, a sterilized scissors, a medical brace & a surgical tubings. The script is supposed to return an unsterile set of scalpel, forceps and scissors. This script is attached to the doctor's bag ingestible item


scn scn NIRBDoctorsBagUsedscript



begin onActivate

    player.addItem SurgicalForceps01 1

    player.addItem SurgicalScalpel01 1

    player.addItem SurgicalScissors01 1

    Activate Player

end


Any help would be appriciated.


 



JaxFirehart
Posts: 3003
Joined: Wed Sep 12, 2012 12:33 am

for debugging scripts, the

Post by JaxFirehart » Mon Jul 14, 2014 2:01 pm

for debugging scripts, the command printc is very useful. It accepts format specifiers allowing you to do commands like:


printc "Avg. Skill: %.0f, Random Chance: %.0f" chancefailed randomnum


combine that with my console logging mod (Requires NVSE) and you will a nice list of every failure calculation after a play session


I'm only had time for a cursory glance at the first one, and I don't see anything obviously wrong.


The second one should be an onequip block and you don't need to call Player.EquipItem in those blocks. Generally speaking, inventory items are equipped, world objects are activated.



nicholiathan
Posts: 8
Joined: Sat Jun 28, 2014 5:00 am

I managed to fix the Doctors

Post by nicholiathan » Tue Jul 15, 2014 9:32 am

I managed to fix the Doctors Bag script problem by changing the scrip to an effect script, creating an effect to call the script and assigning the new effect to the doctor's bag. My 1st script had an even more idiotic problem. I put the wrong script on my item. It works but apparently the onAdd Player block is not called when an item is crafted. It works but only if the player drops the Chance of Failure and picks it back up. Not what I wanted.



Post Reply