Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#1 Old 29th Oct 2020 at 12: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
Field Researcher
#2 Old 29th Oct 2020 at 1:08 AM Last edited by lizcandor : 29th Oct 2020 at 2: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 12: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
Field Researcher
#4 Old 30th Oct 2020 at 2: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 3: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.
Field Researcher
#6 Old 4th Nov 2020 at 7: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 4: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)
{
}
}
Field Researcher
#8 Old 9th Nov 2020 at 4: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 5: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 6: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
Check out my website for updates on my mods and other work PuddingFace.wixsite.com
Check out my Youtube channel for tutorials(modding tutorials) and other content Youtube

Follow me on Twitter Instagram Pinterest Tumblr
Test Subject
Original Poster
#11 Old 10th Nov 2020 at 2: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 3: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
Check out my website for updates on my mods and other work PuddingFace.wixsite.com
Check out my Youtube channel for tutorials(modding tutorials) and other content Youtube

Follow me on Twitter Instagram Pinterest Tumblr
Field Researcher
#13 Old 10th Nov 2020 at 4: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 10th Nov 2020 at 11:59 PM
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 3: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 7: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 9: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 4: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 8: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 23rd Nov 2020 at 4: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 23rd Nov 2020 at 10: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 24th Nov 2020 at 3: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 24th Nov 2020 at 7: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
Check out my website for updates on my mods and other work PuddingFace.wixsite.com
Check out my Youtube channel for tutorials(modding tutorials) and other content Youtube

Follow me on Twitter Instagram Pinterest Tumblr
Field Researcher
#24 Old 24th Nov 2020 at 7: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.
Virtual gardener
staff: administrator
#25 Old 25th Nov 2020 at 1:50 PM Last edited by Lyralei : 25th Nov 2020 at 2:03 PM.
Quote: Originally posted by lizcandor
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.
I think you're correct here Lizcandor! So seconding this!

Because when you're using foreach loops, you need to use the variable you used to define the class  (in your case 'sim') With a foreach loop you can't actually access the public class of what variable you're casting too, because the variable is the only way for the foreach loop to say 'this single sim we're going to add this buff to'. As foreach loops obviously loop through all the sims it can find inside an array or object.

Right now you're basically doing this:

Code:
foreach (int number in numbers) { 
        return  int;
}

So let's assume 'int' is the 'Sim' class here for a second. int is simply a type (or object in the case of the 'Sim' class), and types of course don't hold any information rather than "Hey i'm a number! Not a string or anything else". The 'number' var on the other hand is what *actually* holds the information. It knows which number it is. Therefore we *actually* want to do this instead:

Code:
foreach (int number in numbers) { 
        return  number;
}
Remember as well, the variable is the only thing that can call functions! You can't ever do 'Sim.AddElement();'. It always has to be accessed through a variable. Which can be done through loops as demonstrated above, but also 'Sim sim = new Sim();' where we would use 'sim' as our way to access the functions that the Sim class has for us. Although I'd choose parameters over the whole 'new' stuff in the case of sims. Or, of course, when we use interactions, 'sim' or 'actor' is already defined. Confused yet? :p It's all about instantiating objects, which is something to get used to when you're starting out with C#...

If you're used to javascript, then I know this whole 'defining' the whole 'int' and 'string' and whatever is super weird. It's pretty rare at least that you need to define or check a type of something. And the whole Object stuff just doesn't exist (unless we're talking somewhat more advanced JS stuff) I had to get used to it as well :p 

(Also see: https://www.geeksforgeeks.org/c-sharp-foreach-loop/ )
Page 1 of 2
Back to top