Jump to content

OnPlayerFireWeapon


Recommended Posts

hello, I'm trying to get this code to work, whenever i attack, it activates a code.

 

so far i keep getting stuck with "no viable alternative at input 'if' "

 

here is my code

Scriptname myweapon extends ObjectReference Const

explosion property myweapon auto const

Event OnPlayerFireWeapon(Actor akActor) native

	if akActor == Game.GetPlayer()
		Debug.Trace("you attacked")

	endIf
endEvent

//it gives an error; scythswi.psc(7,1): no viable alternative at input 'if'.

what am i missing?

Edited by xBloodTigerx
Link to comment
Share on other sites

Your script shouldnt be const as usual const means that the object does not contain any data and the game can throw it away at will. Also Where you have that script attached to? Also onPlayerFireWeapon will fire only if you are out of combat, you should use "weaponFire" animation event instead.

If I were you I would make new quest which runs automatically and attach script on it. It would look like this:

 

Event onQuestInit()

RegisterForAnimationEvent(game.getplayer(), weaponFire)

Endevent

 

Event OnAnimationEvent(ObjectReference akSource, string asEventName)

If (akSource == Game.GetPlayer() && asEventName == "weaponFire")

Debug.Notification("you fired weapon")

EndIf

EndEvent

Link to comment
Share on other sites

the script is attached to the weapon itself. and thanks, ill try it out.
but is it possible to just call for weaponfire? i don't want it to activate on all the weapons

 

the code still does not work even without it being const, still gives the error. idk what im missing .-.

Edited by xBloodTigerx
Link to comment
Share on other sites

OnPlayerFireWeapon is a function in Actor script. You cannot use it that way in a script that extends ObjectReference. Actor extends ObjectReference but not the other way around.

 

If you still wanted to call OnPlayerFireWeapon, you would do it like this: RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerFireWeapon"), then rename your event to:

 

Event Actor.OnPlayerFireWeapon(Actor akSender, Form akBaseObject)

	if akSender == Game.GetPlayer()
		Debug.Trace("you fired weapon: " + akBaseObject)
	endIf
endEvent
Note that you cannot use the native flag on your functions, and that "OnPlayerFireWeapon(Actor akActor)" is invalid, the native function is "OnPlayerFireWeapon(Form akBaseObject)", you must keep the argument types consistent.. Edited by steve40
Link to comment
Share on other sites

  • Recently Browsing   0 members

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