Replies: 23 (Who?), Viewed: 734 times.
Test Subject
Original Poster
#1 Old 29th Oct 2020 at 1:59 AM
Default hey,I need help with a royal mod!
So I am making a royal mod for the sims 3,but I need a lot of help because I am a newbie. First I really need help connecting a trait to a buff like in sims 4,where if you have a trait a buff shows up. I would like if someone helped me with this part so that I can advanced.
Advertisement
Lab Assistant
#2 Old 29th Oct 2020 at 2:08 AM Last edited by lizcandor : 29th Oct 2020 at 3:40 PM.
Quote:
Originally Posted by SimShady19
So I am making a royal mod for the sims 3,but I need a lot of help because I am a newbie. First I really need help connecting a trait to a buff like in sims 4,where if you have a trait a buff shows up. I would like if someone helped me with this part so that I can advanced.


I learned to do that recently! You can make this happen by using an event listener (the tutorial on basic script modding explains) for the event EventTypeId.kTraitGained. Then have your ListenerAction (in the tutorial, that's OnSimEnteredVacationWorld) figure out what the trait that was gained was by adding "TraitNames trait = (e as TraitGainedEvent).TraitName", check if that trait is your royalty trait, and if it is add the buff using Sim.BuffManager.AddElement.

Oh! And if you want the buff to expire and have a chance of coming back (instead of just using a permanent buff) you might be able to do that by having your ListenerAction on kTraitGained add a repeating alarm to the actor of the event (e.Actor as Sim), and having the alarm callback try to apply the buff every time it fires. Explanation of alarms is also in that same tutorial, and there's more on this kind of use of alarms in the forums if you search.
Test Subject
Original Poster
#3 Old 30th Oct 2020 at 1:08 AM
Quote:
Originally Posted by lizcandor
I learned to do that recently! You can make this happen by using an event listener (the tutorial on basic script modding explains) for the event EventTypeId.kTraitGained. Then have your ListenerAction (in the tutorial, that's OnSimEnteredVacationWorld) figure out what the trait that was gained was by adding "TraitNames trait = (e as TraitGainedEvent).TraitName", check if that trait is your royalty trait, and if it is add the buff using Sim.BuffManager.AddElement.

Oh! And if you want the buff to expire and have a chance of coming back (instead of just using a permanent buff) you might be able to do that by having your ListenerAction on kTraitGained add a repeating alarm to the actor of the event (e.Actor as Sim), and having the alarm callback try to apply the buff every time it fires. Explanation of alarms is also in that same tutorial, and there's more on this kind of use of alarms in the forums if you search.


Thank you so much, but there seems to be an error for some reason. I don't know if it's because I did something wrong or...
Screenshots
Lab Assistant
#4 Old 30th Oct 2020 at 3:13 AM
It doesn't work because you're trying to use the line "TraitNames trait = (e as TraitGainedEvent).TraitName" as an alarm callback, which it isn't. It defines the variable "trait", which is a variable of type TraitNames; you should define that variable inside of your callback function (where the tutorial sets the game speed) so your callback can use it to do whatever you want to have happen when it's called. If you read through that and the other script modding tutorials a few more times it should become clearer not only what to do, but why, which is probably more useful to you than what anyway
Test Subject
Original Poster
#5 Old 4th Nov 2020 at 4:55 AM
Quote:
Originally Posted by lizcandor
It doesn't work because you're trying to use the line "TraitNames trait = (e as TraitGainedEvent).TraitName" as an alarm callback, which it isn't. It defines the variable "trait", which is a variable of type TraitNames; you should define that variable inside of your callback function (where the tutorial sets the game speed) so your callback can use it to do whatever you want to have happen when it's called. If you read through that and the other script modding tutorials a few more times it should become clearer not only what to do, but why, which is probably more useful to you than what anyway


I don't want to keep bothering you about this but am i on the right track, private static void OnWorldLoadFinished(object sender, EventArgs e)
{
EventTracker.AddListener(EventTypeId.kTraitGained, new ProcessEventDelegate(TraitNames trait = (e as TraitGainedEvent).TraitName));
}
}
if not is there a reference or did someone make something like this so I can look at this.
Lab Assistant
#6 Old 4th Nov 2020 at 8:24 AM
That would be
Code:
public static void OnWorldLoadFinished(object sender, EventArgs e)
{
    EventTracker.AddListener(EventTypeId.kTraitGained, new ProcessEventDelegate(NameOfYourListener));
}

And then elsewhere, something like
Code:
public static ListenerAction NameOfYourListener(Event e)
{
    TraitNames trait = (e as TraitGainedEvent).TraitName;
    if(trait!=null && trait==(TraitNames)hex-code-of-your-royalty-trait)
    {
      // Do whatever
    }
}
Test Subject
Original Poster
#7 Old 9th Nov 2020 at 5:14 AM
Thank you so much, I just have a question how do I get rid of the error; not all code paths return a value.
public static ListenerAction AristocratTrait(Event e)
{
TraitNames trait = (e as TraitGainedEvent).TraitName;
if (trait != null && trait == (TraitNames)0x7ADB040434CAACBB)
{
}
}
Lab Assistant
#8 Old 9th Nov 2020 at 5:39 AM
Ah, I left something out, sorry! That error is because AristocratTrait is expecting to return a ListenerAction and none is given - you'd need to edit it like this, like you see in the tutorials:

Code:
public static ListenerAction NameOfYourListener(Event e)
{
    TraitNames trait = (e as TraitGainedEvent).TraitName;
    if(trait!=null && trait==(TraitNames)hex-code-of-your-royalty-trait)
    {
      // Do whatever
    }
    return ListenerAction.Keep;
}
Test Subject
Original Poster
#9 Old 9th Nov 2020 at 6:31 PM
Quote:
Originally Posted by lizcandor
Ah, I left something out, sorry! That error is because AristocratTrait is expecting to return a ListenerAction and none is given - you'd need to edit it like this, like you see in the tutorials:

Code:
public static ListenerAction NameOfYourListener(Event e)
{
    TraitNames trait = (e as TraitGainedEvent).TraitName;
    if(trait!=null && trait==(TraitNames)hex-code-of-your-royalty-trait)
    {
      // Do whatever
    }
    return ListenerAction.Keep;
}


Thank you so much it helped, because I was so confused;I have a question about adding buffs I am familiar with it but it seems like I always have an issue adding the code part. I would add something like this Actor.BuffManager.AddElement(BuffNames.Defeat, Origin.FromBeingSubduedByWasher); or like this sim.BuffManager.AddElement(0xFFFFFFFFFFFFFFFF, Origin.None);. And I still get Sim does'nt exist in the current contex or no assembly for buff manager.
Scholar
#10 Old 9th Nov 2020 at 7:44 PM
sim.BuffManager.AddElement(0xFFFFFFFFFFFFFFFF, Origin.None); has to be sim.BuffManager.AddElement((BuffName)(0xFFFFFFFFFFFFFFFF), Origin.None);

Forgot if it was BuffName or BUffNames.

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Test Subject
Original Poster
#11 Old 10th Nov 2020 at 3:00 AM
Quote:
Originally Posted by PuddingFace
sim.BuffManager.AddElement(0xFFFFFFFFFFFFFFFF, Origin.None); has to be sim.BuffManager.AddElement((BuffName)(0xFFFFFFFFFFFFFFFF), Origin.None);

Forgot if it was BuffName or BUffNames.

I have taken your suggestion and it seems like, it just keeps saying sim doesn't exist in current context. It just won't go through.
sim.BuffManager.AddElement((BuffNames)(0xFFFFFFFFFFFFFFFF), Origin.None);
Scholar
#12 Old 10th Nov 2020 at 4:24 AM
Who is sim here? And where are you adding the moodlet? Is it via the trait? Try looking at the lucky trait and how it's adding the lucky moodlet through it.

Is sim supposed to be whoever has the trait?

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
#13 Old 10th Nov 2020 at 5:22 AM
Does your code contain the statement "using Sims3.Gameplay.Actors" in the using section you wrote at the top, and have you defined a Sim object called "sim" before trying to do sim.BuffManager.AddElement? You need to define a variable before you can use it, and to use the Sim class you need to have specified the location where it can be found; it sounds like you might not have done one or both of those things.
Test Subject
Original Poster
#14 Old 11th Nov 2020 at 12:59 AM
Quote:
Originally Posted by lizcandor
Does your code contain the statement "using Sims3.Gameplay.Actors" in the using section you wrote at the top, and have you defined a Sim object called "sim" before trying to do sim.BuffManager.AddElement? You need to define a variable before you can use it, and to use the Sim class you need to have specified the location where it can be found; it sounds like you might not have done one or both of those things.


So I had fixed the problem with the sim part but the next issue was that the part that says buff was the one that had the error.

foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>()) ;
{
sim.BuffManager.AddElement((BuffName)(0xFFFFFFFFFFFFFFFF), Origin.None);

}
Virtual gardener
staff: administrator
#15 Old 11th Nov 2020 at 4:18 PM
Quote:
Originally Posted by SimShady19
So I had fixed the problem with the sim part but the next issue was that the part that says buff was the one that had the error.

foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>()) ;
{
sim.BuffManager.AddElement((BuffName)(0xFFFFFFFFFFFFFFFF), Origin.None);

}
Maybe a weird question, but why is it referring to an empty buff? 
Test Subject
Original Poster
#16 Old 11th Nov 2020 at 8:25 PM
Quote:
Originally Posted by Lyralei
Maybe a weird question, but why is it referring to an empty buff? 


Since I was just trying to test the buff, but it always seems to always have some sort of error. I don't know what I'm doing wrong.
Virtual gardener
staff: administrator
#17 Old 12th Nov 2020 at 10:22 AM
Quote:
Originally Posted by SimShady19
Since I was just trying to test the buff, but it always seems to always have some sort of error. I don't know what I'm doing wrong.
Hrm so with error is it like a null reference? Because that's possibly directed to the code trying to find an instance version of 0xFFFFFFFFFFFFF. So that will always return nothing, therefore the code can't run properly

Althoughhhh I think you're referring to this, right?

Quote:
And I still get Sim does'nt exist in the current contex or no assembly for buff manager.
Which to me sounds like you're missing a few 'using sims3.blahblah' thingies here. So, what I usually do is when I, for the first time, refer to, say, 'Sim'. You need to right-click on it and select something along the lines of 'add sims3.blahblah reference".  

This is, of course, assuming you got all the right DLLs.
Test Subject
Original Poster
#18 Old 17th Nov 2020 at 5:18 PM
Quote:
Originally Posted by Lyralei
Hrm so with error is it like a null reference? Because that's possibly directed to the code trying to find an instance version of 0xFFFFFFFFFFFFF. So that will always return nothing, therefore the code can't run properly

Althoughhhh I think you're referring to this, right?

Which to me sounds like you're missing a few 'using sims3.blahblah' thingies here. So, what I usually do is when I, for the first time, refer to, say, 'Sim'. You need to right-click on it and select something along the lines of 'add sims3.blahblah reference".  

This is, of course, assuming you got all the right DLLs.


I was taking a look at other people's mods and added this foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>()),to my code it helped but now the add element is just acting up. I don't know if anyone has ran onto an error like this or if this is just me.
Virtual gardener
staff: administrator
#19 Old 18th Nov 2020 at 9:37 AM
Quote:
Originally Posted by SimShady19
I was taking a look at other people's mods and added this foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>()),to my code it helped but now the add element is just acting up. I don't know if anyone has ran onto an error like this or if this is just me.
But it does work if you test it with any of EA's buffs? And what kind of error does it give?
Test Subject
Original Poster
#20 Old Yesterday at 5:47 AM
Quote:
Originally Posted by Lyralei
But it does work if you test it with any of EA's buffs? And what kind of error does it give?


it still does, but if i use this.Actor.BuffManager.AddElem ent(0x3E8A 488119A 1FA 27,(O rigin)Re sourceUtils.HashString64("From NursingChild"));. Would there be an issue because it is a custom buff or do people have different ways to add it.
Virtual gardener
staff: administrator
#21 Old Yesterday at 11:02 AM
Quote:
Originally Posted by SimShady19
it still does, but if i use this.Actor.BuffManager.AddElem ent(0x3E8A 488119A 1FA 27,(O rigin)Re sourceUtils.HashString64("From NursingChild"));. Would there be an issue because it is a custom buff or do people have different ways to add it.
IIRC, a custom buff does require you to have the original mod in-game before it could work. That's because the game is also looking for the XML file that's linked with said buff  But in theory, this should also have worked with EA's buffs, so it's really weird that VS is telling you that you can't.

Could you screenshot the errors you're having? I'm personally out of ideas what it could be. It actually sounds more as if there's something in your solution that is screwing things up (So the entire C# project file you're working in with Sharpdevelop/VS). Maybe it might be worth redoing this bit?: 

(Sharp develop) https://modthesims.info/showthread.php?t=632267
(VS) https://www.modthesims.info/wiki.ph..._Studio_project
Test Subject
Original Poster
#22 Old Today at 4:24 AM
Quote:
Originally Posted by Lyralei
IIRC, a custom buff does require you to have the original mod in-game before it could work. That's because the game is also looking for the XML file that's linked with said buff  But in theory, this should also have worked with EA's buffs, so it's really weird that VS is telling you that you can't.

Could you screenshot the errors you're having? I'm personally out of ideas what it could be. It actually sounds more as if there's something in your solution that is screwing things up (So the entire C# project file you're working in with Sharpdevelop/VS). Maybe it might be worth redoing this bit?: 

(Sharp develop) https://modthesims.info/showthread.php?t=632267
(VS) https://www.modthesims.info/wiki.ph..._Studio_project


this is a screenshot of what I'm dealing with.
Screenshots
Scholar
#23 Old Today at 8:12 AM
Quote:
Originally Posted by SimShady19
this is a screenshot of what I'm dealing with.


Don't know why Add Element is giving error. Are you missing a using ....?

Look at the BuffManager class and see if Add element isn't private or something?

If you like my mods. Consider supporting me on Patreon

Follow me on
Twitter
Instagram
Lab Assistant
#24 Old Today at 8:30 AM
I think the problem is that line 38 says Sim.BuffManager.AddElement instead of sim.BuffManager.AddElement? Sim with a capital S is the class, and sim with a lowercase s is the instance of the Sim class that's being worked with.
Back to top