Jump to content

Recommended Posts

Hello, I have a question if someone could help me with it that would be awesome :D!!

So, lf I want to check if the character is wearing Rabbit Ear Muffs in this code

if inst.sg:HasStateTag("roaring") and v.wearing_rabbit_earmuff_hat? then
return
end

how exactly would I do it? I'm sorry i'm a noob & I don't even know where to look for such a thing in DST's files :(..

So, if someone could help me that would be so wonderful, thanks for reading my question have a great day/night :D!!!

 

I have another simple question is if I want to make this pure black color, what would I do? Also, can someone link me to a good site for calculating colors & stuff then I can do it myself in the future xD...

inst.AnimState:SetAddColour(0,0,0,1)
	inst.AnimState:SetMultColour(0,.05,.85,1)

 

Edited by SuperDavid
1 hour ago, SuperDavid said:

Hello, I have a question if someone could help me with it that would be awesome :D!!

So, lf I want to check if the character is wearing Rabbit Ear Muffs in this code


if inst.sg:HasStateTag("roaring") and v.wearing_rabbit_earmuff_hat? then
return
end

how exactly would I do it? I'm sorry i'm a noob & I don't even know where to look for such a thing in DST's files :(..

So, if someone could help me that would be so wonderful, thanks for reading my question have a great day/night :D!!!

 

I have another simple question is if I want to make this pure black color, what would I do? Also, can someone link me to a good site for calculating colors & stuff then I can do it myself in the future xD...


inst.AnimState:SetAddColour(0,0,0,1)
	inst.AnimState:SetMultColour(0,.05,.85,1)

 

for color (divide the RGB value by 255 to get the number to use):
http://www.rapidtables.com/web/color/RGB_Color.htm


To check equipment, check the inventory component. It depends if you want to execute code at server or at client. If at client, then you have to check the replica of inventory, accessed with inst.replica.inventory I think.
The function of inventory you can use is GetEquippedItem(eslot) , while eslot can be:
EQUIPSLOTS.BODY, EQUIPSLOTS.HANDS, EQUIPSLOTS.HEAD
(if you make this check in modmain, don't forget to put GLOBAL. in front of these)

If your equipment should have a specific tag, you might also use EquipHasTag(tag).

take a look on Attack State, has something related

equip =  inst.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD)

if equip:HasTag("yourtag") then

your cool code.

end

Still, take a peek on the Attack State

Edited by Neutral_Steve
Removed Useless Stuff.

Thanks guys :D! The only problem is that rabbit ear muffs have no tags & they're inside "hats.lua" so I don't know how would I do a prefabpostinit to give it a unique tag then I can call it :shock:! So, if someone can help me with that. that would be great :D!!

4 minutes ago, SuperDavid said:

Thanks guys :D! The only problem is that rabbit ear muffs have no tags & they're inside "hats.lua" so I don't know how would I do a prefabpostinit to give it a unique tag then I can call it :shock:! So, if someone can help me with that. that would be great :D!!

how about

equip =  inst.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD)

if equip.prefab == "earmuff" then

your cool code.

end

idk the earmuff prefab name

Edited by Neutral_Steve
6 minutes ago, Neutral_Steve said:

how about

equip =  inst.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD)

if equip.prefab == "earmuff" then

your cool code.

end

I tried putting this

local equip = v.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD)

like this

for _, v in pairs(very_close_players) do
local equip = v.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD)
 if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not equip.prefab == "earmuffshat" then
  v:DoTaskInTime(0.7, function(v)
  if inst.sg:HasStateTag("roaring") and not v.components.health:IsDead() and not v:HasTag("playerghost") then
  v.sg:GoToState("hit")
  v.components.health:DoDelta(-8.33333333333)
  end
  end)

and I get a crash saying " attempt to index field 'equip' (a nil value) "?

--you always want to make sure that equip can show up as nil, also when checking for something that require a ==, don't use "not something == this", use "something ~= this".
--So I changed it to where, it SHOULDN't crash if equip == nil
for _, v in pairs(very_close_players) do
local equip = v.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD) or nil
 if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and equip.prefab ~= "earmuffshat" then
  v:DoTaskInTime(0.7, function(v)
  if inst.sg:HasStateTag("roaring") and not v.components.health:IsDead() and not v:HasTag("playerghost") then
  v.sg:GoToState("hit")
  v.components.health:DoDelta(-8.33333333333)
  end
  end)

I never saw a component named "equip" ?! maybe this is from DS?
Just use the inventory component check I already described above. And what is the problem about earmuffs? Just do AddPrefabPostInit( "earmuffshat" ,....)

 

edit:

Quote

local equip = v.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD) or nil


@DarkKingBoo: that change won't help, since it is still tried to call a non existent component (even if "equip" component would exist in some cases).
It has to be:
 

local equip = v.components.equip and v.components.equip:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

 

Edited by Serpens
2 minutes ago, SuperDavid said:

@DarkKingBoo I tried that & I got the same exact crash :(..

 

@Serpens I'm kinda a noob & don't know how preform a inventory component check, can you maybe tell me how :)?

I edited my post above with code how it would not crash.  But since equip component does not exist, it won't help you ;)

Just replace inst.components.equip  with inst.components.inventory (in your case "v" of course)

Edited by Serpens

Oops I didn't even notice that it wasn't the inventory component.

make it 

equip = v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

Edit: Darn, Serpens already beat me to it.

Edit: I'm dumb

Edited by DarkKingBoo

Sorry, but I need help again. I have a new problem, this crash happens "attempt to index local 'equip' (a nil value)"  from this line of code

if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and equip.prefab ~= "earmuffshat" then

whenever some player that doesn't have a earmuffhat on & hears the roar, anyway to fix it? Because I don't know :(.

 

@DarkKingBoo Also, what's the difference between  "don't use "not something == this", use "something ~= this"."?

Edited by SuperDavid

Hmm. We need to check to see if equip == nil to prevent that crash. Did you make equip = 

v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

?

Also you can do this:

for _, v in pairs(very_close_players) do
local equip = v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil
 if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring")	then
 if equip == nil or equip.prefab ~= "earmuffshat" then
  v:DoTaskInTime(0.7, function(v)
  if inst.sg:HasStateTag("roaring") and not v.components.health:IsDead() and not v:HasTag("playerghost") then
  v.sg:GoToState("hit")
  v.components.health:DoDelta(-8.33333333333)
  end
  end
  end)

There is a way to check to see if "equip == nil or equip.prefab ~= "rabbitsmuff" " on the line you mentioned but I honestly never found out how to do it (I still have much to learn about lua/coding). But this should still do the trick.

 

Also you don't want to use "not something == this" because it doesn't work as intended, so you use "something ~= this" instead. 

~= is "not equal" just incase you didn't know.

1 hour ago, SuperDavid said:

This's my current code.


for _, v in pairs(very_close_players) do
local equip = v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil
 if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and equip.prefab ~= "earmuffshat" then
  v:DoTaskInTime(0.7, function(v)
  if inst.sg:HasStateTag("roaring") and not v.components.health:IsDead() and not v:HasTag("playerghost") then
  v.sg:GoToState("hit")
  v.components.health:DoDelta(-8.33333333333)
  end
  end)

 

it would be more save to include the crash fix I posted above.
Of course normally every player has an inventory, but maybe not all the time (don't know how it is exacttly for beavermode). And e.g in case your code is executed as client (I think it is not, but who knows what you are coding ;) )

@Serpens I'm so, so sorry i'm super dumb so If I can ask for your help...

This's the entire code...

Spoiler

-- and equip.prefab ~= "earmuffshat"
-- local equip = v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil
for _, v in pairs(close_players) do -- Close players.
 if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
  v:DoTaskInTime(0.7, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(0.8, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(0.9, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1, function(v) 
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.1, function(v) 
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.2, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.3, function(v) 
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.4, function(v) 
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.5, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.6, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.7, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
  v:DoTaskInTime(1.8, function(v)
   if not v:HasTag("perfect") and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and not inst.components.health:IsDead() then
   v.sg:GoToState("hit") v.components.health:DoDelta(-4.16666666667) v.components.sanity:DoDelta(-3.125)
   end
  end)
 end
end

if I wanted to make players or "v" with "earmuffshat" & "footballhat" take none of the effects in this code what exactly would I do? I'm so, so, so sorry for annoying you so much :(, please forgive me!

why should be -- and equip.prefab ~= "earmuffshat" -- wrong?

But didn't you learn in one of your first days, to make this ugly code look better with help of a for loop?

local equip = v.components.inventory and v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil -- does first check if v.components.inventory is true. if it is it will call GetEquippedItem. If not it will be set to nil
for _, v in pairs(close_players) do -- Close players.
    if not v:HasTag("perfect") and v.components.health and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and inst.components.health and not inst.components.health:IsDead() and equip~=nil and equip.prefab ~= "earmuffshat" and equip.prefab ~= "footballhat" then
        for i=0.7, 1.8, 0.1 do -- start at i = 0.7 and go to 1.8 in 0.1 steps
            v:DoTaskInTime(i, function(v)
                v.sg:GoToState("hit")
                v.components.health:DoDelta(-4.16666666667)
                v.components.sanity:DoDelta(-3.125)
            end)
        end
    end
end

 

@Serpens I put the code you gave me

local equip = inst.components.inventory and inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil -- does first check if inst.components.inventory is true. if it is it will call GetEquippedItem. If not it will be set to nil
for _, v in pairs(close_players) do -- Close players.
    if not v:HasTag("perfect") and v.components.health and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and inst.components.health and not inst.components.health:IsDead() and equip~=nil and equip.prefab ~= "earmuffshat" or equip.prefab ~= "footballhat" then
        for i=0.7, 1.8, 0.1 do -- start at i = 0.7 and go to 1.8 in 0.1 steps
            v:DoTaskInTime(i, function(v)
                v.sg:GoToState("hit")
                v.components.health:DoDelta(-4.16666666667)
                v.components.sanity:DoDelta(-3.125)
            end)
        end
    end
end

and if any character's not wearing a hat I get this crash from line, also if anyone was wearing any kind of hat the roar would be nullified not just the earmuffs & footballhat :shock:!

if not v:HasTag("perfect") and v.components.health and not v.components.health:IsDead() and not v:HasTag("playerghost") and inst.sg:HasStateTag("roaring") and inst.components.health and not inst.components.health:IsDead() and equip~=nil and equip.prefab ~= "earmuffshat" or equip.prefab ~= "footballhat" then

20161102003947_1.jpg

 

2 hours ago, Serpens said:

But didn't you learn in one of your first days, to make this ugly code look better with help of a for loop?

I never learned that xD... and I still kinda don't get it, hahaha :)..... but seriously thank you so much for shortening it, my lua is so freaking bloated because of code like that, hopefully with your example I fix it all now!

Edited by SuperDavid

why did you changed on "and" into "or" ? the one before footballhelmet. That way it can't work. Without it you won't get this crash.

The "if" statement works that way :

if bla and blub and bli then

this mean, if bla is true it will check blub. But if bla is false or nil then it won't check the next thing.
therefore I added euip~=nil into that if statement, before equip.prefab is called.

"and" and "or" are compareable to +- to * /.  If you write "if a and b and c or d" this means that a,b and c must be true OR d. So it is like a*b*c+d ;) Therefore, if you want to combine "and" and "or" it is better to add brackets.

The code I gave you should do exactly what I understood you want. If it is not what you want, you have to write it down or try to fix it yourself, with that explantion I wrote above ;)

Okay, so I got your exact code & used it & then I got this crash.

20161102012702_1.jpg

and so I changed

local equip = v.components.inventory and v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

into

local equip = inst.components.inventory and inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

and now nothing inside the "for _, v in pairs(close_players) do" does anything it seems :shock:...

8 minutes ago, SuperDavid said:

Okay, so I got your exact code & used it & then I got this crash.

20161102012702_1.jpg

and so I changed


local equip = v.components.inventory and v.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

into

local equip = inst.components.inventory and inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) or nil

and now nothing inside the "for _, v in pairs(close_players) do" does anything it seems :shock:...

that's because I did not compare alle the details from all the codes you post with the same look ;)
your original code had the "for _, v in pairs(very_close_players) do" function before "local equip = ..". But the code I used to improve it, had it outcommented and outside of the for loop. 
I don't know what you want to do. If you want to check euipment from players or from "inst" (maybe inst is also a player, I don't know).
So depending on what you want, you have to put the lcoal equip inside of the for function or not (and use inst or v)

Edited by Serpens
3 minutes ago, Serpens said:

If you want to check euipment from players or from "inst" (maybe inst is also a player, I don't know).

I'm sorry, I should've been more clear :(. What I want is to check if the other players or you can refer to as "v" if they have a earmuff or footballhat then they don't get effected by the code in  "for _, v in pairs(very_close_players) do.

It doesn't matter what "inst" or my character's wearing on his head.

 

@Serpens Yes, "inst" is refering to my character, this code is in my character.lua it's triggered from my player character

Edited by SuperDavid
1 minute ago, SuperDavid said:

I'm sorry, I should've been more clear :(. What I want is to check if the other players or you can refer to as "v" if they have a earmuff or footballhat then they don't get effected by the code in  "for _, v in pairs(very_close_players) do.

It doesn't matter what "inst" or my character's wearing on his head.

so you are able to fix the code yourself, right? Try it out and if it does not work, ask again ;)

Never mind, I give up. I thought this would be very simple but it's toocomplicated for me :wilson_facepalm:... Nothing I do works & I have no idea how to fix this...

The only other idea I have is do you know how I add a prefabpostinit for all player characters? Then I add a onequip function for all players that just give them inst.soundproof = true then I can check for that instead. That would probably be much easier :)..

AddPlayerPostInit(function(inst) ... end)
to add something to players ;)

And it is easy , if you understand what you do ;) Now it is the time to understand something step by step ;) if you did not understand how exactly the if statement works and why it crashed with your version, I would suggest you to test around here:
http://www.lua.org/demo.html

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
×
  • Create New...