Jump to content

Scripting help


hiTo1337

Recommended Posts

Okay, I'm pretty new to modding in G.E.C.K. Although I'm finding it being pretty easy to learn.

 

Although I have a scripting problem. Let's say I have an interior cell with lots of raiders in it. just regular leveled raiders. Now what kind of script can I do to give an integer +1 everytime any one of those raiders dies?

 

Now remember that ONLY those raiders in that building/cell that should count. I seriously can't find a good solution. But I guess I have to use some kind of reference scripting?

 

Any help would be appreciated :)

Link to comment
Share on other sites

There are many ways to accomplish this:

-The easiest would be to script the raiders themselves, this would require you to make copies of the original raiders and give them a script like this:

 

scn ScriptName

begin ondeath
set YourQuestName.KilledRaiders to YourQuestName.KilledRaiders + 1
end

 

and a quest script with

 

short KilledRaiders

 

-ANOTHER way would be to make a quest script which checks if the raiders are dead, this means that you would have to make all the raiders persistent references and give them unique editorID's:

 

scn QuestScriptName

short KilledRaiders
short raider01killed
short raider02killed
short raider03killed
short raider04killed
;and so on

begin gamemode

if raider01REF.getdead == 1 && raider01killed == 0
set KilledRaiders to KilledRaiders + 1
set raider01killed to 1

elseif raider02REF.getdead == 1 && raider02killed == 0
set KilledRaiders to KilledRaiders + 1
set raider02killed to 1

elseif raider03REF.getdead == 1 && raider03killed == 0
set KilledRaiders to KilledRaiders + 1
set raider03killed to 1

elseif raider04REF.getdead == 1 && raider04killed == 0
set KilledRaiders to KilledRaiders + 1
set raider04killed to 1

;and so on
endif
end

 

Keep in mind that if the raiders respawn it will either mess up your counter or add to it when you kill them again, for this reason I recommend using the first method, making copies and unticking their respawn checkboxes.

Link to comment
Share on other sites

There are many ways to accomplish this:

-The easiest would be to script the raiders themselves, this would require you to make copies of the original raiders and give them a script...

 

Thanks for the quick answer. I actually thought of the first way myself, but it just seemed like a lot of work to copy the lvlraider-kit.

 

Just out of curiosity, how do you make the raiders persistent references? That checkbox is greyed out to me.

 

Btw, I saw somewhere some function called 'IsInList'. Can't you add all the raiders to a list and then do something like

 

if creatureType.killed == Raider && creature.killed.IsInList == SpecialRaiderList
    set raidersKilled to raidersKilled + 1
endif

 

?

Just a thought.

I guess I'm not really familiar with something where you can't access the 'triggering' object (begin OnDeath).

Link to comment
Share on other sites

There are many ways to accomplish this:

-The easiest would be to script the raiders themselves, this would require you to make copies of the original raiders and give them a script...

 

Thanks for the quick answer. I actually thought of the first way myself, but it just seemed like a lot of work to copy the lvlraider-kit.

 

Just out of curiosity, how do you make the raiders persistent references? That checkbox is greyed out to me.

 

Btw, I saw somewhere some function called 'IsInList'. Can't you add all the raiders to a list and then do something like

 

if creatureType.killed == Raider && creature.killed.IsInList == SpecialRaiderList
    set raidersKilled to raidersKilled + 1
endif

 

?

Just a thought.

I guess I'm not really familiar with something where you can't access the 'triggering' object (begin OnDeath).

 

I think the persistent checkbox is always greyed out for actors because they're always persistent. Anyways, the checkbox should still be checked, no?

But yes, copying every raider in the list is a lot of trouble, but I don't think you have to do that. Make a new creature and select the raider leveled list from the template box, tick all the checkboxes except script and then give it the aforementioned script. The raider that will be spawned will now have the script.

Still, most modders would probably prefer the second method, just because scripting is awesome :happy:

Link to comment
Share on other sites

... and about your "script"

 

if creatureType.killed == Raider && creature.killed.IsInList == SpecialRaiderList
set raidersKilled to raidersKilled + 1
endif

 

The problem here isn't the conditions, it's the reference. While you can use

RaiderREF.isinlist SpecialRaiderList == 1

as a condition it doesn't do anything except tell you if that raider is on the list. Every script has to run inside a block, and Fallout just doesn't have blocks that run when the player kills an actor, there's only ondeath and onmurder that run when the scripted actor is killed. Obviously checking if an actor is dead every frame would be a huge waste of computing power. :biggrin:

Link to comment
Share on other sites

with other words, I'll rewrite my wannabe-script to something like this:

 

begin OnDeath theRef

    if theRef.IsInList == SpecialRaiderList

    set raidersKilled to raidersKilled + 1

    endif

end

 

Nope. The "begin OnDeath theRef" runs when the actor who has the script is KILLED by "theREF"

Do as I say and give the raider she script I first presented to you, in any case it won't be necessary to use IsInList with the onDeath block since the game already knows who the raider is because the ondeath block always refers to the actor who has the script, and the only actors who have it are going to be the ones you give it to, right?

scn ScriptName

begin ondeath
set YourQuestName.KilledRaiders to YourQuestName.KilledRaiders + 1
end

 

Do I sound confusing? :sweat:

Link to comment
Share on other sites

Nope. The "begin OnDeath theRef" runs when the actor who has the script is KILLED by "theREF"

Do as I say and give the raider she script I first presented to you, in any case it won't be necessary to use IsInList with the onDeath block since the game already knows who the raider is because the ondeath block always refers to the actor who has the script, and the only actors who have it are going to be the ones you give it to, right?

scn ScriptName

begin ondeath
set YourQuestName.KilledRaiders to YourQuestName.KilledRaiders + 1
end

 

Do I sound confusing? :sweat:

 

 

Nono, I get what you meant earlier now, when you say it like that. I thought that you could make a quest script with my wannabe-script and it would be like "If anyone is killed -> check who got killed -> if it is a raider, add 1 to var.

 

I did however made it like you said the first time, and copied the leveled raiders. Haven't really tried it out yet, hopefully it will work they way I intend it to. Thanks very much for your help :)

Link to comment
Share on other sites

@mazakala:

Please indent your scripts - this makes them much easier to read. If you don't know how to indent your scripts, here is a tool that can do it for you, as well as check your scripts for several structural errors - Script Validator

 

I think the persistent checkbox is always greyed out for actors because they're always persistent.
The "Persistent" checkbox will be greyed out and the actor will be set to persistent by default if the "No Low Level Processing" checkbox is unchecked. The "No Low Level Processing" checkbox, when checked, will prevent an actor's AI from running when the player is not nearby, and as a general rule of thumb should be checked on enemies, as it isn't particularly important whether or not they're following their AI packages to the letter when the player is not nearby, because they'll probably be dead soon after the player finds them anyway.

 

Obviously checking if an actor is dead every frame would be a huge waste of computing power. :biggrin:
Actually, I would expect that GetDead is quite an efficient function, and under most circumstances even the more "CPU-heavy" functions need to be called thousands of times per frame in order to have any noticeable affect on performance. It's always nice to be efficient, but due to the fact that only very high-level functions are available to us almost all optimisation will be related to conditional statements.

 

Every script has to run inside a block, and Fallout just doesn't have blocks that run when the player kills an actor
While it's true that all Object, Effect and Quest scripts must run within a Begin/End block, there are also scripts that do not have this limitation - result scripts. There are two important features of result scripts that make them quite different from other scripts:
  • They do not contain Begin/End blocks
  • Only "ref" variables can be declared in Result scripts

There are also other ways to trigger certain blocks, and I know of one that can cause a GameMode block to run once when a player kills an actor, so long as that actor fits certain conditions. In order to do this, a new perk must be added to the player with an "Entry Point" perk entry of type "Add Leveled Item On Death". I would recommend that the conditions for this perk entry check that the player is in the appropriate cell, and the actor is in the appropriate faction.

 

The leveled item to be added should always be the same item - a scripted token. A token is a piece of armour that has the "Playable" checkbox unticked, to that it will be invisible should the player attempt to view it in the inventory menu. The script on the token would be simple - increment the quest variable then remove itself:

Begin GameMode
set <MyQuest>.iRaiderKillCount to <MyQuest>.iRaiderKillCount + 1
RemoveMe
End

There is a drawback to this method, however. If a raider is killed by anything other than the player, the token will not be added and the script therefore will not run. Although it's a very useful tool and something that I think you should know about, this drawback makes it difficult to rely on.

 

Personally, I would probably create a templated actor (so that its stats remain unchanged) with a simple script containing an OnDeath block that increments your quest variable.

 

Cipscis

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...