Can't get script to compile

Post » Sat May 28, 2011 5:11 am

I'm trying to write my first script and any help would be greatly appreciated, I have 0 experience with programming.

scn companionstealthboy

Ref rTeamStealthboy

begin MenuMode

set rTeamStealthboy to GetPlayerTeammate

if player.IsSpellTarget StealthBoy
rTeamStealthboy.AddSpell StealthBoyInvisibilitySpell
else
rTeamStealthboy.RemoveSpell StealthBoyInvisibilitySpell
endif

end


I know that line 7:

set rTeamStealthboy to GetPlayerTeammate

Needs to be changed to an explicit reference, as it is a quest script. An explicit reference would be something that points to a paticular ID (like Player), right? So does that mean for this script I can't use a set variabe?

What are my options?
User avatar
Mélida Brunet
 
Posts: 3440
Joined: Thu Mar 29, 2007 2:45 am

Post » Sat May 28, 2011 7:35 pm

Another question, I'm working on an object script for light armour. If I use Begin OnEquip will that start whenever the NPC spawns? I'm assuming that when an NPC spawns it'll automatically equip his/her best armour. Or perhaps they spawn with the armour already equipped so there's no equip action for OnEquip to latch onto?
User avatar
Bee Baby
 
Posts: 3450
Joined: Sun Jun 18, 2006 4:47 am

Post » Sat May 28, 2011 9:03 am

GetPlayerTeammate is used to check if a specific reference is set to playerteammate. Unless you want to use the reference id of the companion I don't think a quest script is going to work for this. You could add an item to the companion with a script attached to it. Not sure why you are using menumode, I think gamemode would be required for this to work properly. You could also just make it part of the companions script unless you don't want to edit them, which is understandable.

I'm not sure about the onequip question. It's easy to test though, just put a showmessage (or print to console if using NVSE) in the onequip block and see when it displays.
User avatar
Mr. Ray
 
Posts: 3459
Joined: Sun Jul 29, 2007 8:08 am

Post » Sat May 28, 2011 1:29 pm

GetPlayerTeammate is used to check if a specific reference is set to playerteammate. Unless you want to use the reference id of the companion I don't think a quest script is going to work for this. You could add an item to the companion with a script attached to it. Not sure why you are using menumode, I think gamemode would be required for this to work properly. You could also just make it part of the companions script unless you don't want to edit them, which is understandable.


I do want to use the reference id of the companion/team mate, I was hoping to just add one effect and script to the stealth boy so that it would affect every person who is a current member of playerteammate, vanilla permanent companions, temporary companions and companions added by new mods and DLC, instead of having to alter the script for every NPC who can follow the PC.

The goal of the script is to make everyone who is a member of playerteammate have a stealth field (and benefit from stop combat alarm) when the PC uses a stealth field.


I'm not sure about the onequip question. It's easy to test though, just put a showmessage (or print to console if using NVSE) in the onequip block and see when it displays.


Aahh, that's useful, I'll have to test that shortly, thank you. There was something else I wanted to test out and that'll make it a thousand times easier.
User avatar
Poetic Vice
 
Posts: 3440
Joined: Wed Oct 31, 2007 8:19 pm

Post » Sat May 28, 2011 1:16 pm

You can add a script to the stealthboy that ref walks the near by cells, and uses the GetPlayerTeammate function. You would have to use NVSE. I'll take a closer look at the stealthboy and try to come up with a script if you need.
User avatar
Tina Tupou
 
Posts: 3487
Joined: Fri Mar 09, 2007 4:37 pm

Post » Sat May 28, 2011 12:24 pm

You would think that there should be an easy way to get the reference of the current teammate. In standard FNV, there isn't. For an example, see the Gomorrah elevator script. It has a big "case statement" which lists each possible companion. It is possible there is a NVSE command to do this, but I don't think so. Anyway, there are a number of mods which allow you to have a large/unlimited number of companions. So any such command would need to return a list, and you would need to do this for each NPC on the list.

For a partial solution, clone the Gomorrah elevator script. I don't think there is a perfect solution.
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Sat May 28, 2011 3:02 pm

You can add a script to the stealthboy that ref walks the near by cells, and uses the GetPlayerTeammate function. You would have to use NVSE. I'll take a closer look at the stealthboy and try to come up with a script if you need.


Thank you, that'd be great. I've not used NVSE yet, but now is as good a time as any to start.

For a partial solution, clone the Gomorrah elevator script. I don't think there is a perfect solution.


Alright, I'll hav to look into that, thanks.


I've got (yet) another question.

If I attach a script to a piece of armour that uses without a reference, would that add the perk to the NPC equipping the armour or to the PC? If the latter, is there a that returns the ID of the NPC equipping the armour?

I want to add a perk to light armour wearing NPCs to make them move faster depending on their level. The perk, it's script and effects are finished, it's just applying it. Failing that, is there a that returns the ID of all NPCs wearing light armour?
User avatar
Adriana Lenzo
 
Posts: 3446
Joined: Tue Apr 03, 2007 1:32 am

Post » Sat May 28, 2011 9:37 am

I am not sure a perk is the best way to add an armor effect. If you look at some of the existing armors with "magic effects" like the powered armor, they use an object effect. There are many existing ones to choose from and you can make your own.

If you use addperk or any other command which takes a reference, and you don't give a reference, it uses the object which activated the script. This would apply the perk to the armor, which is not what you want. You can use "set rRef to getcontainer" to get the owner (container) of the armor.
User avatar
Lance Vannortwick
 
Posts: 3479
Joined: Thu Sep 27, 2007 5:30 pm

Post » Sat May 28, 2011 5:16 pm

Ok what I have done is to create a new base effect with a script effect and the following script...
scn StealthScriptref npcbegin scripteffectstartset npc to getfirstref 200 1label 10if(npc)   if(npc.getplayerteammate)     npc.CastImmediateOnSelf StealthboyCompanion   endif   set npc to ArmorCombat   set npc to getnextref   goto 10endifendifend


I added this effect to the stealth boy with a 2 second duration, though the duration may not be important since it loops.

The SlealthboyCompanion is just a new ingestible that was a copy of the normal stealthboy without the new script effect.

If I attach a script to a piece of armour that uses without a reference, would that add the perk to the NPC equipping the armour or to the PC? If the latter, is there a that returns the ID of the NPC equipping the armour?


Use getcontainer to return the NPC equipping an item.

I want to add a perk to light armour wearing NPCs to make them move faster depending on their level. The perk, it's script and effects are finished, it's just applying it. Failing that, is there a that returns the ID of all NPCs wearing light armour?


Don't think this is really doable without ref walking new areas each time the player changes cells, or scripting all light armors. Not very practical I think.
User avatar
Fam Mughal
 
Posts: 3468
Joined: Sat May 26, 2007 3:18 am

Post » Sat May 28, 2011 6:44 pm

Ok what I have done is to create a new base effect with a script effect and the following script...
scn StealthScriptref npcbegin scripteffectstartset npc to getfirstref 200 1label 10if(npc)   if(npc.getplayerteammate)     npc.CastImmediateOnSelf StealthboyCompanion   endif   set npc to ArmorCombat   set npc to getnextref   goto 10endifendifend


I added this effect to the stealth boy with a 2 second duration, though the duration may not be important since it loops.

The SlealthboyCompanion is just a new ingestible that was a copy of the normal stealthboy without the new script effect.



I just had a look at the NVSE commands, I get what getfirstref is for, but what's the purpose of " 200 1" and what does setting the npc variable to "ArmorCombat" do?


Use getcontainer to return the NPC equipping an item.


If you use addperk or any other command which takes a reference, and you don't give a reference, it uses the object which activated the script. This would apply the perk to the armor, which is not what you want. You can use "set rRef to getcontainer" to get the owner (container) of the armor.


Ugh, now I feel like a complete idiot, I must have glanced pass that link in the wiki a 100 times today...



or scripting all light armors. Not very practical I think.


Yeah, that's what I was going to do. It'd be time consuming adding it to armours that already have a script, but it's the only option coming to mind.


I am not sure a perk is the best way to add an armor effect. If you look at some of the existing armors with "magic effects" like the powered armor, they use an object effect. There are many existing ones to choose from and you can make your own.


I had considered that, but I didn't want the PC to be affected.

Thanks guys, you've been very helpful.
User avatar
Dean
 
Posts: 3438
Joined: Fri Jul 27, 2007 4:58 pm

Post » Sat May 28, 2011 4:09 pm

I just had a look at the NVSE commands, I get what getfirstref is for, but what's the purpose of " 200 1" and what does setting the npc variable to "ArmorCombat" do?


The 200 tells the script to scan for actors only, and the 1 is the cell depth which in this case is the players cell and 8 adjacent cells.

Setting the reference to an object between calls prevents an error that can cause crashes from what I understand. It can be any object I just used the armor.

Edit: BTW in my version I added another check to the script that only allows companions to stealth if they have a stealthboy in their inventory. Don't know if that's useful to you of not but you just need to add this if so...

if(npc.getplayerteammate)
if npc.getitemcount stealthboy >= 1
npc.CastImmediateOnSelf StealthboyCompanion
npc.removeitem stealthboy 1
endif
endif

Edit2: Forgot to remove the stealthboy from the companion, fixed above now :P
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm

Post » Sat May 28, 2011 11:10 am

The 200 tells the script to scan for actors only, and the 1 is the cell depth which in this case is the players cell and 8 adjacent cells.

Setting the reference to an object between calls prevents an error that can cause crashes from what I understand. It can be any object I just used the armor.

Edit: BTW in my version I added another check to the script that only allows companions to stealth if they have a stealthboy in their inventory. Don't know if that's useful to you of not but you just need to add this if so...

if(npc.getplayerteammate)
if npc.getitemcount stealthboy >= 1
npc.CastImmediateOnSelf StealthboyCompanion
endif
endif


That's brill, thanks for all the help.
User avatar
Megan Stabler
 
Posts: 3420
Joined: Mon Sep 18, 2006 2:03 pm


Return to Fallout: New Vegas