[HELP} Need help with simple scripting

Post » Sat Feb 19, 2011 2:12 am

I'll cut right to the chase here :

I'm currently learning how to script and have been experimenting with a few things here.

I'm trying to summon custom NPC's using a Vertibird.

i'm done with the first part ... i've created a menubased script which let's me do just that

scn 1SquadRadioScriptint ibuttonref r1SquadSniperBegin OnEquipshowmessage 1SquadSummonMenuendBegin GameModeset iButton to GetButtonPressed if iButton == -1returnelseif iButton == 0 playsound WPNAlienBlasterFire2Delseif iButton == 1 placeatme 1TacticalSquadVertibird 1elseif iButton == 2  PlaceAtMe 1TacticalSquadVertibird 1set r1SquadSniper to 0endif


Now there is a second script attached to a verbird activator with a line "placeatme 1SquadSniper 3" ...and it works fine ... but now there are two things that i cannot acomplish
1. I would like to be able to summon no more than 3 combatants ... so when there are allready 3 alive ones in scene the script would result in 0
2. How to dismiss the summoned troops ?? tried with disable and remove and GetIsID xxx => 1 remove them all
but the problem is that i cannot find anywhere how to get actor count of the custom NPC's in the current scene and i cannot find a command on how to remove them

And lastly .. how do you assign custom Variables to custom groups of actors ???

Thanks in Advance
Alex
User avatar
Matt Terry
 
Posts: 3453
Joined: Sun May 13, 2007 10:58 am

Post » Sat Feb 19, 2011 9:45 am

1. Use a global counter

short cntset cnt to GlobalCounterplaceatme 1SquadSniper cntset GlobalCounter to 0


and in the OnDeath/Remove Script increase the counter for each trooper that needs to be replaced
set GlobalCounter to GlobalCounter + 1




2. The best strategy depends on what you're exactly planning to do, and how much flexibility you need. You can use the above approach, and use another global variable to make the first trooper that runs his script disappear

if ( RemoveTroopers > 0 )  set RemoveToopers to Removetroopers -1  disable  MarkForDeleteendif



Or you can make use of the fact that Placeatme returns a reference to the created object

ref Trooper1ref Trooper2ref Trooper3if (Trooper1 == 0)   set Trooper1 to PlaceAtMe 1SquadSniper 1endifif (Trooper2 == 0)   set Trooper2 to PlaceAtMe 1SquadSniper 1endifif (Trooper3 == 0)   set Trooper3 to PlaceAtMe 1SquadSniper 1endif


Now you can refer to each trooper by its reference variable
ref victimset victim to VertibirdRef.Trooper3set VertibirdRef.Trooper3 to 0victim.disablevictim.MarkForDelete


And to get the count of active toopers you do

set TrooperCount to (VertibirdRef.Trooper1 != 0) + (VertibirdRef.Trooper2 != 0) + (VertibirdRef.Trooper3 != 0) 



If you want to increase the count of troopers later, you need to add a new reference and use it in all scripts, though, but as long as you need a reference to that trooper and can't work with an external flag that is used in the NPC's script, that's the only way to go.



3. Not sure what you're asking for. To attach a variable to any object, you add a script with those variables, but to access those variables from outside that script you need to know the object's reference.


No matter which approach of ceeping count of your troops you use, You can set the NPC's variables when he is created:

1st approach (Global counter, Now placing the troopers one after the other in separate frames):

ref trooper
if ( GlobalCounter > 0 )
set Trooper to PlaceAtMe 1SquadSniper 1
set Trooper.IDnumber to 3
set GlobalCounter to GlobalCounter - 1
endif

2nd approach (Fixed set of reference variables):

if (Trooper 3 == 0)   set Trooper3 to PlaceAtMe 1SquadSniper 1   set Trooper3.IDnumber to 3endif

User avatar
Dorian Cozens
 
Posts: 3398
Joined: Sat May 26, 2007 9:47 am

Post » Sat Feb 19, 2011 5:17 am

thanks a lot for the reply ... i'm going to try and explain :

i'm gonna skip the troopers count limitations for now and keep it simple for my own sake : )

this is what i'm trying to accomplish :

1. the vertibird comes when summoned and drops off troops ... for now i have attached a simple line to it ... " placeAtMe 1squadsniper 3" spawns 3 identical NPC
2. now when vertibird is called in order to pick up the troops (dismiss them) dead or alive they have to disappear .... problem is that i cannot find commands that would remove those earlier spawned characters ...


i was trying to make something like this :

if active == 1if isanimplaying forward == 0; landed -- drop off troopers if we have a landing markerif getDestroyed == 0	if landingMarker != 1  &&  count 1squadsniper < 1placeatme 1SquadSniper 3else remove them all endif

User avatar
Evaa
 
Posts: 3502
Joined: Mon Dec 18, 2006 9:11 am

Post » Sat Feb 19, 2011 4:58 am

2. now when vertibird is called in order to pick up the troops (dismiss them) dead or alive they have to disappear .... problem is that i cannot find commands that would remove those earlier spawned characters ...


Either set a global variable that serves as flag to remove them in their own script
if ( RemoveTroopers > 0 )  set RemoveToopers to Removetroopers -1  disable  MarkForDeleteendif



Or remember their references and remove them externally
ref victimset victim to VertibirdRef.Trooper3set VertibirdRef.Trooper3 to 0victim.disablevictim.MarkForDelete

User avatar
josie treuberg
 
Posts: 3572
Joined: Wed Feb 07, 2007 7:56 am

Post » Fri Feb 18, 2011 11:55 pm

thanks ... i'm going to try that :)
User avatar
Nicole Mark
 
Posts: 3384
Joined: Wed Apr 25, 2007 7:33 pm

Post » Sat Feb 19, 2011 6:18 am

i'm trying to do it with globals now

scn 1SquadRadioScriptint ibuttonBegin OnEquip	showmessage 1SquadSummonMenuendBegin GameMode	set iButton to GetButtonPressed 				if iButton == -1   ;noone knows what it means		return	elseif iButton == 0  ;cancel the menu		playsound WPNAlienBlasterFire2D	elseif iButton == 1  ;summon the squad		set AlexSquadDismis to 0           		placeatme 1TacticalSquadVertibird 1		elseif iButton == 2  ;Dismiss the squad		set AlexSquadDismis to 1           		PlaceAtMe 1TacticalSquadVertibird 1			endifend



 if AlexSquadDismis == 0						placeatme 1SquadSniper 1                  		elseif AlexSquadDismis == 1                        		                                               disable                             MarkForDelete


the vertibird disappears at landing ..the trooper stays lol
User avatar
Laura Samson
 
Posts: 3337
Joined: Wed Aug 29, 2007 6:36 pm

Post » Fri Feb 18, 2011 10:35 pm

the vertibird disappears at landing ..the trooper stays lol


If you don't use a reference, functions run on the object the script is running on. Thus your second script needs to be put on each of the troopers, not on the vertibird.
User avatar
cheryl wright
 
Posts: 3382
Joined: Sat Nov 25, 2006 4:43 am

Post » Sat Feb 19, 2011 9:35 am

ooo damn you're right ...completely forgot about that ...thanks ...it's been a really long day lol
User avatar
JERMAINE VIDAURRI
 
Posts: 3382
Joined: Tue Dec 04, 2007 9:06 am

Post » Fri Feb 18, 2011 9:06 pm

it works ..thanks


although if i summon them twice i need to dismiss them twice also lol

they don't want to travel in the same vertibird lol
User avatar
Nikki Hype
 
Posts: 3429
Joined: Mon Jan 01, 2007 12:38 pm

Post » Fri Feb 18, 2011 5:59 pm

bump again

now i'm trying to make my squad switch weapons on command and have no luck :(

i've set up a global variable so that id the variable == 0 equip weapons 1 and if variable > 0 equip weapons 2

i have to scripts running 1 menu based and the other is attached to a trooper it looks like this the variable is at the bottom of the trooper script

scn AlexSquadCommandsScriptint ibuttonBegin OnEquip	showmessage AlexSquadCommandMessageendBegin GameMode	set iButton to GetButtonPressed 	    if iButton == -1   ;noone knows what it means		return	elseif iButton == 0  ;cancel the menu		playsound WPNAlienBlasterFire2D	elseif iButton == 1 ;Make your Squad use silenced weapons      set AlexSquadweaponchange to 1	elseif iButton == 2 ;make your squad use regular weapons     set AlexSquadweaponchange to 0           				endifend


scn AlextrooperTrooperAssaultScriptbegin gamemode;by dismissing the current squad you're resetting the restriction on summoning more troops==========================================================================                                if AlexSquadDisableAssault > 0                                 set AlexSquadDisableAssault to AlexSquadDisableAssault -1                                Disable                                MarkForDelete endifend;if one soldier died you will be able to summon another to replace him ========================================================= Begin OnDeath                                     set AlexSquadToManySummoned to (AlexSquadToManySummoned - 1)endifendBegin Gamemodeif AlexSquadweaponchange == 0equipitem AlexAssaultCarbine 1 elseif AlexSquadweaponchange > 0equipitem AlexSilentSMG 1 endifend



thanks in advance peeps
User avatar
Amy Masters
 
Posts: 3277
Joined: Thu Jun 22, 2006 10:26 am

Post » Sat Feb 19, 2011 8:00 am

You should only use one GameMode block. Also, setup the weapon switch so that it's not equipping the weapon every frame - check to see if it's already equipped first. If so, then do nothing to it.

scn AlextrooperTrooperAssaultScript  begin gamemode ;by dismissing the current squad you're resetting the restriction on summoning more troops ========================================================================== 	if AlexSquadDisableAssault > 0  		set AlexSquadDisableAssault to AlexSquadDisableAssault -1 		Disable 		MarkForDelete  	endif 		if AlexSquadweaponchange == 0		if (GetEquipped AlexAssaultCarbine == 0)			UnEquipItem AlexSilentSMG			equipitem AlexAssaultCarbine 1		endif	else		if (GetEquipped AlexSilentSMG == 0)			UnEquipItem AlexAssaultCarbine			equipitem AlexSilentSMG 1		endif	endifend   ;if one soldier died you will be able to summon another to replace him  =========================================================    Begin OnDeath   set AlexSquadToManySummoned to (AlexSquadToManySummoned - 1)  end 

User avatar
Je suis
 
Posts: 3350
Joined: Sat Mar 17, 2007 7:44 pm

Post » Sat Feb 19, 2011 5:20 am

thanks for the reply ... much appreciated ...
i have been able to solve it with almost similar solution a bit earlier ...
thanks
User avatar
Ysabelle
 
Posts: 3413
Joined: Sat Jul 08, 2006 5:58 pm

Post » Fri Feb 18, 2011 5:47 pm

the solution look like this

the scripts still need to be adjusted .. i need to add a couple of conditions to them .. but in general they are working like they should

the summon and dismiss menu script for vertibird
scn AlexSquadRadioScriptint ibuttonBegin OnEquip	showmessage 1SquadSummonMenuendBegin GameMode	set iButton to GetButtonPressed 				if iButton == -1   ;noone knows what it means		return	elseif iButton == 0  ;cancel the menu		playsound WPNAlienBlasterFire2D	elseif iButton == 1  &&   AlexSquadToManySummoned > 2  ;summon the squad   showmessage AlexToManyTroopsPresentreturnelse    set AlexSquadDismis to 0           		placeatme AlexSquadVertibird 1          set AlexSquadToManySummoned to 3           endifendif		elseif iButton == 2  ;Dismiss the squad		set AlexSquadDismis to 1           		PlaceAtMe AlexSquadVertibird 1		endifend



the vertibird script

scn AlexSquadSummonVertibirdshort activeref landingMarkerbegin onLoad	if active == 0		playgroup forward 0		set active to 1	endifendbegin OnActivate	if IsActionRef player == 0		; assume this is my reference marker		set landingMarker to GetActionRef		; move soldier drop-off markers		FFEDropOffMarkerA.moveto landingMarker 0 -75 0		FFEDropOffMarkerB.moveto landingMarker 0 75 0	endifendbegin gameMode	if active == 1		if isanimplaying forward == 0			; landed -- drop off troopers if we have a landing marker			if getDestroyed == 0					if landingMarker != 1                   if AlexSquadDismis == 1                         set AlexSquadDisableSniper to 1                        set AlexSquadDisableSupport to 1                        set AlexSquadDisableAssault to 1                        set AlexSquadToManySummoned to -1                         elseif AlexSquadDismis == 0						placeatme AlexSquadSniper 1                              placeatme AlexSquadAssault 1                              placeatme AlexSquadSupport 1                                                                                          		                        											endif				endif				playgroup backward 0			endif			set active to 2					endif	elseif active == 2		if isanimplaying backward == 0			set active to 3			markfordelete		endif	endifend





the command menu script:
scn AlexSquadCommandsScriptint ibuttonBegin OnEquip	showmessage AlexSquadCommandMessageendBegin GameMode	set iButton to GetButtonPressed 	    if iButton == -1   ;noone knows what it means		return	elseif iButton == 0  ;cancel the menu		playsound WPNAlienBlasterFire2D	elseif iButton == 1 ;Make your Squad use silenced weapons             set AlexSquadweaponchange to 1                                                  	elseif iButton == 2 ;make your squad use regular weapons          set AlexSquadweaponchange to 0                  		endifend




the result script for the troopers looks like this now

scn AlextrooperTrooperAssaultScriptbegin gamemode;forcing equip a weapon by menu ;===========================                             if AlexSquadweaponchange == 1 && getequipped AlexSilentSMG == 0 && getdead == 0                             removeitem AlexAssaultCarbine 1 1                             additem AlexSilentSMG 1 1                             equipitem AlexSilentSMG 0 1                             else returnendif                             elseif AlexSquadweaponchange == 0 && getequipped AlexAssaultCarbine == 0 && getdead == 0                             removeitem AlexSilentSMG 1 1                             additem AlexAssaultCarbine 1 1                             equipitem AlexAssaultCarbine 0 1                             else returnendif;Forcing actor to go into sneaking mod if player is sneaking;================================                             if player.IsSneaking == 1	                        SetForceSneak  1else	                        SetForceSneak  0endif;by dismissing the current squad you're resetting the restriction on summoning more troops;==========================================================================                                if AlexSquadDisableAssault > 0                                 set AlexSquadDisableAssault to AlexSquadDisableAssault -1                                                                Disable                                MarkForDelete endif            end;if one soldier died you will be able to summon another to replace him ;========================================================= Begin OnDeath                                     set AlexSquadToManySummoned to (AlexSquadToManySummoned - 1)endifend

User avatar
Mrs. Patton
 
Posts: 3418
Joined: Fri Jan 26, 2007 8:00 am

Post » Sat Feb 19, 2011 6:09 am

another bump :

how to force an actor not to pick up a stronger weapon or any other weapon if he finds it ???

and is there any way to force equip a weapon on actor from form list rather than by spec. ref???

thanks
User avatar
Jay Baby
 
Posts: 3369
Joined: Sat Sep 15, 2007 12:43 pm

Post » Sat Feb 19, 2011 12:15 am

how to force an actor not to pick up a stronger weapon or any other weapon if he finds it ???

Aren't they only looking for other weapons when they've lost their own or are out of ammo?

and is there any way to force equip a weapon on actor from form list rather than by spec. ref???

If you want to add that random item on the fly you need to trick the NPC into searching his inventory for a new weapon:
Additem ListOfWeapons 1Additem WeapKnife 1EquipItem WeapKnife 1RemoveItem WeapKnife 1

User avatar
Jeff Tingler
 
Posts: 3609
Joined: Sat Oct 13, 2007 7:55 pm

Post » Sat Feb 19, 2011 8:55 am

Aren't they only looking for other weapons when they've lost their own or are out of ammo?


If you want to add that random item on the fly you need to trick the NPC into searching his inventory for a new weapon:
Additem ListOfWeapons 1Additem WeapKnife 1EquipItem WeapKnife 1RemoveItem WeapKnife 1



thanks Jog ... no those idiots .. when in heavy combat ... tend to pick up stronger weapons if they happen to come across ....

anyway i have been able to solve the issue (with help from Various Scripters) ... i had to switch to NVSE and Form Lists Though ... i was wondering

if you could do with the leveled items the same without using the fose

;forcing equip a weapon by menu   ;===========================    if FormListIndex != AlexSquadWeaponChange    Set FormListIndex to AlexSquadWeaponChange      Set rWeaponRef to ListGetNthForm AlexAllWeaponsList FormListIndex  endif    If rWeaponRef !=0 && getequipped rWeaponRef == 0 && getdead == 0     If GetItemCount rWeaponRef == 0        additem rWeaponRef 1 1     endif                  equipitem rWeaponRef 0 1  endif  

User avatar
Noraima Vega
 
Posts: 3467
Joined: Wed Jun 06, 2007 7:28 am

Post » Sat Feb 19, 2011 6:36 am

nevermind the post above solved them all

but i have experienced a new problem .. when i put more that one condition to my menu it gets completely messed up .. what am i doing wrong ??

scn AlexSquadRadioScript  int ibutton Short toMany  Begin OnEquip         showmessage 1SquadSummonMenu  end   Begin GameMode set ToMany to 0         set iButton to GetButtonPressed                                      if iButton == -1   ;noone knows what it means                 return endif     if iButton == 0  ;cancel the menu                 playsound WPNAlienBlasterFire2D endif      if iButton == 1  &&   AlexSquadToManySummoned > 2  ;checking if there are more than 2 troops present   showmessage AlexToManyTroopsPresent  else              set AlexSquadDismis to 0            ;summon the squad             placeatme AlexSquadVertibird 1           set AlexSquadToManySummoned to 3             endif         if iButton == 2 && AlexSquadToManySummoned < 0        ;checking if there are any troops present       showmessage AlexThereIsNobododytoDismissmessage       else          set AlexSquadDismis to 1             ;Dismiss the squad          PlaceAtMe AlexSquadVertibird 1                         endif end


EDIT: ignore to many variable ... it's not in the final script
User avatar
Michael Russ
 
Posts: 3380
Joined: Thu Jul 05, 2007 3:33 am

Post » Sat Feb 19, 2011 9:28 am

if iButton == -1   ;noone knows what it means 


Is that a question? This is what GetButtonPressed returns while there is no button pressed.

    if iButton == 1  &&   AlexSquadToManySummoned > 2  ;checking if there are more than 2 troops present   showmessage AlexToManyTroopsPresent  else              set AlexSquadDismis to 0            ;summon the squad             placeatme AlexSquadVertibird 1           set AlexSquadToManySummoned to 3             endif         if iButton == 2 && AlexSquadToManySummoned < 0        ;checking if there are any troops present       showmessage AlexThereIsNobododytoDismissmessage       else          set AlexSquadDismis to 1             ;Dismiss the squad          PlaceAtMe AlexSquadVertibird 1 





Okay, that's a bit messed up, you have separate if-blocks instead of one if-elseif block, thus each of them is executed.

When you test on If Button==1 AND AlexSquadToManySummoned > 2 the following ELSE-statement will be executed whenever you press a button other than Button 1 or the variable is >2. So your squad will be constantly summoned and dismissed when you click any button.


Try this.
scn AlexSquadRadioScript  short ibuttonshort messageup Begin OnEquip 	showmessage 1SquadSummonMenu 	set messageup to 1end   Begin GameMode 	if messageup		set iButton to GetButtonPressed  		if iButton == -1   	;Wait until button was pressed			return		endif		set messageup to 0				if iButton == 0	;cancel the menu 			playsound WPNAlienBlasterFire2D 	     	elseif iButton == 1	;summon the squad 			if AlexSquadToManySummoned > 2  	;checking if there are more than 2 troops present   				showmessage AlexToManyTroopsPresent 			else         	     		set AlexSquadDismis to 0				placeatme AlexSquadVertibird 1				set AlexSquadToManySummoned to 3			endif		elseif iButton == 2	;Dismiss the squad			if AlexSquadToManySummoned < 0		;checking if there are any troops present				showmessage AlexThereIsNobododytoDismissmessage       			else				set AlexSquadDismis to 1             ;Dismiss the squad				PlaceAtMe AlexSquadVertibird 1 			endif             		endif 	endifend


The test on "messageup" prevents this part of the script from reacting to buttons from other messages, and now each part should only be executed when it is supposed to.
User avatar
Facebook me
 
Posts: 3442
Joined: Wed Nov 08, 2006 8:05 am

Post » Sat Feb 19, 2011 8:39 am

thanks i'll try yours now :)

i had tried all kind if combo's with if blocks and elseif block putting endif and return between some some of them .. but couldn't get it to work lol
User avatar
Elea Rossi
 
Posts: 3554
Joined: Tue Mar 27, 2007 1:39 am

Post » Sat Feb 19, 2011 3:38 am

THANKS IT WORKS
User avatar
His Bella
 
Posts: 3428
Joined: Wed Apr 25, 2007 5:57 am

Post » Sat Feb 19, 2011 2:14 am

so what if i put more options in the menu .. can i continue writing the script the way the previous buttons were scripted
User avatar
Naazhe Perezz
 
Posts: 3393
Joined: Sat Aug 19, 2006 6:14 am

Post » Sat Feb 19, 2011 3:55 am

so what if i put more options in the menu .. can i continue writing the script the way the previous buttons were scripted


Yes, just insert your "elseif ibutton == 3" block before the second-last "endif".
User avatar
Fanny Rouyé
 
Posts: 3316
Joined: Sun Mar 25, 2007 9:47 am

Post » Fri Feb 18, 2011 11:51 pm

ok thanks :)
btw .. now after 4 days of scripting .. your previous posts make much more sense to me ..lol
thanks for those once more :)
User avatar
Alba Casas
 
Posts: 3478
Joined: Tue Dec 12, 2006 2:31 pm

Post » Sat Feb 19, 2011 6:10 am

ug oh .. it seems that i'm having problems with a multilevel menu

it's one main menu ... with two small sub menus ..looks like this

cancel
summon
dismiss
go silent
go loud
follow
wait
==========

commands WAIT open a submenu and command FOLLOW opens a submenu

scn AlexSquadRadioScript    short ibutton short messageup int iButton0int iButton1int iButton2int iMenuLevelint iAlternateMessage        Begin OnEquip          showmessage AlexSquadSummonMenu           end      Begin GameMode           if iMenuLevel == 0                 set iButton0 to GetButtonPressed                   if iButton == -1        ;Wait until button was pressed                         return                 endif                                                  if iButton0 == 0 ;cancel the menu                          playsound WPNAlienBlasterFire2D                                         elseif iButton0 == 1     ;summon the squad                                                         set AlexSquadDismis to 0                                 placeatme AlexSquadVertibird 1                                 set AlexSquadToManySummoned to 3                                       elseif iButton0 == 2     ;Dismiss the squad                                                        set AlexSquadDismis to 1             ;Dismiss the squad                                 PlaceAtMe AlexSquadVertibird 1                                   elseif iButton0 == 3  ;Tell your squad to use silent weapons            set AlexSquadweaponchange to 1                                       elseif iButton0 == 4 ;tell your squad to use primary weapons            set AlexSquadweaponchange to 0           elseif iButton0 == 5 ;                     ShowMessage AlexWaitOptions                     set iMenuLevel to 1           set iButton1 to GetButtonPressed                          if iButton1 == -1 ; No button has been pressed yet              return endif                            if iButton1 == 0        playsound WPNAlienBlasterFire2D              elseif iButton1 == 1           set AlexSquadholdposition to 1           elseif iButton1 == 2           set AlexSquadWaitRelax to 1endif           elseif iButton0 == 6 ;          ShowMessage AlexFollowOptions               set iMenuLevel to 2        set iButton2 to GetButtonPressed           if iButton2 == -1 ; No button has been pressed yet           return endifif iButton2 == 0 playsound WPNAlienBlasterFire2D  elseif iButton2 == 1set AlexSquadFollowClose to 1elseif iButton2 == 2set AlexSquadFollowLong to 1endifendif  endif end


after i go into either one of those sub menus .. all buttons stop functioning

thanks

Alex
User avatar
No Name
 
Posts: 3456
Joined: Mon Dec 03, 2007 2:30 am

Post » Fri Feb 18, 2011 9:20 pm

Have you used http://cipscis.com/fallout/tutorials/menu.aspx multi level menu tutorial?
User avatar
Poetic Vice
 
Posts: 3440
Joined: Wed Oct 31, 2007 8:19 pm

Next

Return to Fallout: New Vegas