Problems with RemoveSpell/Dispel

Post » Sun Aug 08, 2010 12:09 pm

I've been working on and off at a script for a perk I'm trying to add, but I've hit a wall and can't figure out what to do. I'm an extremely inexperienced programmer, which is probably related to my issue. Here's my script:

scn NPTrashHumperSCRIPT; Big thanks to otm from the gamesas forums for putting me on the right trackshort doOnceref yourPaper ; yourPaper is gonna be ShackPaperDebris01-05Begin GameMode    set yourPaper to GetFirstRef 32 1 0 ; Find static world object in cell    Label 10    if yourPaper != 0        if yourPaper.GetIsID ShackPaperDebris01 || yourPaper.GetIsID ShackPaperDebris02 || yourPaper.GetIsID ShackPaperDebris03 || yourPaper.GetIsID ShackPaperDebris04 || yourPaper.GetIsID ShackPaperDebris05            if doOnce == 0                if yourPaper.GetDistance player < 90 ; If the player is close to yourPaper                    player.AddSpell NPTrashHumperSPELL ; Add perk ability                    set doOnce to 1                endif            else                player.RemoveSpell NPTrashHumperSPELL ; Remove perk ability                set doOnce to 0            endif        endif        set yourPaper to Pencil01 ; Prevent apple bug        set yourPaper to GetNextRef ; Find the next static world object        Goto 10 ; Loop the loop!    endifEnd


The first bit will run fine if I comment out the RemoveSpell line, but when I let the RemoveSpell line run, the NPTrashHumperSPELL ability won't work correctly (I get the message that it's running, but no stat change). I've tried Dispel and CastImmediateOnSelf with no improvement, as well as changing the spell from Ability to Actor Effect to Disease.

EDIT: Tried ModAV instead of AddSpell and RemoveSpell, and I'm now able to trigger the effect both coming and going. Unfortunately many (not all) of the ShackPaperDebris objects have stopped working with the script, even though the exact same ones worked with the spell version. I'm kind of confused.
User avatar
The Time Car
 
Posts: 3435
Joined: Sat Oct 27, 2007 7:13 pm

Post » Sun Aug 08, 2010 2:33 pm

I don't recognize half of what you wrote. It must be FOSE.

If you were doing it in geckspeak I could prolly fix it for you =p

No matter tho, a fose person will come and help, most likely.
User avatar
Rinceoir
 
Posts: 3407
Joined: Thu Jun 29, 2006 1:54 am

Post » Sun Aug 08, 2010 7:56 am

I don't recognize half of what you wrote. It must be FOSE.

If you were doing it in geckspeak I could prolly fix it for you =p

No matter tho, a fose person will come and help, most likely.

Yeah, sorry about that - I am using FOSE.
User avatar
Alexx Peace
 
Posts: 3432
Joined: Thu Jul 20, 2006 5:55 pm

Post » Sun Aug 08, 2010 10:12 pm

The way your loop is set up with the 'doOnce' variable - you are adding/removing the spell every other loop if there are multiple paper debris in the cell close by.

For a perk, use the Player.AddPerk, btw.

You might want to set up a variable for counting the number of papers nearby in the loop. When the loop is done and the count is > 0 , add the perk, otherwise, remove it.
And you probably should run the ref walk in a quest script in case you are not so it doesn't run every frame - maybe every .25 second or so.
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm

Post » Sun Aug 08, 2010 3:34 pm

The way your loop is set up with the 'doOnce' variable - you are adding/removing the spell every other loop if there are multiple paper debris in the cell close by.

For a perk, use the Player.AddPerk, btw.

You might want to set up a variable for counting the number of papers nearby in the loop. When the loop is done and the count is > 0 , add the perk, otherwise, remove it.
And you probably should run the ref walk in a quest script in case you are not so it doesn't run every frame - maybe every .25 second or so.

Forgive my stupidity, but I'm not sure I'm grasping what you mean. This is a quest script running from the perk. If I remove the perk - the thing that makes the script run - won't the script stop running and be unable to start again? I don't get what's wrong with the doOnce variable either - I believe you that it's screwed up, but I don't know why/where.

Thanks!
User avatar
Allison C
 
Posts: 3369
Joined: Mon Dec 18, 2006 11:02 am

Post » Sun Aug 08, 2010 4:16 pm

This is a quest script running from the perk. If I remove the perk - the thing that makes the script run - won't the script stop running and be unable to start again?


If the perk is starting the quest, removing the perk won't stop the quest. But I think I was a bit hazy about what you are trying to do. Looking at it again - I think what you have is a perk, that starts a quest script, and in this script a loop that checks for items near the player. If the item(s) are there within a certain distance, add a spell to the player. If the items are not there, remove the spell.


I don't get what's wrong with the doOnce variable either - I believe you that it's screwed up, but I don't know why/where.


Say there are two papers within 90 of the player and DoOnce is 0
The Gamemode block of the quest script starts

All of this occurs in One Frame:
GetFirstRef finds the first paper
the 'if yourPaper' is true and the long if statement is true
DoOnce is 0, the paper is within 90, so the spell is added, and DoOnce is set to 1
...the 'else' stuff is skipped
GetNextRef finds the next paper
Goto 10
the 'if yourPaper' is still true and the long if statement is true
BUT doOnce is not zero, so the 'else' code that removes the spell is run

Remember this is all in the same split second frame.

If you re-arrange some things, you can check for the paper and a give enough time for the spell to actually do something if you run your quest script every second or so.

scn NPTrashHumperSCRIPT; Big thanks to otm from the gamesas forums for putting me on the right trackshort doOnceref yourPaper ; yourPaper is gonna be ShackPaperDebris01-05short iPaperCountBegin GameMode	    set iPaperCount to 0    set yourPaper to GetFirstRef 32 1 0 ; Find static world object in cell    Label 10    if yourPaper != 0        if yourPaper.GetIsID ShackPaperDebris01 || yourPaper.GetIsID ShackPaperDebris02 || yourPaper.GetIsID ShackPaperDebris03 || yourPaper.GetIsID ShackPaperDebris04 || yourPaper.GetIsID ShackPaperDebris05            if yourPaper.GetDistance player < 90 ; If the player is close to yourPaper                 set iPaperCount to iPaperCount + 1           endif        endif        set yourPaper to Pencil01 ; Prevent apple bug        set yourPaper to GetNextRef ; Find the next static world object        Goto 10 ; Loop the loop!    endif    if (iPaperCount)       player.AddSpell NPTrashHumperSPELL ; Add perk ability   else      Player.RemoveSpell NPTrashHumperSPELL ; Remove perk ability    endifEnd

User avatar
Neliel Kudoh
 
Posts: 3348
Joined: Thu Oct 26, 2006 2:39 am

Post » Sun Aug 08, 2010 2:13 pm

Beautiful! Oh, you are my hero, sir. It works like a charm. Now I just need to tweak the script processing delay and test some other stuff and I'm set! A script like this, running every second, won't overtax people's machines? That was a worry of mine. Of course the fact that it was running every frame and my laptop wasn't exploding into flames is something of a miracle, considering the state of this computer.

Thanks again, I've learned a lot!

EDIT: It looks like it's gonna need to be running every 0.1 seconds this way - still a huge improvement over the previous "run every frame and don't actually do anything" version, but it makes me worry more about the possible impact on people's computers.
User avatar
Jonathan Egan
 
Posts: 3432
Joined: Fri Jun 22, 2007 3:27 pm

Post » Sun Aug 08, 2010 10:04 pm

Okay, due to my rediscovery of a few additional, much larger paper statics, I had to add some stuff to the code. I want to check this with you just in case there's a much easier way to do this that I haven't found - or in case I'm doing something horrible without realizing it.

 if yourPaper.GetIsID ShackPaperDebris01 || yourPaper.GetIsID ShackPaperDebris02 || yourPaper.GetIsID ShackPaperDebris03 || yourPaper.GetIsID ShackPaperDebris04 || yourPaper.GetIsID ShackPaperDebris05	if yourPaper.GetDistance player < 100 ; If the player is close to yourPaper		set iPaperCount to iPaperCount + 1 ; Count paper	endifelseif yourPaper.GetIsID StreetLitter01 || yourPaper.GetIsID StreetLitterDark01 || yourPaper.GetIsID StreetLitterEdgeShaded01	if yourPaper.GetDistance player < 220		set iPaperCount to iPaperCount + 1	endifelseif yourPaper.GetIsID StreetLitter02 || yourPaper.GetIsID StreetLitterDark02	if yourPaper.GetDistance player < 190		set iPaperCount to iPaperCount + 1	endifendif


I may still want to tweak the StreetLitter01 and ShackPaperDebris03 distances. StreetLitter01 is the only one that isn't more or less round, so there's a big gap where the player is getting the spell's benefits despite not standing on - or even all that close to - the texture. I could probably provide an alternate file that would work better with the script, but that's a whole other aspect of modding that I don't know anything about. I guess I'd just extract the default texture and copy and past stuff around a bit so it's more even?

Also, it is extremely cool to finally see this working. Dodging from trash pile to trash pile in the metro is just as I imagined it. Thanks again.
User avatar
Bloomer
 
Posts: 3435
Joined: Sun May 27, 2007 9:23 pm

Post » Sun Aug 08, 2010 4:22 pm

If you have a large number of items you need to check for, you could make a form list and add them to it, and test against the form list, like:

if yourPaper.IsInList MYPaperFormList


or

set iFormIndex to ListGetFormIndex MYPaperFormList yourPaper     ;iFormIndex will be -1 if not in list



But for the number of items you are checking for now in your IF statements, it probably isn't worth the trouble.
User avatar
[Bounty][Ben]
 
Posts: 3352
Joined: Mon Jul 30, 2007 2:11 pm

Post » Sun Aug 08, 2010 10:03 pm

Okay, cool. Thanks once more!
User avatar
Amelia Pritchard
 
Posts: 3445
Joined: Mon Jul 24, 2006 2:40 am


Return to Fallout 3