Some help with Player references

Post » Tue May 17, 2011 4:52 am

Hi and welcome to.. err, wait i mean.. hey.

I have been writing a script for an ability, which counts the times you have hit the same actor, in case you hit another actor then the count is reset.

I thought about something like this.

if player.IsAttacking == 1 && player.IsCasting == 0 && player.IsPowerAttacking == 0	set rPlayerTarget to GetCrosshairRef					;Get your reference		if rPlayerTarget.getdistance rPlayerTarget <= 100			if aaKSourceQ.[censored]2 == 1				set aaKSourceQ.[censored]2 to 0				if rPlayerTarget == rFocusedTarget	        ;Same reference?					set sStackCount to sStackCount + 1	;good to go.				else	if rPlayerTarget.IsActor == 1		;not same ref, but wait it's the reference an actor?					set rFocusedTarget to rPlayerTarget	;Not same reference, switch actors					set sStackCount to 0		        ;and clear stacks				endif			endif		endif	endifendif


Works good, added the actor check so the reference doesn't switch and clear the stacks if you aim a door or an object.

However sometimes the reference is lost (seems to happen when the actor staggers or recoils, this however is unconfirmed and may be pure coincidence) , i set the script so it prints to the console both references, and when this happens it prints (as if the ref is empty or the actor has no name) on both refs, instead of printing the actual actor's name (it is supposed to be an actor, just in case IsActor misfire or something i tried GetAV checks but with no better results)

If anyone of you could give a hand or some advice, well that would be awesome indeed...

If the player manages to get say 10 stacks, it could randomly reset, and the player would need to start from 0 again, that's the main issue.

Thanks for any help and thank you for reading.

Until next time! or reply!.
User avatar
Star Dunkels Macmillan
 
Posts: 3421
Joined: Thu Aug 31, 2006 4:00 pm

Post » Tue May 17, 2011 5:52 am

  • if player.IsAttacking == 1 && player.IsCasting == 0 && player.IsPowerAttacking == 0
    These conditions would be 'cheaper' if divided into separate lines
  • if rPlayerTarget.getdistance rPlayerTarget <= 100
    This condition will always return true as they're the same ref
  • else if rPlayerTarget.IsActor == 1
    Space between 'Else' and 'If' probably won't compile how you want it to. Also, booleans like IsActor are 'cheaper' sans the '==1'
  • EndIf on line 14
    That 'EndIf' is extraneous and might be causing unpredictable behavior



Try...
	If Player.IsCasting	ElseIf Player.IsPowerAttacking	ElseIf Player.IsAttacking		Set rPlayerTarget to GetCrosshairRef				;Get your reference		If (Player.GetDistance rPlayerTarget <= 150) ; Try 150 or more if problems still arise?			If aaKSourceQ.[censored]2 == 1				Set aaKSourceQ.[censored]2 to 0				If (rPlayerTarget == rFocusedTarget)	        ;Same reference?					Set sStackCount to (sStackCount + 1)	;good to go.				ElseIf rPlayerTarget.IsActor		;not same ref, but wait it's the reference an actor?					Set rFocusedTarget to rPlayerTarget	;Not same reference, switch actors					Set sStackCount to 0		        ;and clear stacks				EndIf			EndIf		EndIf	EndIf
...? Hopefully something in there is helpful. :)
User avatar
c.o.s.m.o
 
Posts: 3419
Joined: Sat Aug 12, 2006 9:21 am

Post » Tue May 17, 2011 12:27 am

Thanks a lot JustinOther, some of the mistakes you found on the script were non present on the CS, sorry my mistake when writing the script here, and thanks for the advice to make a more efficient script! (thought the distance check was indeed a mistake i had on the CS as well =D)

You know what's weird? If Player.GetDistance rPlayerTarget seems to crash the script, for some unknown reason i have not found yet, so right now i have removed it. =(

Anyway, when doing further testing i found the strange behavior that is clearing the stacks, and im beginning to think that this may be a game issue and not the script itself.

I found that this happens when you hit the actor from a distance around 130 or 120 away (around the max weapon reach, barely hitting, 130 is not a correct distance though im just calculating,) the reference gets replaced with , if you keep hitting the actor around this distance, the stacks keep increasing, and the ref remains the same (), if you move closer the reference then changes to the actor id (or in this case the actors name), and the stack count is reset again.

So what im trying to say is if i hit some actor named Caldwyn (some npc around hawkhaven) at close range (normal melee range) i get the right ref, stacks increase.
If i hit it the same actor but from a distance around 130-110 (max weapon reach, as if the weapon barely touched the actor) the ref is replaced with and the stacks reset.

I guess you could fix this by adding a GetDistance check, but doing so crashes the script =/

I haven't found a way to fix this, so if any of you has any kind of experience with this or an idea, please share.

Thank You.
User avatar
Amanda Leis
 
Posts: 3518
Joined: Sun Dec 24, 2006 1:57 am

Post » Tue May 17, 2011 11:01 am

...If Player.GetDistance rPlayerTarget seems to crash the script...
Hmm... Try the inverse, 'If rPlayerTarget.GetDistance Player', but after a check to ensure there is a rPlayerTarget as checking on a non-existent ref can CTD.


Spoiler
	If Player.IsCasting	ElseIf Player.IsPowerAttacking	ElseIf Player.IsAttacking		Set rPlayerTarget to GetCrosshairRef		If (rPlayerTarget.IsActor && rPlayerTarget.GetDead == 0)		Else			Set rPlayerTarget to 0		EndIf		If rPlayerTarget		Else			Return		EndIf		If (rPlayerTarget.GetDistance Player <= 150)			If aaKSourceQ.[censored]2 == 1				Set aaKSourceQ.[censored]2 to 0				If (rPlayerTarget == rFocusedTarget)					Set sStackCount to (sStackCount + 1)				Else;If rPlayerTarget.IsActor					Set rFocusedTarget to rPlayerTarget					Set sStackCount to 0				EndIf			EndIf		EndIf	EndIf
Hope you get to the bottom of it.

Just a thought, but is this a quest? If so you could further optimize it so it's less hungry while not in combat.

Spoiler
Int bQuickeningFloat fQuestDelayTimeBegin GameMode	If (Player.GetInCombat != bQuickening)		Set bQuickening to (bQuickening == 0) ; Set bool to whatever it's not		If bQuickening			Set fQuestDelayTime to .01		Else			Set fQuestDelayTime to 3		EndIf		Return	ElseIf Player.IsCasting	ElseIf Player.IsPowerAttacking	ElseIf Player.IsAttacking		Set rPlayerTarget to GetCrosshairRef		If (rPlayerTarget.IsActor && rPlayerTarget.GetDead == 0)		Else			Set rPlayerTarget to 0		EndIf		If rPlayerTarget		Else			Return		EndIf		If (rPlayerTarget.GetDistance Player <= 150)			If aaKSourceQ.[censored]2 == 1				Set aaKSourceQ.[censored]2 to 0				If (rPlayerTarget == rFocusedTarget)					Set sStackCount to (sStackCount + 1)				Else;If rPlayerTarget.IsActor					Set rFocusedTarget to rPlayerTarget					Set sStackCount to 0				EndIf			EndIf		EndIf	EndIf

User avatar
Alexandra walker
 
Posts: 3441
Joined: Wed Sep 13, 2006 2:50 am

Post » Tue May 17, 2011 1:38 am

Hahaha, it worked, it frickin worked.

Yes the function works now and the issue of the reference is gone as well!

Well, thanks a lot JustinOther, that was some clever thinking...

The script is an ability which is added by using a toggle spell (add and remove), the ability is a "combat form" so to speak, in this case is an aggressive and acrobatic combat form relying on a combination of power, strength, and speed, effective against single opponents because is focused.

So when using this combat form each action flows from one to another in smooth transitions increasing your damage with each strike (each successful strike against the opponent). Each successful attack against the current target increases all your damage caused by 5% for 3 sec, this effect stacks up to 6 times, if you switch targets the increased damage is lost. (im still testing the formulas to make it balanced and stuff)

I like your idea, and now that you know how this script is implemented, do you think it would be good to make the ability a quest? and toggle it using a script which modifies a value set in the quest script...

Well anyway i can now move on and write the script for the last form, so thank you. (i will clean my other scripts also with the advices you wrote)

=D
User avatar
Mr. Ray
 
Posts: 3459
Joined: Sun Jul 29, 2007 8:08 am

Post » Tue May 17, 2011 11:22 am

:foodndrink:
User avatar
Gaelle Courant
 
Posts: 3465
Joined: Fri Apr 06, 2007 11:06 pm


Return to IV - Oblivion