Silane Posted November 6, 2013 Share Posted November 6, 2013 I am wanting to create my first MOD. A relatively simple one, that makes the basic traps more effective...... or at least useful. Allowing for Slurtles, Snurtles and Pengulls to be caught in basic traps. inst:AddTag("canbetrapped") Is the line used in the rabbit, spider and frog scripts for them to be trapped. I'm not altogether experienced at all with MODS and I am tring to figure it out on my own. But if anyone has any suggestions or can help I would love it. Or if anyone would like to try testing it once I have it ready for testing Link to comment Share on other sites More sharing options...
seronis Posted November 6, 2013 Share Posted November 6, 2013 to start your modmain will need to edit the desired prefabs as they are spawned. You can do this by having the following code in your modmain.lua:function doTweak1(inst) inst.components.periodicspawner:SetOnlySpawnOffscreen(false)endfunction doTweak2(inst) inst:AddComponent("stackable") inst.components.stackable.maxsize = 99endAddPrefabPostInit("beefalo", doTweak1)AddPrefabPostInit("rabbit", doTweak2) So you use the postinit() calls to set up the hook, and in the functions you just do the tweaks you want. In my 2 examples that would be a mod to make rabbits VERY stackable and make beefalos willing to poop without an audience required. Link to comment Share on other sites More sharing options...
debugman18 Posted November 6, 2013 Share Posted November 6, 2013 I am wanting to create my first MOD. A relatively simple one, that makes the basic traps more effective...... or at least useful. Allowing for Slurtles, Snurtles and Pengulls to be caught in basic traps. inst:AddTag("canbetrapped") Is the line used in the rabbit, spider and frog scripts for them to be trapped. I'm not altogether experienced at all with MODS and I am tring to figure it out on my own. But if anyone has any suggestions or can help I would love it. Or if anyone would like to try testing it once I have it ready for testing In your AddPrefabPostInit fn(), make sure to addinst:AddComponent("inventoryitem")inst.components.inventoryitem.canbepickedup = false and it should work. It's untested though... Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 Here is the current .lua script I have. Sorry if I am missing something or I didn't do something obvious. XD (Noob remember?) function doTweak1(inst) inst:AddTag("canbetrapped") end function doTweak2(inst) inst:AddTag("canbetrapped") end AddPrefabPostInit("Penguin", doTweak1) inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = false AddPrefabPostInit("Slurtle", doTweak2) inst:Addcomponenet("invetoryitem") inst.components.invetoryitem.canbepickup = false I don't think it works yet, probably not as it wasn't workings before. XD (Pengulls would just walked right over the traps like normal) But now I get this error when trying to load if for testing: Link to comment Share on other sites More sharing options...
debugman18 Posted November 6, 2013 Share Posted November 6, 2013 Here is the current .lua script I have. Sorry if I am missing something or I didn't do something obvious. XD (Noob remember?) function doTweak1(inst) inst:AddTag("canbetrapped")end function doTweak2(inst) inst:AddTag("canbetrapped")end AddPrefabPostInit("Penguin", doTweak1) inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = false AddPrefabPostInit("Slurtle", doTweak2) inst:Addcomponenet("invetoryitem") inst.components.invetoryitem.canbepickup = false I don't think it works yet, probably not as it wasn't workings before. XD (Pengulls would just walked right over the traps like normal) But now I get this error when trying to load if for testing: The lines I gave you go into doTweak1 and doTweak2, sorry. Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 Yay. It isn't crashing now. <3 But the Pengulls are still ignoring the trap..... *Goes off to do research* Anyone is welcome to toss an idea in. function doTweak1(inst) inst:AddTag("canbetrapped") inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = falseendfunction doTweak2(inst) inst:AddTag("canbetrapped") inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = falseendAddPrefabPostInit("Penguin", doTweak1)AddPrefabPostInit("Slurtle", doTweak2)(And for other things, I need to figure out how to make it not "Out of Date" and for my name to show in the "By" of the mod info on the mod page ingame. tnx!) Link to comment Share on other sites More sharing options...
Malacath Posted November 6, 2013 Share Posted November 6, 2013 Yay. It isn't crashing now. <3 But the Pengulls are still ignoring the trap..... *Goes off to do research* Anyone is welcome to toss an idea in. function doTweak1(inst) inst:AddTag("canbetrapped") inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = falseendfunction doTweak2(inst) inst:AddTag("canbetrapped") inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = falseendAddPrefabPostInit("Penguin", doTweak1)AddPrefabPostInit("Slurtle", doTweak2)(And for other things, I need to figure out how to make it not "Out of Date" and for my name to show in the "By" of the mod info on the mod page ingame. tnx!)Well, for one you have written "invetoryitem" instead of "inveNtoryitem".For adding infos like the author to the mod you'll want to create a modinfo.lua next to modmain.lua. It looks like this:name = "Mod Name"description = "Mod Description"author = "Someone"version = "1.0"forumthread = "TBA"api_version = 4icon_atlas = "modicon.xml"icon = "modicon.tex" Link to comment Share on other sites More sharing options...
debugman18 Posted November 6, 2013 Share Posted November 6, 2013 Yay. It isn't crashing now. <3 But the Pengulls are still ignoring the trap..... *Goes off to do research* Anyone is welcome to toss an idea in. function doTweak1(inst) inst:AddTag("canbetrapped") inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = falseendfunction doTweak2(inst) inst:AddTag("canbetrapped") inst:AddComponent("invetoryitem") inst.components.invetoryitem.canbepickup = falseendAddPrefabPostInit("Penguin", doTweak1)AddPrefabPostInit("Slurtle", doTweak2)(And for other things, I need to figure out how to make it not "Out of Date" and for my name to show in the "By" of the mod info on the mod page ingame. tnx!) You can edit modinfo for the last part. I'm not sure why the penguins aren't being affected. Are Slurtles trappable? Edit: Ninjad by Malacath. Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 Sorry about that. XD I had already created a modinfo file. NOw it is showing me as the author. -- This information tells the player more about the modname = "Better Traps"description = "Makes normal traps work on Pengulls, Slurtles, and Snurtles"author = "Silane"Version = "1.0"forumthread = "TBA"api_version = 4--Can specify custom icon for this modicon_atlas = "modicon.xml"icon = "modicon.tex"And since I obliviously can't spell here is the changed modmain.lua.function doTweak1(inst) inst:AddTag("canbetrapped") inst:AddComponent("inventoryitem") inst.components.invetoryitem.canbepickup = falseendfunction doTweak2(inst) inst:AddTag("canbetrapped") inst:AddComponent("inventoryitem") inst.components.invetoryitem.canbepickup = falseendAddPrefabPostInit("Penguin", doTweak1)AddPrefabPostInit("Slurtle", doTweak2)I don't know about Slurtles. Not near a cave. So I was just testing the Pengulls for now since they are easier to get to.. Link to comment Share on other sites More sharing options...
Malacath Posted November 6, 2013 Share Posted November 6, 2013 Now you'll also have to change it to inventoryitem in the linesinst.components.invetoryitem.canbepickup = falseI'm confused you're not getting a crash the way it is right now o.0 On a side not: am I the only one who gets a ton of syntax errors when opening this thread? Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 XD Seems I really am bad at spelling today. Fixed that. Also fixed the syntax error thing. >.< Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 It's not crashing now, that I know of. Even with the fixed "inventory" lines it's still not catch the pengulls.... Link to comment Share on other sites More sharing options...
seronis Posted November 6, 2013 Share Posted November 6, 2013 the prefab names shouldnt be capitalized. penguin not Penguin the reason you dont get a crash for the bad spelling is you are effectively creating brand new variables and assigning them a value. its just the rest of the code never uses your (badly spelled) new variables so they do nothing. Link to comment Share on other sites More sharing options...
Malacath Posted November 6, 2013 Share Posted November 6, 2013 the prefab names shouldnt be capitalized. penguin not Penguin the reason you dont get a crash for the bad spelling is you are effectively creating brand new variables and assigning them a value. its just the rest of the code never uses your (badly spelled) new variables so they do nothing.But as far as I know you cannot create a list with an element in this way. inst.components.invetoryitem is nil before assigning anything to it, in consequence inst.components.invetoryitem.canbepickedup will attempt to index a nil value which should lead to a crash. Probably the function wasn't ever run because the prefab names were capitalised. Srsly, I have to click through a ton of "SyntaxHighlighter\n\nCan't find brush for:nocode" messages, what the hell? Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 I've fixed it. ^^ Alright. I'm sure that this should be fairly simple..... I looked through, just to make sure, the Scripts and Components files and found nothing on the trap item or on any of the trappable creatures files about how they get trapped. So the functions are in the Prefab files, which is what I am trying to base my code off. That being said I think I may be missing some coding or coding something wrong and doing so in a way that the game can't read and/or crash.function Trap1(inst) inst:AddTag("canbetrapped") inst:AddComponent("inventoryitem") inst.components.inventoryitem.canbepickup = falseendfunction Trap2(inst) inst:AddTag("canbetrapped") inst:AddComponent("inventoryitem") inst.components.inventoryitem.canbepickup = falseendAddPrefabPostInit("penguin", Trap1)AddPrefabPostInit("slurtle", Trap2) Link to comment Share on other sites More sharing options...
Malacath Posted November 6, 2013 Share Posted November 6, 2013 And you're using the basic trap which you also use for catching rabbits and spiders? Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 Yup. I think I figured out what I'm doing wrong. And I have an idea how to fix it but I'm not sure.... The script I made tells the game that the slurtles and pengulls are trappable, yes. But it doesn't tell the trap to trap them! ............. Now I get to figure that part out. Link to comment Share on other sites More sharing options...
Malacath Posted November 6, 2013 Share Posted November 6, 2013 Yup. I think I figured out what I'm doing wrong. And I have an idea how to fix it but I'm not sure.... The script I made tells the game that the slurtles and pengulls are trappable, yes. But it doesn't tell the trap to trap them! ............. Now I get to figure that part out. Well, the trap does this local guy = FindEntity(self.inst, self.range, function(guy) return not (guy.components.health and guy.components.health:IsDead() ) and not (guy.components.inventoryitem and guy.components.inventoryitem:IsHeld() ) end, {self.targettag}) if guy then self.target = guy self:StopUpdating() self.inst:PushEvent("springtrap") self.target:PushEvent("trapped") endevery few seconds. So when an entity with the tag "canbetrapped" walks close enough it will push the event "springtrap. This is listened for in the stategraph and ultimately leads to this if self.target and self.target:IsValid() and not self.target:IsInLimbo() then self.target:PushEvent("ontrapped", {trapper=self.inst, bait=self.bait}) if self.onspring then self.onspring(self.inst, self.target, self.bait) end if self.target.components.inventoryitem then self.lootprefabs = {self.target.prefab} else if self.target.components.lootdropper then self.lootprefabs = self.target.components.lootdropper:GenerateLoot() end end ProfileStatsAdd("trapped_" .. self.target.prefab) self.target:AddTag("insprungtrap") -- prevents the same ent from being caught in two traps on the same frame self.target:Remove() endWhen the penguin has the "canbetrapped" tag and the inventoryitem component I don't see what's missing. Link to comment Share on other sites More sharing options...
Silane Posted November 6, 2013 Author Share Posted November 6, 2013 I don't know why it isn't working then..... >.< This should link to the zip file for what I have. (In case I am missing something and/or for anyone who wants to see what they can see) http://www.mediafire.com/download/1h7kxwrkgdbl59d/Better_Traps.zip Link to comment Share on other sites More sharing options...
simplex Posted November 7, 2013 Share Posted November 7, 2013 I don't know why it isn't working then..... >.< This should link to the zip file for what I have. (In case I am missing something and/or for anyone who wants to see what they can see) http://www.mediafire.com/download/1h7kxwrkgdbl59d/Better_Traps.zip It's not working because your mod is crashing on load. You don't have a mod icon yet, so you shouldn't specify it in modinfo.lua. Either delete the two lines referring to it or comment them our (prefix them with "--", without the quotes). Link to comment Share on other sites More sharing options...
Malacath Posted November 7, 2013 Share Posted November 7, 2013 It's not working because your mod is crashing on load. You don't have a mod icon yet, so you shouldn't specify it in modinfo.lua. Either delete the two lines referring to it or comment them our (prefix them with "--", without the quotes).Not really the problem we're searching for. I'm kinda confused because I can't even activate the mod. Well, I can but it will immediatley deactivate again. EDIT: The problem is also in modinfo. Lua is case-sensitive and version is written Verison in here. So making that lower-cas will allow me start the mod. EDIT: @Silane Now the mod works, what you'll need to do next is add an inventoryimage for the penguin and slurtle. It's easy if you are on Windows. Size 64x64 in png format and put them in "bettertraps/images/inventoryimages". Download the Mod Tools from Steam and run the game.Change your modmain like this:Assets ={ Asset("IMAGE", "images/inventoryimages/penguin.tex"), Asset("ATLAS", "images/inventoryimages/penguin.xml"), Asset("IMAGE", "images/inventoryimages/slurtle.tex"), Asset("ATLAS", "images/inventoryimages/slurtle.xml"),}local function doTrap1(inst) inst:AddTag("canbetrapped") inst:AddComponent("inventoryitem") inst.components.inventoryitem.canbepickup = false inst.components.inventoryitem.imagename = "penguin" inst.components.inventoryitem.atlasname = "images/inventoryimages/penguin.xml"endlocal function doTrap2(inst) inst:AddTag("canbetrapped") inst:AddComponent("inventoryitem") inst.components.inventoryitem.canbepickup = false inst.components.inventoryitem.imagename = "slurtle" inst.components.inventoryitem.atlasname = "images/inventoryimages/slurtle.xml"endAddPrefabPostInit("penguin", doTrap1)AddPrefabPostInit("slurtle", doTrap2) Link to comment Share on other sites More sharing options...
Silane Posted November 7, 2013 Author Share Posted November 7, 2013 Thanks. I fixed that now, but it is still crashing in the mods page. But instead of saying it's crashing now it's just disabling it. Link to comment Share on other sites More sharing options...
Silane Posted November 7, 2013 Author Share Posted November 7, 2013 Oh! I will try that! So I need to create images? How do I do that for the tex files? (Tried opening other mod's text files and they never open foe me) Link to comment Share on other sites More sharing options...
simplex Posted November 7, 2013 Share Posted November 7, 2013 Not really the problem we're searching for. I'm kinda confused because I can't even activate the mod. Well, I can but it will immediatley deactivate again. That's exactly what would happen by specifying a modicon without it existing. So I wouldn't say it's "not what you're looking for". But the lack of inventory images would also do that. It's the same issue, an asset declared without existing. Link to comment Share on other sites More sharing options...
Malacath Posted November 7, 2013 Share Posted November 7, 2013 Oh! I will try that! So I need to create images? How do I do that for the tex files? (Tried opening other mod's text files and they never open foe me)I told you: create *.png files with size 64x64... 8and the rest I have written beneath the code)And *.tex files are not text-files, they are images that are compressed into Kleis own format. You can open them with this or if you are on Linux or Mac with this. But the Mod Tools for Windows on Steam allow you to convert the files without any trouble. That's exactly what would happen by specifying a modicon without it existing. So I wouldn't say it's "not what you're looking for".But the lack of inventory images would also do that. It's the same issue, an asset declared without existing.Ahhh sorry, I never made that experience. But still, after fixing that the issue with the upper-case version needed to be fixed as well and only then it worked. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.