- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Help with Scripting
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Help with Scripting
Replies: 4 (Who?), Viewed: 896 times.
#1
30th Aug 2014 at 3:25 PM
Last edited by leefish : 31st Aug 2014 at 7:46 AM.
Reason: added spoiler tags
Posts: 516
Thanks: 4225 in 14 Posts
Help with Scripting
Hi everyone, I'm working on another mod that tries to implement a Horse Temperament System. The more you ride a horse, it becomes easier to ride. This is shown by 1. moodlets, and 2. Chance of throwing sims / biting / kicking (implemented later)
However, I can't declare Sim in the callback when the timer ends:
Code:
using System; using System.Collections.Generic; using System.Text; using Sims3.SimIFace; using Sims3.Gameplay.EventSystem; using Sims3.Gameplay.Actors; using Sims3.Gameplay.ActorSystems; using Sims3.Gameplay.Utilities; namespace Simsmatthew { public class Simsmatthew_HorseOverhaul { //EXTERNAL XML TUNABLES [Tunable] protected static bool kInstantiator = false; [Tunable] protected static int kStartupHorseTemperament = 125; [Tunable] protected static float kDaysAddTemperamentScale = 7f; //INTERNAL [PersistableStatic] public static Dictionary<ulong, int> HorseTemperament = new Dictionary<ulong, int>(); public static EventListener RodeHorseListener; public static Sim HorseManager; static Simsmatthew_HorseOverhaul() { LoadSaveManager.ObjectGroupsPreLoad += OnPreLoad; World.OnWorldLoadFinishedEventHandler += new EventHandler(OnWorldLoadFinished); World.OnWorldQuitEventHandler += new EventHandler(OnWorldQuitEvent); } private static void OnPreLoad() { (new LoadBuffs()).LoadBuffData(); } private static void OnWorldLoadFinished(object sender, EventArgs e) { RodeHorseListener = EventTracker.AddListener(EventTypeId.kSimRodeHorse, new ProcessEventDelegate(OnSimRodeHorse)); //Unsure of this EvnetListener foreach (Sim horse in Sims3.Gameplay.Queries.GetObjects<Sim>()) { if (horse != null && horse.IsInActiveHousehold && horse.IsHorse && !HorseTemperament.ContainsKey(horse.SimDescription.SimDescriptionId)) { HorseTemperament.Add(horse.SimDescription.SimDescriptionId, kStartupHorseTemperament); AlarmManager.Global.AddAlarm(kDaysAddTemperamentScale, TimeUnit.Days, new AlarmTimerCallback(Simsmatthew_HorseOverhaul.OnTemperamentTimerEndReloop), "Loop Horse Add Temperament Scale Alarm", AlarmType.AlwaysPersisted, horse); } } } private static void OnTemperamentTimerEndReloop() { Sim horse; HorseTemperament[horse.SimDescription.SimDescriptionId]++; } public static void OnWorldQuitEvent(object sender, EventArgs e) { EventTracker.RemoveListener(RodeHorseListener); } private static ListenerAction OnSimRodeHorse(Event e) { try { Sim sim = e.Actor as Sim; //Actor Sim: Is a Human Sim horse = e.TargetObject as Sim; //Target Sim: Is a Horse if (sim.SimDescription.IsHuman && horse.SimDescription.IsHorse && HorseTemperament.ContainsKey(horse.SimDescription.SimDescriptionId)) { if (HorseTemperament[horse.SimDescription.SimDescriptionId] > kStartupHorseTemperament * 0.8) { sim.BuffManager.AddElement (0xF1A5F6BFB88B4B27, Origin.FromRidingHorse); //Add buff to horse pending! } if (HorseTemperament[horse.SimDescription.SimDescriptionId] > kStartupHorseTemperament * 0.6 && HorseTemperament[horse.SimDescription.SimDescriptionId] <= kStartupHorseTemperament * 0.8) { sim.BuffManager.AddElement (0xA92BF36A8CC66D1A, Origin.FromRidingHorse); } if (HorseTemperament[horse.SimDescription.SimDescriptionId] > kStartupHorseTemperament * 0.4 && HorseTemperament[horse.SimDescription.SimDescriptionId] <= kStartupHorseTemperament * 0.6) { sim.BuffManager.AddElement (0xC1529553847A4DCF, Origin.FromRidingHorse); } if (HorseTemperament[horse.SimDescription.SimDescriptionId] > kStartupHorseTemperament * 0.2 && HorseTemperament[horse.SimDescription.SimDescriptionId] <= kStartupHorseTemperament * 0.4) { sim.BuffManager.AddElement (0x9D07FBFCAA220471, Origin.FromRidingHorse); } if (HorseTemperament[horse.SimDescription.SimDescriptionId] <= kStartupHorseTemperament * 0.2) { sim.BuffManager.AddElement (0x9628DB30E3C25B4B, Origin.FromRidingHorse); } HorseTemperament[horse.SimDescription.SimDescriptionId]--; } } catch (Exception) { } return ListenerAction.Keep; } } }
The hex numbers are references to custom moodlets.
I can only assign it to be "null" which obviously isn't correct.
I have tried assigning it to be the variable "horse" in OnSimRodeHorse and other places as well, but without success.
The problem in concern is "private static void OnTemperamentTimerEndReloop()". Tried setting it to public as well.
Help please!
Advertisement
Field Researcher
#2
31st Aug 2014 at 7:44 AM
Posts: 338
Thanks: 28674 in 186 Posts
Looking at the "AddSeasicknessAlarm" method in Sims3.Gameplay.ActorSystems.Seasickness should help, basically create a "helper" class to store the information you need for your callback (Btw, it's a good habit to check that "sim" and "horse" are not null at the start OnSimRodeHorse just in case)
#3
31st Aug 2014 at 9:54 AM
Posts: 516
Thanks: 4225 in 14 Posts
Thanks icarus_allsorts, it worked again
You're forever the best xdd
Thanks so much!
You're forever the best xdd
Thanks so much!
#4
1st Sep 2014 at 9:50 AM
Last edited by SimsMatthew : 1st Sep 2014 at 11:34 AM.
Posts: 516
Thanks: 4225 in 14 Posts
I now have another problem: there is no EventListener that actually checks when a Sim is added to household (from NRaas and the game .dlls). The tutorial here: http://modthesims.info/wiki.php?tit..._Extra_Sim_Data adds the dictionary whenever a Sim is instantiated, not just added to household. But I'm afraid that if I put a sim.IsInActiveHousehold check there it will be too early... Hmm..... What should I do? Writing up a manual interaction for players to manually iterate all Sims in town and then add the dictionary to eligible sims is my last resort.
I'm actually even afraid that when a Sim is added to household, it isn't re-instantiated at all, causing the kSimInstantiated event not to fire at all, making it useless..
EDIT: The reason I do not add the code of adding a key in the dictionary if none for that particular horse is found, is because "instructing players to ride a horse at least once to activate the system" is probably just the same as "click the interaction to manually add keys to the dictionary for the eligible horses if none is found for each one." I have thought of using "kSimDismountsHorse" since when a horse is bought, it is ridden, thus when the sim dismounts, the system is added as well, making the system fire almost instantly. But, this doesn't work for adopted ones or tamed wild horses, so I have no idea what to do. As I said before, I am trying to think of alternatives before resorting to the last method.
I'm actually even afraid that when a Sim is added to household, it isn't re-instantiated at all, causing the kSimInstantiated event not to fire at all, making it useless..
EDIT: The reason I do not add the code of adding a key in the dictionary if none for that particular horse is found, is because "instructing players to ride a horse at least once to activate the system" is probably just the same as "click the interaction to manually add keys to the dictionary for the eligible horses if none is found for each one." I have thought of using "kSimDismountsHorse" since when a horse is bought, it is ridden, thus when the sim dismounts, the system is added as well, making the system fire almost instantly. But, this doesn't work for adopted ones or tamed wild horses, so I have no idea what to do. As I said before, I am trying to think of alternatives before resorting to the last method.
#5
6th Sep 2014 at 2:34 PM
Posts: 516
Thanks: 4225 in 14 Posts
I have done that above parts.
Another question: How can I actually make an Actor horse and a human sim to get riding? I mean, I have the RidingPosture.AnimateSimAndStartRiding method when the Sim exits the rabbithole, but how to get them actually go into correct postures?? Can anyone give some codes???
Another question: How can I actually make an Actor horse and a human sim to get riding? I mean, I have the RidingPosture.AnimateSimAndStartRiding method when the Sim exits the rabbithole, but how to get them actually go into correct postures?? Can anyone give some codes???
Who Posted
|