Hello!
I m trying to make a random class generator for a bunch of NPCs i made for my mod.
For example:
When the player walks through a trigger, the game will roll random numbers and get a result of 1 to 4. Accoring to that number the NPC will get a different class.
But i really dont know how i can call the ID of that NPC. I mean how to tell the script to change the class of the first NPC.
I made the script below so far but is not working. My game dont crash but not class change occurs.
Attention: NPC is not in game world that moment. He will spawn to the world later, having the class i have rolled for him.
I m using .GetOwner but i dont think its right.
My NPC ID is "PC01"
Can anyone help me plz?
scriptname NPCClasstrigger
short PC01class
ref NPC01
Begin OnTrigger Player
set PC01class to Rand 1 4
set NPC01 to PC01.GetOwner
if PC01Class == 1
NPC01.SetClass Crusader
message "Crusader"
elseif PC01Class == 2
NPC01.SetClass Warrior
message "Warrior"
elseif PC01Class == 3
NPC01.SetClass Warlock
message "Warlock"
elseif PC01Class ==4
NPC01.SetClass Thief
message "Thief"
endif
End
Help of calling a reference
-
BFG
- Champion

- Posts: 902
- Joined: Sat Oct 18, 2008 3:00 am
- ES Games: Morrowind, Oblivion
- Platform: PC/Windows 7 x64, PS3
- Status: Exhilarated
- Location: Rebuilding the lost city of Sutch
Re: Help of calling a reference
I don't know how to do it with the base Construction Set, but if you have OBSE you can use the GetBaseObject command.
- PrinceShroob
- Apprentice

- Posts: 158
- Joined: Wed Mar 17, 2010 7:58 pm
- ES Games: Oblivion, Morrowind
- Platform: Xbox 360, PC
Re: Help of calling a reference
You cannot call "setclass" without a reference, and you cannot find an NPCs class without a reference.
However, taking advantage of the fact that NPC scripts run on the base item without need of a reference, then you can attach a script to the NPC,GameMode that sets the class depending on variables.
For example, if your script rolls that the NPC should be a warlock, then perhaps set a variable to a number, let's call the variable "class" (short variable) and say that it now equals 3. The NPCs script might look like this:
begin Gamemode
short Done
if (TrigZoneRef.class == 1)
setclass Crusader
elseif (TrigZoneRef.class == 2)
setclass Warrior
elseif...
You get the idea.
Be aware that, unlike Morrowind, an NPC will not gain spells automatically and you cannot add a levelled set of spells. Your NPC will have to possess the "LL2Warlock100" / "LL2WarlockLvl100" set in order to be able to cast magic. Thankfully, the Warlock set includes a major and minor destruction spell, and a major restoration spell, same as the crusader set, so the crusader will have appropriate spells. You do not need to worry about the warrior or thief casting spells, even with the levelled set: NPCs will not have spells if their skills are insufficient, the same reason that Falcar and Mercator Hosidus use no spells even though they have the set.
However, taking advantage of the fact that NPC scripts run on the base item without need of a reference, then you can attach a script to the NPC,GameMode that sets the class depending on variables.
For example, if your script rolls that the NPC should be a warlock, then perhaps set a variable to a number, let's call the variable "class" (short variable) and say that it now equals 3. The NPCs script might look like this:
begin Gamemode
short Done
if (TrigZoneRef.class == 1)
setclass Crusader
elseif (TrigZoneRef.class == 2)
setclass Warrior
elseif...
You get the idea.
Be aware that, unlike Morrowind, an NPC will not gain spells automatically and you cannot add a levelled set of spells. Your NPC will have to possess the "LL2Warlock100" / "LL2WarlockLvl100" set in order to be able to cast magic. Thankfully, the Warlock set includes a major and minor destruction spell, and a major restoration spell, same as the crusader set, so the crusader will have appropriate spells. You do not need to worry about the warrior or thief casting spells, even with the levelled set: NPCs will not have spells if their skills are insufficient, the same reason that Falcar and Mercator Hosidus use no spells even though they have the set.
-
Oblis
- Initiate

- Posts: 38
- Joined: Fri May 18, 2007 2:07 pm
- ES Games: Daggerfall, Morrowind, Oblivion
- Platform: PC
- Location: Greece
Re: Help of calling a reference
I made it thanks. With a different way but it worked. I just put the script on every npc stating script so the numbers are rolled just when they spawn. I made a continous loop so the class will not change all the time. I hope this not be - for game speed. Atm i havent face any special problem
As for the spells, i have empty spellbooks for them, so the player will be able to give them spells in game.
(scroll --> spell) Toaster's function.
But i m really think of adding a default spell to them for start, so they will not be useless at start.
Maybe some low lvl fire spell.
As for the spells, i have empty spellbooks for them, so the player will be able to give them spells in game.
(scroll --> spell) Toaster's function.
But i m really think of adding a default spell to them for start, so they will not be useless at start.
Maybe some low lvl fire spell.
