Jump to content

I need help getting started scripting.


NameNotPresent

Recommended Posts

I need a script that uppon a character getting hit, a magic effect or anything to show it is working is applied to who ever got hit. This needs to run every frame so I should use an object script? What exactly is the proper way to use "Onhit". Ideally this would only affect things near by.

 

I need to get a firm grasp on how to detect who hit what to get started.

 

Also I am concerned about what happens if two people hit each other at the same time.

Link to comment
Share on other sites

OBSE provides neat little handlers called "Event (...well...) Handlers. One of them is an "OnHit" handler. You can taylor it to trigger when the player is hit or when the player hits an actor. Or you could set it to trigger when a specific NPC is hit. Are you trying to track a specific NPC? The Player? Who? Anybody?

Link to comment
Share on other sites

Then an OBSE event handler would probably be handy, as malonn suggested. It is possible to have a custom function "handle" all OnHit events (well, not handle, but be called when it happens), and an OnHit event handler can also be used to get the attacking ref and the one who gets attacked. There is also the OnMagicEffectHit handler, but I do not know how it would be possible to get the attacker ref from it. The OnHealthDamage might also be handy.

 

http://obse.silverlock.org/obse_command_doc.html#Events

Edited by PhilippePetain
Link to comment
Share on other sites

:laugh: I successfully tested the onhit event handler and have begun various experiments. Can I have multiple event handlers in the same script?

 

---------------------------
OBSE
---------------------------
Unquoted argument 'onhit' will be treated as string by default. Check spelling if a form or variable was intended.

'Cancel' will disable this message for the remainder of the session.

What does this mean? Putting onhit in quotes prevents this message but the scripts work even when onhit is not in quotes.

 

 

Also how can I check if the attacker's weapon is a hammer?

 

Why isn't Getequppedobject working? Is this a bug?

 

set attackweapon to attacker.GetEquippedObject 16
set test to Player.GetEquippedObject 16
Message "Weapon is %.0f. my weapon is %.0f", attackweapon, test, 2

 

From that bit it always prints out to the screen "weapon is 0. my weapon is 0". Is this a bug in OBSE or the construction set extender? :sick:

Edited by NameNotPresent
Link to comment
Share on other sites

You can, for example, try to check if the attacker's currently equipped weapon is defined as blunt. Getting a hammer might be difficult... you could, for example, see if the model path includes the word "hammer" in addition to the weapon being blunt. But that might report all blunt weapons in a "Hammerfell" directory as hammers if a mod adds such. Or all blunt weapons made by someone with a username that contains "hammer". Or if the name contains the word "hammer", too. It might get a bit tricky in the end. :tongue: There are only one- and two-handed weapons, either blades or blunts in Oblivion... :sad:

 

Like

ref    rWeapon
ref    rAttacker    ; The one from event handler

...

let rWeapon := rAttacker.GetEquippedObject 9 ; or 16, they are both weapons... hmm...
If ( GetWeaponType rWeapon == 2 || GetWeaponType rWeapon == 3 ) && ( CompareModelPath "hammer" rWeapon )
    ; This is blunt (1H or 2H) hammer? Maybe... ?
EndIf

I have not yet figured out how to get rid of that error message, though. An OnEquip event handler for a project of mine (that got overly complicated and heavy so I abandoned it) worked despite the warning, though. So I am not sure what it means. Maybe someone with an idea of how to fix it happens to pass by. Like malonn, I suspect (or hope, but dare not confess it). :smile:

 

Does it make any difference to have

Object::PlayerRef

or

Ref::PlayerRef

in the script that sets the handler? And, come to think of it, are the restrictions even necessary if you want it to work every time someone is hit? Could it just be

SetEventHandler "OnHit" YourFunction

and the function will still receive both attacker and target. So that

ScriptName YourFunction

ref   rAttacker
ref   rTarget

Begin Function { rTarget rAttacker }
    ; something
End

would still work? And work for every attacker-target pair, without limits? Or was that what you wanted? Would it work... ?

 

Edit: Oops. Mixed GetEquippedObject with GetEquippedItems into GetEquippedItem. :D Corrected that. And it seems GetEquippedObject return base object. Changed the example thing a bit. And it seems you have edited your post, too. :smile: Try slot 9 instead of 16. Slot 16 worked with sheathed weapon when I used it, though. Maybe 9 works with a drawn one? I am not sure.

 

Edit 2: And the Construction Set Extender is not quilty. It works just fine for me. I think it just receives the commands available from OBSE. The OBSE log shows how OBSE digs up all commands from the plugins. But I am not sure.

Edited by PhilippePetain
Link to comment
Share on other sites

But the event handler function does work and is called when the event takes place? Could it be possible for you to post it here? The event handler script? Assuming, of course, that the event handler is "added" succesfully, and the issue is within the event handler function itself.

 

This is odd. The command works for me (in other things), so the problem has to be in the scripts. Seeing them could help solve the issue, I think. Maybe it is something obvious? Like not calling the function on the proper actor? Or trying to call GetEquippedObject on a bear? Cannot tell before seeing it. :D

Link to comment
Share on other sites

The event handlers that I have tried are all working. So far the only thing that have not work are isstaggered and getequippedobject or getequippedslottype (what ever the alternate for getequippedobject was).

 

Here are the scripts.

 

 

scn AAANNPEventHandlers

;float playerlocation

begin gamemode
SetEventHandler "onhit" AAANNPonhitFunction
;seteventhandler "onrecoil"
SetEventHandler "onstagger" AAANNPonstaggerFunction
SetEventHandler "onmagichit" AAAnnpOnMagichitFunction

;if Player.IsAnimGroupPlaying attackbackpower
;set playerlocation to Player.GetPos y
;set playerlocation to playerlocation + 3
;player.SetPos_T y, playerlocation
;endif
end

 

 

 

 

scn AAANNPonhitFunction

ref target
ref attacker
ref attackweapon
short KnockawayChance
ref test

begin function { target, attacker }
if target.IsBlocking ==1
return
else
set attackweapon to attacker.GetEquippedObject 16
set test to player.GetEquippedObject 16
Message "Weapon is %.0f. my weapon is %.0f", attackweapon, test
if attackweapon.GetWeaponType ==3
;if attackweapon.nameincludes "hammer" ==1
set KnockawayChance to GetRandomPercent + 1
if KnockawayChance > 70
attacker.PushActorAway target, 20
endif
endif
;endif
endif
;target.PlayMagicShaderVisuals effectFireDamage 1
;attacker.PlayMagicShaderVisuals effectFrostDamage 1
end

 

 

 

scn AAANNPonstaggerFunction

ref staggeredactor

begin function { staggeredactor }
Message "STAGGER!!! Cancel" 2
staggeredactor.PlayGroup Idle 1
end

 

 

In that last script I tried isstaggered, but removed it as I figured it was not needed. Note there are various things in the scripts for future plans and experimentation.

Edited by NameNotPresent
Link to comment
Share on other sites

I have yet to test those, but it seems odd if you add the event handlers every time the quest (I assume the first is a quest) updates. Maybe they could be added like once when game is restarted? Or only ever once? I do not know if they are discarded when game is closed and then restarted or what. Something to think about, maybe.


Begin GameMode

    If ( GetGameRestarted == 0 )
        Return
    EndIf

    SetEventHandler "OnHit" Blablabla
    ....

End
The OnStagger handler description says it is called when an actor begins stagger animation... so it will probably only be called when someone is staggered. The reason why weapon is printed as 0 is probably using the %.0f thing. It is useful with numbers, like if you want to print a float variable with four decimals, you would use:

    Message "Player has %.4f bananas", fNumberOfBananas
Which should always print the float with four decimals:

    Player has 0.0000 bananas
Because there are not any. Without mods, I think :D The OBSE command doc has the "Format Specifiers" section in which all the different ones are listed. You will probably need %n to print the name of the reference. Maybe that could solve it? Also, check the other weapon slot, as well. Number 16 works with sheathed ones, at least, but I do not know if it works with drawn one... Maybe that could be worth checking?

 

And the Return command cuts the script's processing (like you know), so I normally use it in an If...EndIf thing as short as possible and place all that should be run in case it is not true after it. Not sure if makes any difference, but at least I can avoid all large If...EndIf things. Like:


    If ( Target.IsBlocking )
        Return
    EndIf

    ; All other things here

The effects sound... interesting. Maybe I should try your mod when it is finished. Make my enemies burn. :) There is also the StopMagicXXX commands, if you want to stop the effects one day. I do not know what happens if they are not stopped. Probably nothing, though. But I am not sure. Edited by PhilippePetain
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...