Wolvman's Scripting Questions

Post » Thu Jan 14, 2010 3:53 pm

Instead of making a billion different threads I'm just gonna stick with this one to keep the thread number down.

Right now I've been wondering how to make this code have a very small random percent chance to give the player a disease. I know how to add a disease to the player on the first activation but how do I make it randomly do it after multiple activations.

if ( OnActivate == 1 )	if ( GetHealth < 1 );the NPC is dead.	   return  endifendif

User avatar
Michelle davies
 
Posts: 3509
Joined: Wed Sep 27, 2006 3:59 am

Post » Thu Jan 14, 2010 12:52 pm

See the random function (MWSFD)
User avatar
Sami Blackburn
 
Posts: 3306
Joined: Tue Jun 20, 2006 7:56 am

Post » Thu Jan 14, 2010 1:19 pm

Something like:

if (random100 > 60) then	do somethingelseif (random100 > 40) then	do something elseelse	do something elseendif


I think random100 is a global that gets changed to a random number each frame.
User avatar
Karl harris
 
Posts: 3423
Joined: Thu May 17, 2007 3:17 pm

Post » Thu Jan 14, 2010 2:38 pm

Thanks for the help, I didn't think MWSFD went over this subject. Anyways, I got it figured out and it seems to be working fine however I used this method instead.

short diseaseif ( OnActivate == 1 )if ( GetHealth < 1 );the NPC is dead.set disease to random 10returnendifendif	If ( Disease == 7 )		If ( player->getspell, "snowwerewolf blood" == 0 )			If ( player->getspell, "timberwerewolf blood" == 0 )				If ( player->getspell, "werewolf blood" == 0 )					If ( player->getspell, "werebear blood" == 0 )						If ( player->getspell, "wereboar blood" == 0 )							If ( player->getspell, "werecroc blood" == 0 )								If ( player->getspell, "werelion blood" == 0 )									If ( player->getspell, "werevult blood" == 0 )										If ( player->getspell, "wereshark blood" == 0 )										player->addspell "werewolf blood"									Messagebox, "You have contracted Sanies Lupus"endifendifendifendifendifendifendifendifendifendif


It looks a bit different than your approach Danjb so I'm not sure if my setup is the best way to go. Is the way I did it ok?

I also have another question that's a bit more complicated than the last. I'm wanting to make a script that does damage everytime you activate someone (or a creature) in both combat and out of combat, but then you have to wait a few seconds after each press of the key before it has an effect on anything again. Is there an easier way to do this than to give every single NPC/Creature a script that deals with OnActivate in it? I know about the XNextRef and XFirstNPC functions using MWSE ,but I have yet to figure out how to get them to work.
User avatar
Tiff Clark
 
Posts: 3297
Joined: Wed Aug 09, 2006 2:23 am

Post » Thu Jan 14, 2010 10:36 pm

Hmm that is a strange script but it should work. your saying if the disease is 7 out of a possible 10 then it should work. Im not good with random so im not sure but dont you need to get rid of the space? Could you test it??
User avatar
Megan Stabler
 
Posts: 3420
Joined: Mon Sep 18, 2006 2:03 pm

Post » Thu Jan 14, 2010 5:52 pm

Yep, it works fine. I was just wondering if it might cause some issues doing it my way :shrug: .
User avatar
Darlene DIllow
 
Posts: 3403
Joined: Fri Oct 26, 2007 5:34 am

Post » Thu Jan 14, 2010 10:54 pm

I dont think so. :P i like the script better its far more organized.

However what is the werewolf command for if the player is a werewolf during the day.
User avatar
FLYBOYLEAK
 
Posts: 3440
Joined: Tue Oct 30, 2007 6:41 am

Post » Thu Jan 14, 2010 6:23 pm

What do you mean exactly?
User avatar
Amelia Pritchard
 
Posts: 3445
Joined: Mon Jul 24, 2006 2:40 am

Post » Thu Jan 14, 2010 10:05 am

Oh nevermind i figured it out i meant what was the command (PCwerewolf) i found it on uespcommands.
User avatar
Jessica Colville
 
Posts: 3349
Joined: Wed Oct 18, 2006 6:53 pm

Post » Thu Jan 14, 2010 12:01 pm

I also have another question that's a bit more complicated than the last. I'm wanting to make a script that does damage everytime you activate someone (or a creature) in both combat and out of combat, but then you have to wait a few seconds after each press of the key before it has an effect on anything again. Is there an easier way to do this than to give every single NPC/Creature a script that deals with OnActivate in it? I know about the XNextRef and XFirstNPC functions using MWSE ,but I have yet to figure out how to get them to work.

Do you want to damage the player or everything around the object that's activated? If it's the former, then you can apply damage directly to the player. If it's the later, then you can use the ExplodeSpell command that Tribunal added. I used the later in my lightning strike mod.
User avatar
Mandi Norton
 
Posts: 3451
Joined: Tue Jan 30, 2007 2:43 pm

Post » Thu Jan 14, 2010 1:16 pm

Actually I'm wanting to just damage the NPC/Creature that gets activated by the player. I don't know how to get timers to work right yet so I was wondering about that as well, in order to make sure the player doesn't over do the damage by rapidly activating everything.
User avatar
Laura
 
Posts: 3456
Joined: Sun Sep 10, 2006 7:11 am

Post » Thu Jan 14, 2010 11:13 am

Timers refer to MWSFD i cant help you becuase i also have many problems with timers. As for creatures you could make a script
If ( Onactivate == 1 )
Cast " "
endif
end

You need to work with it but its a pretty simple script. You should use spells rather then using scripts commands but if you want script commands refer to this uesp page.
http://www.uesp.net/morrow/editor/mw_cscommands.shtml
You also need to add doonce to the script and you have to set doonce back to 0 at the end of the script so that it will happen agian. Should be a fairly simple script.
User avatar
john palmer
 
Posts: 3410
Joined: Fri Jun 22, 2007 8:07 pm

Post » Thu Jan 14, 2010 11:38 am

Yes but wouldn't I have to place that script on every single actor that I wanted this script to work on?
User avatar
k a t e
 
Posts: 3378
Joined: Fri Jan 19, 2007 9:00 am

Post » Thu Jan 14, 2010 11:52 am

Uh i think. their is ways of making it so all the npc's follow the script ( think of VE ) but i havent discovered it yet....
User avatar
Céline Rémy
 
Posts: 3443
Joined: Sat Apr 07, 2007 12:45 am

Post » Thu Jan 14, 2010 5:41 pm

Darn, I think I should probably use the XNextRef script on this part and then add the script through that, but I still don't understand how that works either.
User avatar
michael danso
 
Posts: 3492
Joined: Wed Jun 13, 2007 9:21 am

Post » Thu Jan 14, 2010 9:47 am

Yes but wouldn't I have to place that script on every single actor that I wanted this script to work on?

You would need to put the script on every creature that you want to damage. As Wolf pointed out, you can use that bit of scripting. Make a custom spell that damages the creature with whatever effect you want if you want a visual effect, otherwise just reduce their health (ModHealth, -#). As for timers, it's set timer to ( timer + GetSecondsPassed ). Timer is a float variable that you have to declare first. As with any variable, you can call it whatever you want. Here's an example script:

Begin example_scriptshort doOncefloat timerif ( MenuMode == 1 ); If the player has their inventory open, don't run the timer portion of the script.	return endifif ( doOnce == 1 )   if ( timer <= 10 ); timer is less than ten seconds - set higher or lower as desired. This is the amount of time that must pass before the player can damage the creature again.	   set timer to ( timer + GetSecondsPassed )   else;time's up.	  set doOnce to 0;allow the player to damage the creature again.	  set timer to 0;reset the timer.  endifendfiif ( OnActivate == 1 )	if ( doOnce == 0 )	   ExplodeSpell "spell_id";requires Tribunal or Bloodmoon.	   set doOnce to 1	 endiendifEnd


If you go with ModHealth, use that in place of ExplodeSpell.
User avatar
Dustin Brown
 
Posts: 3307
Joined: Sun Sep 30, 2007 6:55 am

Post » Thu Jan 14, 2010 10:35 am

Wow, thanks for the script Jac. However, I can't place this script on each individual creature and NPC as that would cause an insane amount of conflicts with other mods. I was thinking of alternatives to this and was wondering about using the MWSE function xGetPCTarget and then set the script to start for the player if he presses the 'G' key (I already know how to do the key part). It would need a distance function added in to make sure the actor is within the players reach, but I'm not even sure if XGetPCTarget works on actors. What do you guys think I should do?

BTW, this is the script that allows lycanthropes to fake bite incase you were wondering.
User avatar
Dezzeh
 
Posts: 3414
Joined: Sat Jun 16, 2007 2:49 am

Post » Thu Jan 14, 2010 5:29 pm

This is the code I'm using for the howling.

Begin Were_Howl	short KeyRef	short DoOnce	short Howl	short DoOnce2	float timer	short Swimming	float PosZ	float Water	if ( scriptrunning, Were_BecomeLycanthrope == 1 )		return	endif	if ( scriptrunning, Were_BecomeHuman == 1 )		return	endif	if ( menumode == 1 )		return	endif	setx KeyRef to xKeyPressed, 86	if ( KeyRef == 0 )		if ( DoOnce == 1 )			set DoOnce to 0		endif		return	endif	if ( DoOnce == 1 )		return	endif	Set PosZ to ( Player->GetPos Z )	Set Water to ( GetWaterLevel )	set DoOnce to 1	if ( PosZ <= Water - 130 )player->stopsound, "Werewolf Howl 1"player->stopsound, "Werewolf Howl 2"player->stopsound, "Werewolf Howl 3"returnendifif ( DoOnce2 == 0 )	set DoOnce2 to 1endifIf ( DoOnce2 == 1 )Player->playsound, "Werewolf Howl 1"set DoOnce2 to 2returnendifIf ( DoOnce2 == 2 )Player->playsound, "Werewolf Howl 2"set DoOnce2 to 3returnendifIf ( DoOnce2 == 3 )Player->playsound, "Werewolf Howl 3"set DoOnce2 to 0returnendifend

User avatar
Danger Mouse
 
Posts: 3393
Joined: Sat Oct 07, 2006 9:55 am

Post » Thu Jan 14, 2010 7:30 pm

If you want to make the player not be able to howl after a set of time its a pretty basic script.
You could make a global and make it so that once the howl is starts it sets that global to 1 and in order to howl it needs to be 0. Then you need to make it so that after 10 seconds it sets the howl global back to 0 causing the player to howl agian ( playsound ) :P
User avatar
Marta Wolko
 
Posts: 3383
Joined: Mon Aug 28, 2006 6:51 am

Post » Thu Jan 14, 2010 2:04 pm

NM The question has been answered.
User avatar
how solid
 
Posts: 3434
Joined: Mon Apr 23, 2007 5:27 am

Post » Thu Jan 14, 2010 11:34 pm

Mabye you could make it in the equipment slot ( perhaps shirt ) and make it so when it is equiped it gets rid of it plays the eating sound and adds the spell? The only downside is it would be under apperal. Mabye try a key? ( as its under misc )
EDIT: Sry i meant to say lockpick
User avatar
Lauren Denman
 
Posts: 3382
Joined: Fri Jun 16, 2006 10:29 am

Post » Thu Jan 14, 2010 12:06 pm

Ya but wouldn't that mean that it would quickly disarm your character since lockpicks take up the weapon slot?
User avatar
Steeeph
 
Posts: 3443
Joined: Wed Apr 04, 2007 8:28 am

Post » Thu Jan 14, 2010 6:42 pm

Yah it would. Its probably the only thing you can do exept. Ive never tried this but accordin to that uesp commands AIactivate makes an npc drink a potion. Mabye you could use activate on the player?
User avatar
Vincent Joe
 
Posts: 3370
Joined: Wed Sep 26, 2007 1:13 pm

Post » Fri Jan 15, 2010 12:05 am

I've got another quick question. How do I use a timer that reads in-game hours instead of real-life seconds.

Here's an example code usng real-life seconds. I want to make it use a certain number of in-game hours instead of the 500 seconds.

	If ( DoOnce2 == 1 )		If ( randomizer == 3 )			If ( player-> getwillpower > 85 ) 				If ( player-> getwillpower <= 90 ) 					if ( timer <= 500 )						set timer to ( timer + GetSecondsPassed )					else						startscript, "Were_BecomeHuman"						set timer to 0						set DoOnce2 to 0						set randomizer to random 5					endif				endif			endif		endif	endif

User avatar
Scared humanity
 
Posts: 3470
Joined: Tue Oct 16, 2007 3:41 am

Post » Thu Jan 14, 2010 5:20 pm

I am having difficulty imagining why you require this unless you are running the timer on a local script and you want to account for the player leaving the cell. The calendar fix introduced by the Morrowind Code Patch has rendered local day-counters pretty unreliable so global scripts are pretty much a must. A global script could still count seconds making the need to track Gamehour passage unnecessary (and unnecessarily complicated).

It is not clear if you want the game-equivalent of 500 real-time seconds, but at the default timescale of 30 that would be 4.167 gamehours.

This business becomes problematic if the timer is started after 19.833 hours since it will require the timer run into the next day. That in itself if not a problem, but if the player leaves the cell in which a local timer is running you will require a method of keeping track of the day and month (see first paragraph). You could cut a few corners if you are willing to take a chance of your script working most of the time.

float targetHourshort currentDayif ( whatever == 1 )   set whatever to 2   set currentDay to Day   set targetHour to ( Gamehour + 4.167 )endif   If ( DoOnce2 == 1 )	  If ( randomizer == 3 )		 If ( player-> getwillpower > 85 ) 			If ( player-> getwillpower <= 90 ) 			   if ( currentDay = Day )				  if ( targetHour > GameHour )					 return				  else					 startscript, "Were_BecomeHuman"					 set timer to 0					 set DoOnce2 to 0					 set randomizer to random 5				  endif			   else				  if ( targetHour >= 24 )					 if ( targetHour >= ( Gamehour + 24 ) )						return					 else						startscript, "Were_BecomeHuman"						set timer to 0						set DoOnce2 to 0						set randomizer to random 5					 endif				  endif			   endif			endif		 endif	  endif   endif

This may return false negatives in days following the first day change (the problem with not having a reliable calendar). I suspect your code could be made to run more efficiently, but without seeing the rest of the script I just used the structure that you offered.

Again, a global script timing in seconds may be the best way to go, but you have your reasons for wanting to check Gamehour.
User avatar
k a t e
 
Posts: 3378
Joined: Fri Jan 19, 2007 9:00 am

Next

Return to III - Morrowind