Setting NPC ID as Varible

Post » Fri Jun 24, 2011 10:58 pm

Is it possible, through direct or work around methods, To set NPC ID as variables, or be able to get the npcs ID so that you don't have to have scripts on each npc?
My idea is that when you cast a certain spell, a global script starts and gets the npc id. Then, that id is .. "npcI.D.->sethealth 0" or something like that. I got the idea from words of power in Forgotten Realms. Is this at all possible, through normal scripting, MWSE, or otherwise?

I understand that MWSE has the function "xGetBaseID" but I don't know how to mod with MWSE or if that would even work? Any tips appreciated!
User avatar
DarkGypsy
 
Posts: 3309
Joined: Tue Jan 23, 2007 11:32 am

Post » Sat Jun 25, 2011 7:00 am

You would need to use MWSE to get an NPC's id if you don't want to have it hard coded.
User avatar
Leticia Hernandez
 
Posts: 3426
Joined: Tue Oct 23, 2007 9:46 am

Post » Fri Jun 24, 2011 9:18 pm

Oh yes, it's certainly possible with MWSE. You want xRefID instead of xGetBaseID though. ;)

So what is it exactly that you want to accomplish? Step by step through the whole thing....we can then take a look at what you need to look into to get it working.
User avatar
mike
 
Posts: 3432
Joined: Fri Jul 27, 2007 6:51 pm

Post » Sat Jun 25, 2011 3:50 am

Oh yes, it's certainly possible with MWSE. You want xRefID instead of xGetBaseID though. ;)

So what is it exactly that you want to accomplish? Step by step through the whole thing....we can then take a look at what you need to look into to get it working.

I want it so that when the player cast a spell, which we can ID as "stc_deathspell", the target's health is set to 0, meaning that the target always dies. To prevent over balancing, I want to have a random factor in there that will have one-tenth a chance of killing the player instead of the target, so that player's can't abuse it.
To go about this i figured i would need MWSE, but I am clueless as to how I mod with it. Do i just use the functions when writing the script and play with it turned on, or write it in some special program? But To make it work I figured I would have a global script, which detects the spell being cast. When the spell is cast, the global will choose a number from 1-10, and if it is 10, the player dies, else the global get's the target's id, which it sets to a variable. The variable is then sethealth to 0.
I'm not sure if that's possible though.
; Let's assume that "dog" is the npc. Could it work like this? NOTE: I am aware that this won't work, I just mean the conceptbegin globalshort targetset target to xRefIDif ( player->getspelleffects, "stc_deathspell" == 1 )     target->sethealth 0else     returnendifend


I don't know if you can set variable "health" which is one of the reasons I asked here.

So, is that clear enough? I can't really think of much other stuff I need to say but I will say it if you need it :)

BUT MOST IMPORTANTLY...
How do I write script for MWSE?..
I went http://mwse.wikispaces.com/home to get it, but it says the link for the modders version is invalid :/ Also, will MWSE have to run in the background? I have the MGE internal version
User avatar
Connie Thomas
 
Posts: 3362
Joined: Sun Nov 19, 2006 9:58 am

Post » Sat Jun 25, 2011 1:52 am

All right, let's start with how to write MWSE scripts. The Construction Set won't compile with MWSE functions, so you have to use MWEdit. Get that here: http://sourceforge.net/projects/mwedit/files/mwedit/v0.6.1%20-%20Minor%20Update/mwedit-0.6.1.zip/download

Install MWEdit, then get a few support files. First, you need http://www.fliggerty.com/phpBB3/viewtopic.php?f=53&t=1379 Put that in the MWEdit directory, overwriting the one that is already there. Then grab http://dl.dropbox.com/u/31576251/mweditextrafile.esp and put it in your Data Files folder.

Now open up MWEdit and go into the options. Set "Game Data Path" to your Data Files directory. Then put a check in "Extra Script Records" and browse to the mweditextrafile.esp that you downloaded. Finally make sure "Allow Extended Functions" and "Allow Bloodmoon/Tribunal Features" are checked.

Now when you load your mod, you don't load the masters like you would in the CS. Just load your mod. If you are compiling a script that references an object or variable or something that is in one of the esm files, it will fail; but then all you have to do is add it into mweditextrafile.esp. Anything in that can be referenced when MWEdit compiles your scripts.

----------------------

Moving on. Now that you know how to set up MWEdit, use it to write your scripts. I use it for all of my scripts because I like the syntax highlighting and the compiler has more descriptive errors and catches some things the CS misses.

Okay, so to accomplish what you want to do, we have to get the reference to the NPC that you hit with the spell. This is impossible without MWSE, and still somewhat tricky with MWSE. Fortunately I've done this very thing a lot. What we have to do is loop through all of the NPC references in the current cell and look for one that has your spell active.

I will assume you've already determined when the spell is cast and use that to start our script.

In order to loop through the cell, we use the functions xFirstNPC and xNextRef. xFirstNPC will get the reference to the first NPC (or creature actually) in the cell. xNextRef will use that reference we have and get the next one in the list.

The following is a script that will loop through the cell and display the names and health of all the NPCs in the cell.

begin loop_examplelong npcreflong tempfloat healthshort stateif ( MenuMode )     Returnendififx ( state ) ;we set this to 1 when the script needs to end     set state to 0     set npcref to 0     StopScript "loop_example"     Returnelse     ;this is the first thing that will happen when the script is run     ifx ( npcref )          ;npcref contains a reference, let's get the next reference          setx npcref to xNextRef npcref     else          ;npcref is 0, so we get the first reference          setx npcref to xFirstNPC     endif     if ( npcref == 0 )          ;if npcref equals 0 after we called xNextRef, it means we got to the end of the list, so we need to end the script          set state to 1          Return     endif     ;we have a reference, let's make sure it is an NPC and not a creature     setx ltemp to npcref->xRefType     if ( ltemp != 1598246990 ) ;this is the code for NPC          ;not an NPC, let's move on to the next frame and the next reference          Return     endif     ;we have an NPC reference here, let's get the name and health and display it     setx ltemp to npcref->xGetName     ;the function GetHealth is not an MWSE function, so it doesn't accept variables; we have to wrap it with xSetRef     xSetRef npcref     set health to GetHealth     ;now display the name string and the health using xMessageFix     xMessageFix "%s has %f health remaining." ltemp health     MessageBox "                                                                                   "  ;xMessageFix has to be followed with MessageBoxend


So that ought to give you an idea of how to loop through the cell and work with every NPC. Let's see what you can do from here. Let me know if you need health with the next step.
User avatar
Jynx Anthropic
 
Posts: 3352
Joined: Fri Sep 08, 2006 9:36 pm


Return to III - Morrowind