#1

22nd Sep 2019 at 2:19 PM
Last edited by Lyralei : 22nd Sep 2019 at
3:16 PM.
Posts: 3,891
Thanks: 10204 in 80 Posts
30 Achievements
Tip/brains needed for instantiating objects on world loading
Yes! Another coding thread

I am so sorry.
However, currently i'm working on a script where I'd add new thingies and features for snow, which includes the worst idea ever, but adding more meshes to (most or all) trees. Because SpeedTree's TOU simply does not allow ANY mesh-y tweaking done and reuploaded (Unless this is done inside of EA), I want to add the meshes through a script. Also because we somehow need to have a condition where we know that it's snowing and then adding the mesh.
Now the code currently isn't exactly done, it's in it's very testy and debugging state, so currently it will create meteors at every position of a tree and basically logging the position into notification in the worst way possible, but it does the job

(So still need to finetune it

) And it's not winter-compatible yet (aka, that the mesh would show up and get destroyed if it isn't winter or is winter).
Code:
public static void OnWorldLoadFinished(object sender, EventArgs e)
{
// Load in all the alarms after 5 min of the world being loaded.
AlarmManager.Global.AddAlarm(5f, TimeUnit.Minutes, new AlarmTimerCallback(LoadNotificationAfter_5_SimMinutes), "LoadLyraleiSnowModloader", AlarmType.DeleteOnReset, null);
AlarmManager.Global.AddAlarm(0f, TimeUnit.Minutes, new AlarmTimerCallback(GetAllFrozenObjects), "LoadFrozenObjects", AlarmType.DeleteOnReset, null);
}
public static void LoadNotificationAfter_5_SimMinutes()
{
StyledNotification.Format format = new StyledNotification.Format("Snow Additions has loaded!", StyledNotification.NotificationStyle.kGameMessagePositive);
StyledNotification.Show(format);
}
public static void GetAllFrozenObjects()
{
// Here we get an array of all the Flora being loaded into the world (So trees and bushes)
Flora[] objects = Sims3.Gameplay.Queries.GetObjects<Flora>();
if(objects.Length == 0)
{
Exception exception = new Exception();
ShowException(exception);
}
else
{
foreach(Flora flora in Sims3.Gameplay.Queries.GetObjects<Flora>())
{
// Get the object id of the tree/bush
ObjectGuid objectId = flora.ObjectId;
// Store the tree/bush position/transform into a var
mTransform = flora.Transform;
mPosition = flora.Position;
mForwardVector = flora.ForwardVector;
mDisplayPosition = flora.DisplayPosition;
mPositionXZ = flora.PositionXZ;
mPositionOnFloor = flora.PositionOnFloor;
mBoundingBox = flora.Dimensions;
// Convert them to strings for now to use in the debug log
mTransformString = mTransform.ToString();
mPositionString = mPosition.ToString();
mForwardString = mForwardVector.ToString();
mDisplayPositionString = mDisplayPosition.ToString();
mPositionXZString = mPositionXZ.ToString();
mPositionOnFloorString = mPositionOnFloor.ToString();
mBoundingBoxString = mBoundingBox.ToString();
StyledNotification.Format objectReactionLog = new StyledNotification.Format(LogDebugInfo(), StyledNotification.NotificationStyle.kSystemMessage);
StyledNotification.Show(objectReactionLog);
GameObject meteor = GlobalFunctions.CreateObject("MeteorHuge", mPosition, 0, mForwardVector) as GameObject;
} // end for loop
} // end else
} // end GetAllFrozenObjects
public static string LogDebugInfo()
{
StringBuilder stringBuilder = new StringBuilder();
try
{
stringBuilder.AppendFormat(string.Format("\n Tree or bush position: {0}", mPositionString));
stringBuilder.AppendFormat(string.Format("\n Tree or bush transform: {0}", mTransformString));
stringBuilder.AppendFormat(string.Format("\n Tree or bush ForwardVector: {0}", mForwardString));
stringBuilder.AppendFormat(string.Format("\n Tree or bush Display Position: {0}", mDisplayPositionString));
stringBuilder.AppendFormat(string.Format("\n Tree or bush Position XZ: {0}", mPositionXZString));
stringBuilder.AppendFormat(string.Format("\n Tree or bush Position on Floor: {0}", mPositionOnFloorString));
stringBuilder.AppendFormat(string.Format("\n Tree or bush Bounding Box: {0}", mBoundingBoxString));
}
catch
{
stringBuilder.AppendFormat(string.Format("\n Exception was thrown in LogDebugInfo(). Couldn't load everything properly
"));
}
return stringBuilder.ToString();
}
Now, I noticed that OnWorldLoadFinished() Seems to have a few lasting minutes before it would stop, because, of course, it's an event! Those are supposed to stop at some point. However, the time given for that event isn't long enough for my code to execute.
All the other events I've found don't seem to meet the needs, and I'm not sure if at "OnWorldLoadStartedEventHandler()" or "OnStartupAppEventHandler()" Would do the trick since it has to be done at a point that all the trees are instantiated.
Thoughts?