MWSE functions help

Post » Tue Apr 05, 2011 7:01 am

I couldn't find a mwse thread so i'll start one.

I can't seem to get the xKeyPressed function working correctly. It all most works, but not quite.


Begin Mf_test1long PcTargshort KeyP          ;the "P" keylong pShieldsetx PcTarg to xGetPCTargetif ( PcTarg == 0 )	returnendifsetx KeyP to xKeyPressed, 80      ;80 should = "P" keyIfx ( KeyP )	setx pShield to PcTarg->xRefId	messagebox, "Shield set."endifend


Every so often ill get the "Shield set." message box without even hitting the "P" key. Now, if I press "P" it will give the message like it is supposed to. I need the set refID line to only run when the key is pressed or it will screw things up.
User avatar
Amber Ably
 
Posts: 3372
Joined: Wed Aug 29, 2007 4:39 pm

Post » Tue Apr 05, 2011 3:02 am

If it works some of the time, and not at others, I wonder if case is important. Try it upper case, and then lower case. If that is what is wrong, have it check for both cases, 68 (upper) & 100(lower) I believe.

I've never worked with MWSE so I don't know. :(
User avatar
Gemma Woods Illustration
 
Posts: 3356
Joined: Sun Jun 18, 2006 8:48 pm

Post » Mon Apr 04, 2011 11:39 pm

You're never resetting KeyP. You should set it to a safe NULL value after using it, just to make sure a single press isn't registered more than once. :)

If it works some of the time, and not at others, I wonder if case is important. Try it upper case, and then lower case. If that is what is wrong, have it check for both cases, 68 (upper) & 100(lower) I believe.

Does xGetKeyPressed work on ASCII character code or Windows key code? I've never been clear on that, though I was under the impression it just used the lower-level codes. If it uses ASCII, that'd be kind of ridiculous, but your suggestion might be the issue.
User avatar
Betsy Humpledink
 
Posts: 3443
Joined: Wed Jun 28, 2006 11:56 am

Post » Mon Apr 04, 2011 10:29 pm

You're never resetting KeyP. You should set it to a safe NULL value after using it, just to make sure a single press isn't registered more than once. :)


Does xGetKeyPressed work on ASCII character code or Windows key code? I've never been clear on that, though I was under the impression it just used the lower-level codes. If it uses ASCII, that'd be kind of ridiculous, but your suggestion might be the issue.


The MWSE wiki says its Virtual Key Code (between 1 and 254). I'm looking at the list (thats on the mwse wiki) for the key codes and i see 151-159 are unasigned. would that work as a null value?

Begin Mf_test1long PcTargshort KeyPlong pShieldsetx PcTarg to xGetPCTargetif ( PcTarg == 0 )	returnendifsetx KeyP to xKeyPressed, 80Ifx ( KeyP )        setx KeyP to xKeyPressed, 151     ;would this work as  a null value?	setx pShield to PcTarg->xRefId	messagebox, "Shield set."endifEnd


I've got a logitech g15 key board, and it has 6 (macro?) keys. I wonder if that could have anything to do with it.

"If it works some of the time, and not at others, I wonder if case is important. Try it upper case, and then lower case. If that is what is wrong, have it check for both cases, 68 (upper) & 100(lower) I believe."

It works all the time when i press the "P" key. The problem is it sometimes displays that message even if I dont have the "P" key pressed.

Il try that script out

EDIT: I forgot to mention this is a global script.

EDIT2: It didn't work.
User avatar
Lauren Denman
 
Posts: 3382
Joined: Fri Jun 16, 2006 10:29 am

Post » Tue Apr 05, 2011 9:21 am

Ok, I added the line

If ( KeyP == 0 )      returnEndifIf ( KeyP )     ;do stuffffendif


that seemed to stop if from randomly displaying the text.

My next problem is this.

here is the whole script:

Spoiler
Begin Mf_torch_toggleshort OnPcEquipshort TorchEquippedlong PcTargshort KeyPlong pShieldIf ( OnPcEquip == 1 )	set OnPcEquip to 0	If ( TorchEquipped == 1 )		player->Additem, "Mf_toggle_shield" 1		player->Equip, "Mf_toggle_shield"		player->RemoveItem, "Mf_toggle_shield" 1		player->xEquip, pShield ;this is causing ctd's#########################		set TorchEquipped to 0										Else		If ( Player->GetItemCount, "torch" > 0 )			Player-> Equip, "torch"			set TorchEquipped to 1		ElseIf ( Player->GetItemCount, "torch_256" > 0 ) 			Player-> Equip, "torch_256"			set TorchEquipped to 1;##################################################ill put the rest of the torch types in later		Else			MessageBox, "You don't have a torch"			player->additem, "Mf_toggle_shield" 1			player->equip, "Mf_toggle_shield"			player->removeItem, "Mf_toggle_shield" 1			set TorchEquipped to 0		Endif	EndifEndIfsetx PcTarg to xGetPCTargetsetx KeyP to xKeyPressed, 80If ( KeyP == 0 )	returnendifif ( PcTarg == 0 )	returnendifIf ( KeyP == 0 )	returnendifIfx ( KeyP )	setx pShield to PcTarg->xRefId	messagebox, "Shield set."			;sometimes this message will display even if i haven't pushed the "p" buttonendIfEnd


I'm trying to improve my torch toggler mod. I'm wanting it to re-equip a shield when you unequip a torch. You set the shield by looking at it and pressing "P".
The problem is If i have the line: "player->xEquip, pShield" in the script I get a ctd when i load the game. If I take the line out I can load the game just fine, and the rest of the script will work for the most part. It will display "shield set" if i'm near something if I press "P". This script is incomplete and there are more functions that im going to add in later, I just need this simple version to work before I can continue. Any help would be awesome. And this script does compile without any warnings or errors, I know that doesn't necessarily mean anything, but it's a start.

EDTI: yay i got it to work, I have to use Ifx on all extended functions.
User avatar
Darren Chandler
 
Posts: 3361
Joined: Mon Jun 25, 2007 9:03 am

Post » Tue Apr 05, 2011 12:32 am

I'm trying to get getItemCount to look for a variable. Since there is no "xGetItemCount" i'm trying to use the xSetRef function.

script:
Begin Mf_torch_toggleshort OnPcEquipshort TorchEquippedlong PcTargshort KeyPlong pShieldlong pcreflong mycountsetx pcref to xGetRef "player"Ifx ( OnPcEquip )	set OnPcEquip to 0	Ifx ( TorchEquipped )		player->Additem, "Mf_toggle_shield" 1		player->Equip, "Mf_toggle_shield"		player->RemoveItem, "Mf_toggle_shield" 1          ; these lines are here in case the player doesn't have/use a shield or 2 handed weapon		xSetRef pcref		set mycount to GetItemCount, pShield		;I dont want to add a shield if the player doesn't have one: the compiler doesn't like this line		Ifx ( mycount > 0 )			player->xEquip, pShield 			set TorchEquipped to 0		EndIf


I dont' get an error, but I do get a warning: Function does not accept variable input
User avatar
Mandi Norton
 
Posts: 3451
Joined: Tue Jan 30, 2007 2:43 pm

Post » Mon Apr 04, 2011 10:37 pm

With this:
set mycount to GetItemCount, pShield
You've earlier defined pShield as a Long, this function (AFAIK) needs to work on an item ID.

Also, GetItemCount also returns a Short so "mycount" should be a Short and not a Long, although I'm not sure if that makes much difference.

Oh, and you probably have these but: http://planetelderscrolls.gamespy.com/View.php?id=6083&view=Mods.Detail and http://www.tesnexus.com/downloads/file.php?id=20927.
User avatar
Lauren Graves
 
Posts: 3343
Joined: Fri Aug 04, 2006 6:03 pm

Post » Tue Apr 05, 2011 5:07 am

yeah, but the MWSE scripting tutorials are seriously lacking. I know that I've been looking for some and they are virtually non-existant, and you can even find older info that seems to contradict newer (AFAIK. for example, you can find a listing of the add-on scripts given for MWSE and MWE with a copy of MW-Edit, but when you check those MWSE scripts versus the wiki page apparently they removed some? XMemLook comes to mind)

So now my next move (and my advice to anyone who is having a similar problem) is to download as many MWSE mod examples as I can and hope to figure it out from there. Oh, and to ask becuz people usually will answer questions here ;)

ST
User avatar
Eve Booker
 
Posts: 3300
Joined: Thu Jul 20, 2006 7:53 pm

Post » Mon Apr 04, 2011 8:36 pm

With this:
set mycount to GetItemCount, pShield
You've earlier defined pShield as a Long, this function (AFAIK) needs to work on an item ID.

Also, GetItemCount also returns a Short so "mycount" should be a Short and not a Long, although I'm not sure if that makes much difference.

Oh, and you probably have these but: http://planetelderscrolls.gamespy.com/View.php?id=6083&view=Mods.Detail and http://www.tesnexus.com/downloads/file.php?id=20927.


The link that comes with MWSE has some sample scripts in it and I think mwse uses a long to store ID's. Do a edit->search on the link for , in that sample script it sets "inviitem" (whick searches for inventory items) as a long which should be returning and ED. ID. I'm asking the same question on the great house fliggerty site, but it looks like that site has died down over last few months, but I have gotten alot of my google search answers from that site.

I can get this mod to work for the most part, it will re-equip your shield when you un-equip your torch (using the torch toggler, i have mine set to quick key 1).
User avatar
Lyd
 
Posts: 3335
Joined: Sat Aug 26, 2006 2:56 pm

Post » Tue Apr 05, 2011 8:00 am

Ok, few things:

Using xGetRef "player" is ridiculous. There's only one player and you already know it's ID, and you're not using an MWSE function. So, just do "player"->GetItemCount.

Now, while high-level key codes may not be defined at the moment, they aren't safe nulls. Mostly because they're undefined and could be used. I would recommend using the real null (0), especially since that doubles as logical false in an if test.

Finally, what is pShield and why is in with GetItemCount? The error you're getting is telling you that using a variable as input to that function isn't allowed, since it's not a MWSE function and doesn't support variables anyway. You pShield variable seems undefined on top of that. You should either test for the slot to see if the PC has any shield equipped or test for a particular shield ID.
User avatar
Peetay
 
Posts: 3303
Joined: Sun Jul 22, 2007 10:33 am

Post » Mon Apr 04, 2011 11:10 pm

Ok, few things:

Using xGetRef "player" is ridiculous. There's only one player and you already know it's ID, and you're not using an MWSE function. So, just do "player"->GetItemCount.

Now, while high-level key codes may not be defined at the moment, they aren't safe nulls. Mostly because they're undefined and could be used. I would recommend using the real null (0), especially since that doubles as logical false in an if test.

Finally, what is pShield and why is in with GetItemCount? The error you're getting is telling you that using a variable as input to that function isn't allowed, since it's not a MWSE function and doesn't support variables anyway. You pShield variable seems undefined on top of that. You should either test for the slot to see if the PC has any shield equipped or test for a particular shield ID.


I really should have reposted the full script in my last post, pShield is set when the player looks at the shield and pressed "P". Look towards the bottom of the script.

Spoiler
Begin Mf_torch_toggleshort OnPcEquipshort TorchEquippedlong PcTargshort KeyPlong pShieldlong pcreflong mycountsetx pcref to xGetRef "player"Ifx ( OnPcEquip )	set OnPcEquip to 0	Ifx ( TorchEquipped )		player->Additem, "Mf_toggle_shield" 1		player->Equip, "Mf_toggle_shield"		player->RemoveItem, "Mf_toggle_shield" 1		xSetRef pShield		set mycount to pcref->GetItemCount		;I dont want to add a shield if the player doesn't have one		Ifx ( mycount )			player->xEquip, pShield 			set TorchEquipped to 0		EndIf	Else		If ( Player->GetItemCount, "torch" > 0 )			Player-> Equip, "torch"			set TorchEquipped to 1		ElseIf ( TorchEquipped == 0 )			If ( Player->GetItemCount, "torch_256" > 0 )				Player-> Equip, "torch_256"				set TorchEquipped to 1                        EndIf;##################################################ill put the rest of the torch types in later		Else			MessageBox, "You don't have a torch"			player->additem, "Mf_toggle_shield" 1			player->equip, "Mf_toggle_shield"			player->removeItem, "Mf_toggle_shield" 1			set TorchEquipped to 0		Endif	EndifEndIfsetx PcTarg to xGetPCTargetsetx KeyP to xKeyPressed, 80If ( KeyP == 0 )	returnendifif ( PcTarg == 0 )	returnendifIfx ( KeyP )	setx pShield to PcTarg->xRefId        ;set the shield here	messagebox, "Item set."endIfEnd


This does work, the problem is it will equip any shield thats not in your inventory. A player could go to a vendor and walk up to one of the display shields and set it with "P" and then equip it. Thats why i'm trying to get an inventory item count, but that line doesn't accept variables, at least the way I am implementing it any way.
User avatar
Vickey Martinez
 
Posts: 3455
Joined: Thu Apr 19, 2007 5:58 am

Post » Tue Apr 05, 2011 5:02 am

Since there is no xGetItemCount function and the xSetRef doesn't work. I'm wondering if I can use a combination of xInventory and xStringCompare. But the way I am implementing it is causing lockups.

Here is my latest attempt:
Spoiler
Begin Mf_torch_toggleshort OnPcEquipshort TorchEquippedlong PcTargshort KeyPlong pEquipmentshort NoTorchshort DoesntHavelong invitemlong invcountlong invreflong pcrefshort Equipitemshort CompareIfx ( OnPcEquip )	set OnPcEquip to 0	Ifx ( TorchEquipped )		player->Additem, "Mf_toggle_shield" 1			;incase the player isn't using a shield or 2hander		player->Equip, "Mf_toggle_shield"		player->RemoveItem, "Mf_toggle_shield" 1		setx pcref to xGetRef "player"                            ;XXXXXXX this is were the script is causing the game to lock up. XXXXXXXXXXXXXXXXXXXX		setx invitem,invcount,invref to pcref->xInventory		whilex ( invcount )			set DoesntHave to 1		;Assumes the player doesn't have it			setx Compare to xStringCompare pEquipment invitem			If ( Compare == 0 )                    ;the strings do match, meaning the item is in my inventory				set DoesntHave to 0			endif			Ifx ( DoesntHave )		;If the search finds the item at a point in the search, no point in letting this run through all items				setx invitem,invcount,invref to pcref->xInventory			endif		endwhile		If ( DoesntHave == 0 )			set Equipitem to 1		endif		Ifx ( Equipitem )			player->xEquip, pEquipment		endif		set TorchEquipped to 0	Else		If ( Player->GetItemCount, "torch" > 0 )			Player-> Equip, "torch"			set TorchEquipped to 1		ElseIf ( Player->GetItemCount, "torch_256" > 0 )			Player-> Equip, "torch_256"			set TorchEquipped to 1		endif		If ( TorchEquipped == 0 )			set NoTorch to 1		endif		Ifx ( NoTorch )			MessageBox, "You don't have a torch."			player->additem, "Mf_toggle_shield" 1			player->equip, "Mf_toggle_shield"			player->removeItem, "Mf_toggle_shield" 1			player->xEquip, pEquipment			set TorchEquipped to 0			set NoTorch to 0		Endif	EndifEndIf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I may add some drop torch options here, if player has a weapon out and hits the toggler button it will equip shield or 2handedwep,,,setx KeyP to xKeyPressed, 80  ;;;;;;;;;;(cont.) and drop a torch (fight around lit torch in dark dungeons) player must put away weapon to equip a torchIf ( KeyP == 0 )	returnendifIfx ( KeyP )	                        	;I don't know how to set this to work only once, i'll get multiple message box's (Item set) It works fine, it just looks cheap	setx PcTarg to xGetPCTarget	;I moved this down so it won't have to constantly retrieve data, only on key press	if ( PcTarg == 0 )		return	endif	setx pEquipment to PcTarg->xRefId	Messagebox, "Item set."endIfEnd


EDIT: Ok I figured out one problem I need to changet to
User avatar
helliehexx
 
Posts: 3477
Joined: Fri Jun 30, 2006 7:45 pm

Post » Tue Apr 05, 2011 2:09 am

Shouldn't you be using xNextInventory or some similar function? It looks, from a glance, that you have an infinite loop.
User avatar
Dragonz Dancer
 
Posts: 3441
Joined: Sat Jun 24, 2006 11:01 am

Post » Tue Apr 05, 2011 8:43 am

Shouldn't you be using xNextInventory or some similar function? It looks, from a glance, that you have an infinite loop.


Yes,,,, :facepalm:

So the script works now, the item has to be in a players inventory for it to be equipped. Too bad Player->Equip adds the item if it isn't in the players inventory, I could have saved a lot of time,effort, and script overhead.
Anyway, I'm still working on the key press issue. I don't like the message spam when an item is set, and I think the constant refreshing of setting obj ID's to a variable can cause ctd's. If you could, look over the last part of this script.

Latest version:
Spoiler
Begin Mf_torch_toggleshort OnPcEquipshort TorchEquippedlong PcTargshort KeyPlong pEquipmentshort NoTorchshort DoesntHavelong invitemlong invcountlong invreflong pcrefshort Equipitemshort Comparefloat TimePassedshort KeyTimeshort DoOnceIf ( MenuMode )	returnendifIfx ( OnPcEquip )	set OnPcEquip to 0	Ifx ( TorchEquipped )		set Equipitem to 0		set DoesntHave to 1									;this is a reset after Compare runs		player->Additem, "Mf_toggle_shield" 1			;incase the player isn't using a shield or 2hander		player->Equip, "Mf_toggle_shield"		player->RemoveItem, "Mf_toggle_shield" 1		setx pcref to xGetRef "player"		setx invitem, invcount, invref to pcref->xInventory		whilex ( DoesntHave )			setx Compare to xStringCompare invitem pEquipment			If ( Compare == 0 )                    ;the strings do match, meaning the item is in my inventory				set DoesntHave to 0			endif			If ( Invref == 0 )				set pEquipment to 0				set DoesntHave to 0			endif			Ifx ( DoesntHave )				setx invitem, invcount, invref to pcref->xNextStack invref			endif		endwhile		If ( DoesntHave == 0 )			If ( pEquipment != 0 )				set Equipitem to 1			endif		endif		Ifx ( Equipitem )			set EquipItem to 0			player->xEquip, pEquipment		endif		set TorchEquipped to 0	Else		If ( Player->GetItemCount, "torch" > 0 )			Player-> Equip, "torch"			set TorchEquipped to 1		ElseIf ( Player->GetItemCount, "torch_256" > 0 )			Player-> Equip, "torch_256"			set TorchEquipped to 1		endif		If ( TorchEquipped == 0 )			set NoTorch to 1		endif		Ifx ( NoTorch )			set Equipitem to 0			set DoesntHave to 1			MessageBox, "You don't have a torch."			player->additem, "Mf_toggle_shield" 1			player->equip, "Mf_toggle_shield"			player->removeItem, "Mf_toggle_shield" 1			setx pcref to xGetRef "player"			setx invitem, invcount, invref to pcref->xInventory			whilex ( DoesntHave )				setx Compare to xStringCompare invitem pEquipment				If ( Compare == 0 )                    ;the strings do match, meaning the item is in my inventory					set DoesntHave to 0				endif				If ( Invref == 0 )					set pEquipment to 0					set DoesntHave to 0				endif				Ifx ( DoesntHave )					setx invitem, invcount, invref to pcref->xNextStack invref				endif			endwhile			If ( DoesntHave == 0 )				If ( pEquipment != 0 )					set Equipitem to 1				endif			endif			Ifx ( Equipitem )				set EquipItem to 0				player->xEquip, pEquipment			endif			set TorchEquipped to 0			set NoTorch to 0		Endif	EndifEndIf;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX drop lit torch section XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;I might add some drop torch conditions here, if player has a weapon out and hits the toggler button it will equip shield or 2handedwep,,,;(cont.) and drop a torch (fight around lit torch in dark dungeons) player must put away weapon to equip a torch;XXXXXXXXXXXXXXXXXXXXXXXX set shield or 2 handed weapon below XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXIf ( TimePassed > 2 )		;This isn't working like I expected it to	set KeyTime to 1				set TimePassed to 0endifIf ( DoOnce == 0 )	set DoOnce to 1	set KeyTime to 1EndifIfx ( KeyTime )						;This section is supposed to be locked out for 2 secs, but it gets locked out permenantly after the first PcTarg-> is registered	setx KeyP to xKeyPressed, 80	If ( KeyP == 0 )		return	endif	Ifx ( KeyP )		setx PcTarg to xGetPCTarget									if ( PcTarg == 0 )											return												endif			set KeyP to 0											setx pEquipment to PcTarg->xRefId		MessageBox, "Item set."		set TimePassed to ( TimePassed + GetSecondsPassed )		set KeyTime to 0	endifendifEnd


Their might some redundancy in this script, I'll clean them up later (if I can find them).

Btw, if you are confused as to what this script does watch this short vid http://www.youtube.com/watch?v=f8RWNHeln4E

EDIT: never mind, I fixed it.
User avatar
Sun of Sammy
 
Posts: 3442
Joined: Mon Oct 22, 2007 3:38 pm


Return to III - Morrowind

cron