Jump to content

Getting someone to hate someone else's guts


Recommended Posts

I'm planning on making a mod of Risky Boots and figure it'd be fun to have her lose sanity when close to certain characters, like my other Shantae character mods, hero types, Willow (she hates the girl scouts), ect. Is there a way to have this happen that's easy to edit when more modded characters show up? I think it's possible with a table or something...

Link to comment
Share on other sites

local range = TUNING.SANITY_EFFECT_RANGE
local count = 0
local ents = TheSim:FindEntities(x, y, z, range)

inst:DoPeriodicTask(0, function()
    for k,v in pairs(ents) do 
	    if v.prefab == " The guy I really hate " then
	    	count = count + 1
        end
    end
    if count > 0 then
        inst.components.sanity.dapperness = count * TUNING.DAPPERNESS_SMALL * -1
    else
        inst.components.sanity.dapperness = 0
    end
    count = 0
end)

This should do the job.

Link to comment
Share on other sites

On 1/8/2019 at 4:45 AM, Norfeder said:

local range = TUNING.SANITY_EFFECT_RANGE
local count = 0
local ents = TheSim:FindEntities(x, y, z, range)

inst:DoPeriodicTask(0, function()
    for k,v in pairs(ents) do 
	    if v.prefab == " The guy I really hate " then
	    	count = count + 1
        end
    end
    if count > 0 then
        inst.components.sanity.dapperness = count * TUNING.DAPPERNESS_SMALL * -1
    else
        inst.components.sanity.dapperness = 0
    end
    count = 0
end)

This should do the job.

Err...

I had to change the X Y Z because the game yelled at me for not giving them a value. And if I only replace range with a number, a glitched-out lobby happens.

Screenshot (52).png

Edited by icantevenname
More info
Link to comment
Share on other sites

To get the x, y and z, you just need to do this:

local x,y,z = inst.Transform:GetWorldPosition()

where inst is your character.

What do you mean by "glitched out lobby"?

You also need to replace 

" The guy I really hate "

with the name of the character to want to hate. 

And if I'm not mistaken, you need to move this line

local ents = TheSim:FindEntities(x, y, z, range)

to be right after this line

inst:DoPeriodicTask(0, function()

otherwise it'll never update the ents-collection.

Edited by Ultroman
Link to comment
Share on other sites

15 hours ago, Ultroman said:

To get the x, y and z, you just need to do this:


local x,y,z = inst:GetPosition()

where inst is your character.

What do you mean by "glitched out lobby"?

You also need to replace 


" The guy I really hate "

with the name of the character to want to hate. 

And if I'm not mistaken, you need to move this line


local ents = TheSim:FindEntities(x, y, z, range)

to be right after this line


inst:DoPeriodicTask(0, function()

otherwise it'll never update the ents-collection.

Not sure if I did it right...

Screenshot (66).png

Link to comment
Share on other sites

You deleted the line

local ents = TheSim:FindEntities(x, y, z, range)

As I said, move that line just under this line

inst:DoPeriodicTask(0, function()

Obviously, now that you've put in the line

local x,y,z = inst.Transform:GetWorldPosition()

just below that line, it should instead be:

inst:DoPeriodicTask(0, function()
	local x,y,z = inst.Transform:GetWorldPosition()
	local ents = TheSim:FindEntities(x, y, z, range)

 

Just updated the answer.

Edited by Ultroman
Link to comment
Share on other sites

3 hours ago, Ultroman said:

You deleted the line


local ents = TheSim:FindEntities(x, y, z, range)

As I said, move that line just under this line


inst:DoPeriodicTask(0, function()

Obviously, now that you've put in the line


local x,y,z = inst:GetPosition()

just below that line, it should instead be:


inst:DoPeriodicTask(0, function()
	local x,y,z = inst:GetPosition()
	local ents = TheSim:FindEntities(x, y, z, range)

 

Just updated the answer.

Now it's saying "calling 'FindEntities' on bad self (number expected, got table)

 Is the local range not enough?

Link to comment
Share on other sites

No. Just saying that there's a difference between how it's used depending on whether or not it is used in modmain.lua

Post a zip of your mod with your newest code (the one giving the last error) so I can take a look.

Link to comment
Share on other sites

On 3/2/2019 at 11:28 PM, Ultroman said:

Change it to this


inst:DoPeriodicTask(0, function(inst)
	local x,y,z = inst.Transform:GetWorldPosition()
	local ents = TheSim:FindEntities(x, y, z, range)

 

20190304011257_1.thumb.jpg.a7c80abfa752b37d0c132fca263be3fd.jpg

Works now! Now to see if it can respond to more than one type of character.

Link to comment
Share on other sites

26 minutes ago, Ultroman said:

It can ;)

If it can, then I don't see it...

If I use "or", it affects Risky even when no one listed is nearby. Or in the world.

If I use "and", it only affects Risky when everyone listed is nearby.

If I use ("shantae") + ("willow") + ect..., I get a crash report.

If I use ",", I get another crash report.

Link to comment
Share on other sites

16 hours ago, Ultroman said:

I don't know what you're talking about :) Show me your code, and tell me what you want it to do.

5c7de71510a9a_Screenshot(67).thumb.png.cb32e5704f822da7830d005fd3106142.png

I want it so that characters other than Shantae cause Risky to lose Sanity when nearby. But when I set it up like this, she loses sanity regardless if anyone's nearby.

Link to comment
Share on other sites

Well your operators are a little incorrect.

You are doing a comparison properly in the first one but not the other 3 prefabs.

I would suggest just making a table containing all your strings outside above your loop

Local hates = {
"shantae" = true,
"willow" = true,
Etc
}

--Then just do one comparison

if hates[v.prefab] then
 count = count +1
end

This makes it easier to update as you just add your new characters to the table. Rather than having to make that if statement longer.

Edited by IronHunter
Also doing this on mobile sucks...
Link to comment
Share on other sites

1 hour ago, IronHunter said:

Well your operators are a little incorrect.

You are doing a comparison properly in the first one but not the other 3 prefabs.

I would suggest just making a table containing all your strings outside above your loop

Local hates = {
"shantae" = true,
"willow" = true,
Etc
}

--Then just do one comparison

if hates[v.prefab] then
 count = count +1
end

This makes it easier to update as you just add your new characters to the table. Rather than having to make that if statement longer.

20190304234350_1.thumb.jpg.f907703268e723d551d129c752689477.jpg20190304234414_1.thumb.jpg.cee87577e5fb0905740263e6ffc1e63b.jpg20190304234420_1.thumb.jpg.cf40500cebcb18c8b231a871ebad3a24.jpgHad a feeling a table would work fine. Just only needed to make a tweak here an' there, there already was a hate list for vegetables (Risky hates vegetables) so I had to rename the hated characters table and needed to remove the "". It works just fine now! Thanks, you lot!   

Link to comment
Share on other sites

Just to complete the original code (not sure what you ended up with), and support a few hated characters, you'd need to do:

if v.prefab == "shantae" or v.prefab == "willow" then
	count = count + 1
end

I thought it was only going to be one hated character. To support more hated characters and allow for easier extendability, IronHunter's solution is more elegant.

Edited by Ultroman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...