majistik Posted December 18, 2012 Share Posted December 18, 2012 I made a code (my first code!) which wait for event that is being called when the player fired a bow(OnPlayerBowShot) and equips the player arrows with random arrows from the inventory (from a list), Its also recalculate the random range and reset the array if an arrow have "0" count. The code is compiled but the only debug trace that is being triggered is Event OnEquipped(Actor akActor) Debug.Trace("123pickednow") EndEvent All other debug traces - including the traces on OnInit and OnPlayerBowShot are never triggers. I tried to re-equip the bow and shoot many times. the only debug trace i get in the file is "123pickednow". all other traces never triggered and the code doesnt trigger. Scriptname ABrandomArrow extends ObjectReference Weapon property GlassBowABRandom auto Ammo Property ABArrowBigGreenhead Auto Ammo Property ABArrowBlack Auto Ammo Property ABArrowBlackexp Auto Ammo Property ABArrowBlackexpbig Auto Ammo Property ABArrowblue Auto Ammo Property ABArrowGreen Auto Ammo Property ABArrowIce Auto Ammo Property ABArrowIceExpL Auto Ammo Property ABArrowIceExpS Auto Ammo Property ABArrowOrange Auto Ammo Property ABArrowOrangebaloon Auto Ammo Property ABArrowOrangebaloontimer Auto Ammo Property ABArrowRed Auto Ammo Property ABArrowSmallRed Auto Ammo Property ABArrowWhite Auto Ammo Property ABArrowYellow Auto Ammo Property ABArrowYellowfast Auto Ammo[] BirdsInInentoryArray int RandomX int NumOfBirdsNow string BirdsString Event OnInit() Debug.Trace("1234onint") NumOfBirdsNow = 0 BirdsInInentoryArray = new Ammo[18] EndEvent Event OnEquipped(Actor akActor) Debug.Trace("123pickednow") EndEvent int Function GetNowCountAB() NumOfBirdsNow = 0 if (Game.GetPlayer().GetItemCount(ABArrowBigGreenhead) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowBigGreenhead) endIf if (Game.GetPlayer().GetItemCount(ABArrowBlack) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowBlack) endIf if (Game.GetPlayer().GetItemCount(ABArrowBlackexp) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowBlackexp) endIf if (Game.GetPlayer().GetItemCount(ABArrowBlackexpbig) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowBlackexpbig) endIf if (Game.GetPlayer().GetItemCount(ABArrowblue) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowblue) endIf if (Game.GetPlayer().GetItemCount(ABArrowGreen) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowGreen) endIf if (Game.GetPlayer().GetItemCount(ABArrowIce) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowIce) endIf if (Game.GetPlayer().GetItemCount(ABArrowIceExpL) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowIceExpL) endIf if (Game.GetPlayer().GetItemCount(ABArrowIceExpS) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowIceExpS) endIf if (Game.GetPlayer().GetItemCount(ABArrowOrange) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowOrange) endIf if (Game.GetPlayer().GetItemCount(ABArrowOrangebaloon) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowOrangebaloon) endIf if (Game.GetPlayer().GetItemCount(ABArrowOrangebaloontimer) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowOrangebaloontimer) endIf if (Game.GetPlayer().GetItemCount(ABArrowRed) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowRed) endIf if (Game.GetPlayer().GetItemCount(ABArrowSmallRed) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowSmallRed) endIf if (Game.GetPlayer().GetItemCount(ABArrowWhite) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowWhite) endIf if (Game.GetPlayer().GetItemCount(ABArrowYellow) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowYellow) endIf if (Game.GetPlayer().GetItemCount(ABArrowYellowfast) > 0) NumOfBirdsNow = NumOfBirdsNow+1 BirdsInInentoryArray[NumOfBirdsNow]=(ABArrowYellowfast) endIf return NumOfBirdsNow EndFunction Event OnPlayerBowShot(Weapon akWeapon, Ammo akAmmo, float afPower, bool abSunGazing) Debug.Trace("1234fired") if (akWeapon == GlassBowABRandom) Debug.Trace("1234firedashot") RandomX = Utility.RandomInt(0, NumOfBirdsNow)+1 if (Game.GetPlayer().GetItemCount(BirdsInInentoryArray[RandomX]) == 0) NumOfBirdsNow=GetNowCountAB() RandomX = Utility.RandomInt(0, NumOfBirdsNow)+1 endIf if (NumOfBirdsNow > 1) Game.GetPlayer().EquipItem(BirdsInInentoryArray[RandomX]) Debug.Trace("123equippedrandomarrow") endIf endIf endEvent Thanks. Link to comment Share on other sites More sharing options...
acidzebra Posted December 18, 2012 Share Posted December 18, 2012 (edited) Congrats on your first script :) ...what is this script attached to? Because if it's the bow, equipped objects are essentially treated as being inside a container, and as per this page, objects inside containers are outside of the reach of your script-fu. Attaching scripts directly to the player is bad form, but what you could try is creating a quest with just an empty startup stage, an alias pointing to the player, and attach the script to that alias.Of course, if you only want the script to react to a specific bow, you'll have to build in a check for that. Edited December 18, 2012 by acidzebra Link to comment Share on other sites More sharing options...
majistik Posted December 18, 2012 Author Share Posted December 18, 2012 (edited) Congrats on your first script :) ...what is this script attached to? Because if it's the bow, equipped objects are essentially treated as being inside a container, and as per this page, objects inside containers are outside of the reach of your script-fu. Attaching scripts directly to the player is bad form, but what you could try is creating a quest with just an empty startup stage, an alias pointing to the player, and attach the script to that alias.Of course, if you only want the script to react to a specific bow, you'll have to build in a check for that. Thanks for the replay. The onequip function is working so the best thing to do is to start a quest on the bow equip and stop the quest on de-equip.I need to make a quest that will run the scriptright? Edited December 18, 2012 by majistik Link to comment Share on other sites More sharing options...
acidzebra Posted December 18, 2012 Share Posted December 18, 2012 (edited) Just make a quest and leave it at its default setting (which is "game start enabled" - so will start & run always), and like I said add a player alias (tab quest aliases, make new reference alias, alias name player, fill type = specific reference with "forced reference" set to cell (any) and ref set to playerref, then attach the script to that alias. This is also a requirement of "onplayerbowshot", since the CK wiki page states that Event called when the actor is the player, and the player has fired a bow. If this event is handled in a script that's not on the player, the event will never be hit. Edited December 18, 2012 by acidzebra Link to comment Share on other sites More sharing options...
majistik Posted December 18, 2012 Author Share Posted December 18, 2012 Just make a quest and leave it at its default setting (which is "game start enabled" - so will start & run always), and like I said add a player alias (tab quest aliases, make new reference alias, alias name player, fill type = specific reference with "forced reference" set to cell (any) and ref set to playerref, then attach the script to that alias. This is also a requirement of "onplayerbowshot", since the CK wiki page states that Event called when the actor is the player, and the player has fired a bow. If this event is handled in a script that's not on the player, the event will never be hit. Thanks, I did everything you said. however it still doesnt trigger it, I cant see the quest on the quests list in the game aswell. "game start enabled" is marked Link to comment Share on other sites More sharing options...
acidzebra Posted December 18, 2012 Share Posted December 18, 2012 (edited) That's okay, unless your quest makes quest entries, you won't see it. You can check the quest status from the console with the command sqv QUESTNAME check if it actually is running. Now, since your script is running on a player alias inside a quest, it will have to extend referencealias, not objectreference. So change that. Edited December 18, 2012 by acidzebra Link to comment Share on other sites More sharing options...
majistik Posted December 18, 2012 Author Share Posted December 18, 2012 (edited) That's okay, unless your quest makes quest entries, you won't see it. You can check the quest status from the console with the command sqv QUESTNAME check if it actually is running.Ok its running :)But it doesnt run the code and doesnt trigger the debug traces.What do you recommend to do now?Thanks for helping me :D Edited December 18, 2012 by majistik Link to comment Share on other sites More sharing options...
acidzebra Posted December 18, 2012 Share Posted December 18, 2012 Like I (late-)edited in my former post, your script will now have to extend RefererenceAlias instead of ObjectReference. when you did that sqv command, did you see the player listed as an alias? Link to comment Share on other sites More sharing options...
majistik Posted December 18, 2012 Author Share Posted December 18, 2012 (edited) Like I (late-)edited in my former post, your script will now have to extend RefererenceAlias instead of ObjectReference. when you did that sqv command, did you see the player listed as an alias? Its list the player as alias REF 'Player' -> "(00000014)Edit:Ok looks like its working thank so much :D ReferenceAlias Fixed that! Edited December 18, 2012 by majistik Link to comment Share on other sites More sharing options...
acidzebra Posted December 18, 2012 Share Posted December 18, 2012 So you got it running? Nice one :) It would be nice for other users trying to do the same thing if you documented what you did to make it work - helps for future questions :thumbsup: Link to comment Share on other sites More sharing options...
Recommended Posts