Scripting

Old and generally outdated discussions, with the rare hidden gem. Enter at your own risk.

Moderators: Haplo, Lead Developers

Locked
User avatar
Drift3r
Member
Posts: 48
Joined: Thu Aug 13, 2009 8:41 pm
Location: Sea of Ghosts

Scripting

Post by Drift3r »

ok so i can script..i have read scripting for dummies morrowind version...and i have made scripts that work so i can mainly follow how to make them....and i have an idea of what i want but im not sure if its right...(i just found this script in my documents, pretty sure its the right one...)

Begin FightScript
short Fight
endif
if ( GetDistance Mrene_FightrTestScript2 <= 800)
StartCombat Mrene_FightrTestScript2
endif
if ( GetTarget Mrene_FightrTestScript2 == 1 )

if ( GetHealth <= 0 )
StopCombat
AiWander 280 6 0 40 30 20 0 0 0
endif
endif
end

this seem rite i forgot if this is the script i wanted...anyways a basic script to make 2 npcs fight....but does anyone know if u have a companion (follow script) then is there a way to alter it and add it so when by a "rival" guild per se...they start combat? maybe i forgot but maybe some one can tell me what they think...
"Look I'm pulling a Night0205 and doubleposting!" -Haplo
User avatar
Faalen
Developer
Posts: 312
Joined: Wed Jun 18, 2008 5:22 am
Location: America's Dairyland

Post by Faalen »

...

What is it you're trying to do? Your post really doesn't make a whole lot of sense. Also, any answer you get is probably going to come straight out of SFD. Since you have it, you could try reading it.
Q1-77-Tel current progress:
[url=http://tamriel-rebuilt.org/old_forum/viewtopic.php?p=266462#266462]Journals 100% done.[/url]
Practical implementation is now underway.
User avatar
Drift3r
Member
Posts: 48
Joined: Thu Aug 13, 2009 8:41 pm
Location: Sea of Ghosts

Post by Drift3r »

well i read through SFD again... and my friend and i were wondring if anyone could enlighten us as to how we can make two factions, or more fight each other on sight, without us starting the battle...for instances we walk in a room and redoran guards start to attack hlaalu gaurds? is this possible? how? thanks
"Look I'm pulling a Night0205 and doubleposting!" -Haplo
Beave
Developer
Posts: 331
Joined: Sun Nov 02, 2008 2:34 pm

Post by Beave »

As far as I know there isn't any built-in method for making NPC's fight each other. You'll have to code the fight yourself, but you can probably use functions in the game related to factions (I think there's one for faction reaction). But like Faalen said, it should all be in MSFD.
User avatar
The Greatness
Developer
Posts: 358
Joined: Sat May 29, 2010 5:13 pm

Post by The Greatness »

Beave wrote:As far as I know there isn't any built-in method for making NPC's fight each other. You'll have to code the fight yourself, but you can probably use functions in the game related to factions (I think there's one for faction reaction). But like Faalen said, it should all be in MSFD.
Surely 'NPC1->StartCombat, NPC2' would do the trick.
Drift3r wrote:Begin FightScript
short Fight
endif ;you don't need this endif
if ( GetDistance Mrene_FightrTestScript2 <= 800) ;GetDistance should be used with an object
StartCombat Mrene_FightrTestScript2 ;this should be like my example above, unless you actually want StartScript
endif
if ( GetTarget Mrene_FightrTestScript2 == 1 ) ;what?

if ( GetHealth <= 0 ) ;I would use GetDeadCount, which will return 1 when they are dead
StopCombat
AiWander 280 6 0 40 30 20 0 0 0
endif
endif
end
Is Mrene_FightrTestScript2 an NPC? It doesn't sound like one.
Warning: may contain large amounts of sarcasm.

Myzel- We never actually see slaves working on Vvardenfell either. They're always just standing there. If you ask me they deserve a good whipping.
Why
Lead Developer
Posts: 1654
Joined: Sat Jul 04, 2009 3:18 am
Location: Utrecht

Post by Why »

I don't know if Morrowind works like Oblivion in that NPCs start fighting if their Fight value is high enough and their Disposition towards eachother low enough. If yes, you could create a dummy faction with faction reaction of, let's say, -100 towards another faction, and NPCs of these factions should start fighting on sight. But as I said, I don't know if it works that way, taking disposition into account.
Beave
Developer
Posts: 331
Joined: Sun Nov 02, 2008 2:34 pm

Post by Beave »

The Greatness wrote: Surely 'NPC1->StartCombat, NPC2' would do the trick.
That's what I mean. You have to include this because NPC's don't just attack each other based on certain factors.
The Greatness wrote: Is Mrene_FightrTestScript2 an NPC? It doesn't sound like one.
That's my guess, although there was a piece of the code that didn't make sense:

Code: Select all

if ( GetTarget Mrene_FightrTestScript2 == 1 )
    if ( GetHealth <= 0 )
        StopCombat
        AiWander 280 6 0 40 30 20 0 0 0
    endif
endif 
This seems a bit ambiguous to me, because it doesn't make sense for the guy who dies to also stop combat and change their AI package. Is that your intention? Because otherwise, you need to add "Mrene_FightrTestScript2->" to either "GetHealth" or the two functions so that the guy who survives goes back to wander.
MMMowSkwoz
Developer
Posts: 835
Joined: Mon Oct 27, 2008 11:18 pm
Location: London

Post by MMMowSkwoz »

The Greatness wrote:'NPC1->StartCombat, NPC2' would do the trick.
This will only make 2 NPCs fight. I think the OP wanted to create a battle with 2 factions. The trouble you get is if you have them fighting in pairs, so a whole set of duels. Once the duel is over, the winner just stands there, ruining the impression of a large battle.

You need to have a script on each NPC that says:

Code: Select all

If person A not dead
    Fight person A
Else If person B not dead
    Fight person B
Else If ... etc
(obviously this is not actual code!)

The trouble is the scripts would be different for every NPC (a whole lot of effort). We actually have this implemented in TR in a tomb in Map2 I belive, although I can't remember the location. I tweaked the code and was quite proud of the solution - they are split into groups of fighters, which then cycle through the enemies in the opposing faction just as per the above script. However, they all use the same script: which enemy they start with depends on their initial X-coordinate (so they are unique and all initially attack a different enemy).

You might want to test Why's idea, because that would be a nice solution, but I have a feeling that doesn't work in Morrowind.

Edit: found it. It's called "Norem", just East of Windmoth Legion Fort. The main battle takes place in the cell "Norem, Interior" (although the others also have similar battles). The related scripts are prefixed "TR_m2_Norem_" and are all commented, so you should be able to see how it's set up.

Edit 2: The suggestion of using GetDistance might not be a good idea because if you have multiple scripts running in the same cell all calling GetDistance each frame, that could cause some lag.
MaMeeshkaMowSkwoz - choose your syllables
Why
Lead Developer
Posts: 1654
Joined: Sat Jul 04, 2009 3:18 am
Location: Utrecht

Post by Why »

Yeah, I doubt my idea works, but it's worth trying.

Another thing you could do if you want a large battle, make one side AIFollow one NPC, the other side AIFollow another NPC, and have the two NPCs start combat. That should result in everyone fighting everyone.
MMMowSkwoz
Developer
Posts: 835
Joined: Mon Oct 27, 2008 11:18 pm
Location: London

Post by MMMowSkwoz »

Why wrote:Another thing you could do if you want a large battle, make one side AIFollow one NPC, the other side AIFollow another NPC, and have the two NPCs start combat. That should result in everyone fighting everyone.
Inspired idea! But how would you deal with one of the "leaders" dying?
MaMeeshkaMowSkwoz - choose your syllables
User avatar
The Greatness
Developer
Posts: 358
Joined: Sat May 29, 2010 5:13 pm

Post by The Greatness »

MMMowSkwoz wrote:
Why wrote:Another thing you could do if you want a large battle, make one side AIFollow one NPC, the other side AIFollow another NPC, and have the two NPCs start combat. That should result in everyone fighting everyone.
Inspired idea! But how would you deal with one of the "leaders" dying?
Hopefully as they had already started fighting they wouldn't just stop and stand still.
Warning: may contain large amounts of sarcasm.

Myzel- We never actually see slaves working on Vvardenfell either. They're always just standing there. If you ask me they deserve a good whipping.
Why
Lead Developer
Posts: 1654
Joined: Sat Jul 04, 2009 3:18 am
Location: Utrecht

Post by Why »

I *think* that once they initiate combat, they won't stop until the other side is down, since when the leader is attacked, all his followers initiate combat with the attacker, as a result of which all the attacker's followers initiate combat with all his attackers. If not, everyone from one side should follow eachother, that should work too but requires some more coding.
User avatar
Drift3r
Member
Posts: 48
Joined: Thu Aug 13, 2009 8:41 pm
Location: Sea of Ghosts

Post by Drift3r »

Why wrote:I *think* that once they initiate combat, they won't stop until the other side is down, since when the leader is attacked, all his followers initiate combat with the attacker, as a result of which all the attacker's followers initiate combat with all his attackers. If not, everyone from one side should follow eachother, that should work too but requires some more coding.
well i tried something like this...except different in a sense..i used the mod *give your orders* and had a group of followers redoran guards follow me..i proceeded to punch a hlaalu guard and the group of guards not after me talked to me and i resisted arrest they attacked me and i levitated away...after a short distance they redirected there attention to the redoran and began to fight both individually and double teaming each other...i dont know if this holds any hidden coding secrets other wise is this how a battle supposed to run..i would like this but without my involvment (hiring guards)..
"Look I'm pulling a Night0205 and doubleposting!" -Haplo
User avatar
The Greatness
Developer
Posts: 358
Joined: Sat May 29, 2010 5:13 pm

Post by The Greatness »

Drift3r wrote:
Why wrote:I *think* that once they initiate combat, they won't stop until the other side is down, since when the leader is attacked, all his followers initiate combat with the attacker, as a result of which all the attacker's followers initiate combat with all his attackers. If not, everyone from one side should follow eachother, that should work too but requires some more coding.
well i tried something like this...except different in a sense..i used the mod *give your orders* and had a group of followers redoran guards follow me..i proceeded to punch a hlaalu guard and the group of guards not after me talked to me and i resisted arrest they attacked me and i levitated away...after a short distance they redirected there attention to the redoran and began to fight both individually and double teaming each other...i dont know if this holds any hidden coding secrets other wise is this how a battle supposed to run..i would like this but without my involvment (hiring guards)..
What happened there is that first and foremost all gaurds are scripted to try and arrest you if you break the law. Why not try the same thing again but attack some bandits so you're not breaking the law. And please don't put so many '...'s. Just one is fine.
Warning: may contain large amounts of sarcasm.

Myzel- We never actually see slaves working on Vvardenfell either. They're always just standing there. If you ask me they deserve a good whipping.
Locked