Jump to content

Recommended Posts

Alright.

So I managed to swim through a sea of bugs to get my mod working, and now I am moving to step two.

I want to give my character the spiderhat component, and I think I found it here:

 local function spider_update(inst)        local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner        if owner and owner.components.leader then            owner.components.leader:RemoveFollowersByTag("pig")            local x,y,z = owner.Transform:GetWorldPosition()            local ents = TheSim:FindEntities(x,y,z, TUNING.SPIDERHAT_RANGE, {"spider"})            for k,v in pairs(ents) do                if v.components.follower and not v.components.follower.leader and not owner.components.leader:IsFollower(v) and owner.components.leader.numfollowers < 10 then                    owner.components.leader:AddFollower(v)                end            end        end    end    local function spider_enable(inst)        local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner        if owner and owner.components.leader then            owner.components.leader:RemoveFollowersByTag("pig")            owner:AddTag("monster")        end        inst.updatetask = inst:DoPeriodicTask(0.5, spider_update, 1)    end    local function spider_equip(inst, owner)        onequip(inst, owner)        spider_enable(inst)    end    local function spider_unequip(inst, owner)        onunequip(inst, owner)        spider_disable(inst)    end    local function spider_perish(inst)        spider_disable(inst)        inst:Remove()    end 

So my idea is to somehow run the function "spider_equip" on loading a world, but I'm not entirely sure how to go about this.

So I have two guesses as to how to get this to work:

A: paste it directly into webber.lua and have it run with the rest of the prefab

B: Have this script run when the world is loaded?

Any ideas on how I can get this to work? It seems just this code will work, but I will tweak stuff...and maybe add some code from the one man band, where there will be a sanity gain based on number of spider followers.

Any ideas?

P.S. How do spoilers work? I tried <spoiler>yadayadayada</spoiler> several ways and it didn't work.

 

All that code looks like it EXPECTS that the component is attached to an inventory object and not a character. You'll need to rewrite the spider_update function to adjust accordingly.  Also spider_enable is likely what you want to call,  because spider_equip is also written to assume the component is attached to a wearable item instead of directly to a player

All that code looks like it EXPECTS that the component is attached to an inventory object and not a character. You'll need to rewrite the spider_update function to adjust accordingly.  Also spider_enable is likely what you want to call,  because spider_equip is also written to assume the component is attached to a wearable item instead of directly to a player

Wait, so I need to write a component that is attached to a character that calls the function spider_equip? Any ideas of where in the game files I can find a component bound to a specific character for me to study/figure out?

Wait, so I need to write a component that is attached to a character that calls the function spider_equip? Any ideas of where in the game files I can find a component bound to a specific character for me to study/figure out?

No, what he's saying is that all the code implies that the function is called for a prefab which has the inventoryitem component, for example this here

local owner = inst.components.inventoryitem

inst is most likely the player when you're using the function on your character, and the character is surely not an inventoryitem. So you need to sdjust your coed so that it takes into account that inst (in the function call) is actually the entity which the effects should be applied on and not an entity that is in the inventory of the enitity it should be applied on.

If you want this to be a passive effect with no hat required you can go into the stats section of his prefab file and type:

    inst:AddTag("spider")

    inst:AddTag("spiderfriend")

 

 

 

The only problem with this is that if anything attacks a nearby spider the character will automatically attack whatever attacked said spider. You can easily stop this by moving to stop your character from attacking if he's far enough away.

What does each tag do? Is there a way I can stop the automatic attacking? Because that would have a bad effect on the gameplay, especially since using spiders will be a key part of the playstyle.

Edited by goldfish911

grep the lua files for  HasTag("spider") and you'll find all the places that check for its existance.  Easiest way to answer your question

 

-edit-

 

Actually im gonna assume you dont know how to use grep (trust me, learn) and paste the results for 'HasTag("spider'

./scenarios/newgameplus.lua:5:		if v:HasTag("spiderden") and v.components.growable then./components/combat.lua:433:    elseif target:HasTag("insect") or target:HasTag("spider") then./prefabs/spiderden.lua:122:		if v:HasTag("spiderden") or v.prefab == "spiderqueen" then./prefabs/hats.lua:389:                if k:HasTag("spider") and k.components.combat then./prefabs/cavespiders.lua:67:           or (inst:HasTag("spider_warrior") and FindEntity(inst, TUNING.SPIDER_WARRIOR_WAKE_RADIUS, function(...) return FindTargets(inst, ...) end ))./prefabs/cavespiders.lua:99:        return dude:HasTag("spider")./prefabs/spider.lua:74:           or (inst:HasTag("spider_warrior") and FindEntity(inst, TUNING.SPIDER_WARRIOR_WAKE_RADIUS, function(...) return FindWarriorTargets(inst, ...) end ))./prefabs/spider.lua:106:        return dude:HasTag("spider")./brains/spiderbrain.lua:71:            IfNode(function() return self.inst:HasTag("spider_hider") end, "IsHider", ./stategraphs/SGspider.lua:14:            if inst:HasTag("spider_warrior") or inst:HasTag("spider_spitter") then./stategraphs/SGspider.lua:25:            if inst:HasTag("spider_warrior") and./stategraphs/SGspider.lua:29:            elseif inst:HasTag("spider_spitter") and./stategraphs/SGspider.lua:64:    if inst:HasTag("spider_warrior") then./stategraphs/SGspider.lua:66:    elseif inst:HasTag("spider_hider") or inst:HasTag("spider_spitter") then

Thats the output.  You get a nice list of all the files (with line numbers) where the search term was found

Edited by seronis

What do you mean by using spiders?

 

Your character won't attack the spiders,if that's what you thought I meant. I mean, if a pigman attacks a spider, your character will want to attack the pigman. So your chracter wants to protect the spiders. If you do decide to attack a spider, then that spider will become aggressive and combat will continue as normal.

What do you mean by using spiders?

 

Your character won't attack the spiders,if that's what you thought I meant. I mean, if a pigman attacks a spider, your character will want to attack the pigman. So your chracter wants to protect the spiders. If you do decide to attack a spider, then that spider will become aggressive and combat will continue as normal.

By using spiders, I mean a key part of the gameplay will be using spiders to fight stuff, so if the player runs in to protect spiders, it ruins the point of just being able to sic the spiders and stay at a distance. Also, where should I paste those two tags, because I tried pasting them to be initialized with the same function that sets health, life, sanity, and whatnot, and spiders still aggro on me.

grep the lua files for  HasTag("spider") and you'll find all the places that check for its existance.  Easiest way to answer your question

 

-edit-

 

Actually im gonna assume you dont know how to use grep (trust me, learn) and paste the results for 'HasTag("spider'

./scenarios/newgameplus.lua:5:		if v:HasTag("spiderden") and v.components.growable then./components/combat.lua:433:    elseif target:HasTag("insect") or target:HasTag("spider") then./prefabs/spiderden.lua:122:		if v:HasTag("spiderden") or v.prefab == "spiderqueen" then./prefabs/hats.lua:389:                if k:HasTag("spider") and k.components.combat then./prefabs/cavespiders.lua:67:           or (inst:HasTag("spider_warrior") and FindEntity(inst, TUNING.SPIDER_WARRIOR_WAKE_RADIUS, function(...) return FindTargets(inst, ...) end ))./prefabs/cavespiders.lua:99:        return dude:HasTag("spider")./prefabs/spider.lua:74:           or (inst:HasTag("spider_warrior") and FindEntity(inst, TUNING.SPIDER_WARRIOR_WAKE_RADIUS, function(...) return FindWarriorTargets(inst, ...) end ))./prefabs/spider.lua:106:        return dude:HasTag("spider")./brains/spiderbrain.lua:71:            IfNode(function() return self.inst:HasTag("spider_hider") end, "IsHider", ./stategraphs/SGspider.lua:14:            if inst:HasTag("spider_warrior") or inst:HasTag("spider_spitter") then./stategraphs/SGspider.lua:25:            if inst:HasTag("spider_warrior") and./stategraphs/SGspider.lua:29:            elseif inst:HasTag("spider_spitter") and./stategraphs/SGspider.lua:64:    if inst:HasTag("spider_warrior") then./stategraphs/SGspider.lua:66:    elseif inst:HasTag("spider_hider") or inst:HasTag("spider_spitter") then

Thats the output.  You get a nice list of all the files (with line numbers) where the search term was found

Sooo, grep is something one uses to find strings in a file, and you are recommending this so I can find instances where HasTag("spider") can be found and used in my mod, right?

Yes grep comes on any linux system and when I used to use windows i still installed WinGrep because its great at doing quick searches even recursively in a directory tree (searching all sub directories too). Since you didnt know what the spider tag was good for a search for 'hastag' will show all the places in code that check for its existance (they use its presence or lack thereof to choose different behavior)

   inst:AddTag("monster")    inst:AddTag("hostile")    inst:AddTag("epic")        inst:AddTag("largecreature")    inst:AddTag("spiderqueen")        inst:AddTag("spider")

if you tell the game you ARE  a spider queen I believe they will follow you.

Is there a modloading log of some sort or something that allows me to see if the tags are being applied?

EDIT: Both of you were wrong, I not only have to add tags, but I never removed any...So I am still a player, and spiders still aggro.

EDIT2.:Dammit, the tag thing still won't work. I will have to do this the hard way...

Edited by goldfish911

Minitools mod should give you the  system applications hitting ~ I think

 

http://forums.kleientertainment.com/files/file/234-mini-tools/

 

the best way is to spawn spiders at player location and see if the attack or not.

Edited by DarkShiz

Minitools mod should give you the  system applications hitting ~ I think

 

http://forums.kleientertainment.com/files/file/234-mini-tools/

 

the best way is to spawn spiders at player location and see if the attack or not.

I just go into a world with spiders set to "lots" and walk on some creep. They always attack me. Curiously enough, the spiderhat does some wierd team leader thing. It doesn't add the "spider" tag to the player, and it says in its code that if the player attacks a spider, their next target is suggested to be the player. I can't change a component to a tag,sooo...

Now that I think about it, there is a mod that has hounds as friendlies. Maybe I should check that out and see what I can figure out.

AGHH!!!! the mod "wulfe" which makes hounds friendly overwrites hounded.lua, which is a recipe for disaster if I did a similar strategy(Which I may have to). For now, I'll try to do something with the friggin spiderhat.

EDIT:Actually, that mod did the same thing with tags. I don't even....

EDIT2: The tag thing works with hounds, but not spiders. WHY????

EDIT3: pig and pigfriend don't have any effect. This is getting weirder and weirder....

Edited by goldfish911

It wouldn't be a disaster, the problem is that the character still has the tag "character" and the spiders are commanded to attack anything with that tag. It's funny you mention Wolfe, that's my cousins creation XD. Spider issue is in the prefab for spiders. Lemme see if I can figure out a way to convince the spiders only the character with the code is a non character

FIGURED IT OUT! I tried doing this:

inst:AddTag("spider")
inst:AddTag("spiderfriend")
inst:AddTag("monster")
inst:RemoveTag("character")
No auto-kiting when nearby spiders are attacked, but spiders give no **** when the player walks around with them. I might do this to save the spiderhat's purpose! However, I have a feeling lack of the "character" tag could lead to some issues. 

Other things probably wont attack you either for removing character. i would say the best thing to do is add to the spider.lua so they and only they will not attack the character with spiderfriend, right now the spider friend part is not doing anything at all

 

edit:  if you want them to protect you add the tag spider queen or spiderden

Edited by DarkShiz

Adding monster and removing character tags i THINK makes you unable to use a tent. Not sure what other side effects exist.  

 

Which is why i told you about grep.  Stop guessing.  Find the places where the code checks if a tag exists and READ what it does. Then you'll just know the answer

I totally agree with seronis, you shouldn't just remove a tag because it sounds promising without knowing what it actually does. In some cases you can summon disasters.

I did some digging and came up with this(no thanks to grep really)
 
local function NormalRetarget(inst)
    local targetDist = TUNING.SPIDER_TARGET_DIST
    if inst.components.knownlocations:GetLocation("investigate") then
        targetDist = TUNING.SPIDER_INVESTIGATETARGET_DIST
    end
    return FindEntity(inst, targetDist, 
        function(guy) 
            if inst.components.combat:CanTarget(guy)
               and not (inst.components.follower and inst.components.follower.leader == guy) then
                return guy:HasTag("character")
            end
    end)
end
 
So anyone who doesn't have the leader component, granted by the spiderhat, is classified as a "character" by spiders. Later on, maybe not in this code, it says that spiders hate players or those with the tag "pig"
--So if I did something like this to the code:local function NormalRetarget(inst)    local targetDist = TUNING.SPIDER_TARGET_DIST    if inst.components.knownlocations:GetLocation("investigate") then        targetDist = TUNING.SPIDER_INVESTIGATETARGET_DIST    end    return FindEntity(inst, targetDist,         function(guy)             if inst.components.combat:CanTarget(guy)               and not (inst.components.follower and inst.components.follower.leader == guy or inst.HasTag:webber ) then                return guy:HasTag("character")            end    end)end--and if I added this to webber.lua:inst.AddTag:("webber") 

Actually, I can't seem to figure out how to code it so that "guy" is not labeled as a character by spiders, because the function(guy) thing determines later on that if "guy" has the tag "character" or "pig", they will be selected next. I can't seem to figure out how to code it in, but I know what I have to do. I then will have to manually overwrite spider.lua in the scripts for my mod, right? Any ideas?

EDIT: I made a change on line 10, if anyone didn't notice.

EDIT2: I think I screwed up again, it should be guy.HasTag("webber"), not inst.HasTag webber

Amirite?

Edited by goldfish911

I did it! I overwrote spider.lua, stating that anyone with the spiderhat's teamleader component OR the tag "webber" does not have the tag "character" according to spiders. So yeah!  However, taking off a spiderhat aggroes spiders still, but putting it back on makes them forget after they attack once. YAY! Now only to tweak some other stuff, but for now, I shall upload the next beta!

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...