whatsherface Posted September 24, 2016 Share Posted September 24, 2016 (edited) Hi there! thanks for taking the time to read this and hopefully give me some hints as to how to solve my problem. I'm making a mod which adds a series of characters that belong to my friends into the game. Right now I'm having the mopst difficulty implementing a character who is a vampire into the game. This requires several perks and a new item. In the end I want it to turn out like this: Mundy the Vampire: Perk 1: Takes damage while in sunlight. - This can be avoided by using an umbrella during the day. Perk 2: Drinks blood -Mundy can eat normal food but it only restores 25% of the usual hunger value. -Instead he can eat Bloodbags, which can be crafted only by other players using Mosquito Sack, Stinger, and 50 Health. -Alternatively he can consume Mosquito Sacks themselves for much less health and hunger. Perk 3: Friend of Bats -Basilisks don't attack him Spoiler I have no clue how to go about Perk 1, even after looking into Wx-78's damage during rain. For Perk two I've created the item "Blood Bag" but I can't seem to get the -50 Health to take effect when I craft it. I looked into the recipe for the Tell Tale Heart and found I needed to use CHARACTER_INGREDIENT.HEALTH instead of just "health". The only problem is I crash with a "attempt to index global 'CHARACTER_INGREDIENT' (a nil value)" In game the item also comes up as a "MISSING_NAME". I also want this recipe to be hidden from Mundy himself. Here is my current recipie: local bloodbag_recipie = Recipe("bloodbag", {Ingredient("mosquitosack", 1), Ingredient("stinger", 1), Ingredient(CHARACTER_INGREDIENT.HEALTH, 50)}, RECIPETABS.SURVIVAL, TECH.NONE) bloodbag_recipie.sortkey = 1 bloodbag_recipie.atlas = "images/inventoryimages/bloodbag.xml" STRINGS.RECIPE_DESC.BLOODBAG = "Description." How would I go about making Mosquito Sacks edible for him only, and Reduce the amount of hunger other foods give him? For Perk 3 I looked into Webber's prefab and found the tag "Spider Whisperer." How would I go about recreating that with Basilisks? Thanks again for taking a look into my problems here. ^^ TLDR: How can I make a character take damage in the sun? How can I prevent that damage with an umbrella? How do I fix my Item's recipe and make it exclusive to all characters but one? How can I make Mosquito Sacks edible for a single character instead of healing them? How can I reduce the amount of hunger food gives a certain character? How do I make a mob not aggressive to a certain character? EDIT: Solution for Perk 1: Spoiler WIP Solution for Perk 2 Spoiler WIP Solution for Perk 3 Spoiler WIP Edited September 28, 2016 by whatsherface Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/ Share on other sites More sharing options...
whismerhill Posted September 25, 2016 Share Posted September 25, 2016 (edited) for perk 1 looking at wx78 this doesn't seem too difficult please keep in mind I don't have dst so things might have to get adapted. in the character prefab, in the base function you'll need to declare a periodic task which will refer to another function which you could call : dosunlightdmg , in wx78 this is the line : Spoiler inst:DoPeriodicTask(1/10, function() dorainsparks(inst, 1/10) end) after that you just take the function : local function dorainsparks(inst, dt) rename it to dosunlightdmg then adapt the inside to conditions you need for sunlight dmg I'd just check : if daytime & notincave then full dmg elseif evening & notincave then half dmg now there's the incave check, not sure how to go about checking whether there is light coming in from a crack and not just a fire or something edit: you can check out sanity.lua for some examples on light Edited September 25, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-817886 Share on other sites More sharing options...
whatsherface Posted September 28, 2016 Author Share Posted September 28, 2016 (edited) On 9/24/2016 at 10:10 PM, whismerhill said: for perk 1 looking at wx78 this doesn't seem too difficult please keep in mind I don't have dst so things might have to get adapted. in the character prefab, in the base function you'll need to declare a periodic task which will refer to another function which you could call : dosunlightdmg , in wx78 this is the line : Hide contents inst:DoPeriodicTask(1/10, function() dorainsparks(inst, 1/10) end) after that you just take the function : local function dorainsparks(inst, dt) rename it to dosunlightdmg then adapt the inside to conditions you need for sunlight dmg I'd just check : if daytime & notincave then full dmg elseif evening & notincave then half dmg now there's the incave check, not sure how to go about checking whether there is light coming in from a crack and not just a fire or something edit: you can check out sanity.lua for some examples on light Hmm.. Okay I've been going at this for a few days and I'm still a little lost. Here's what my character prefab looks like now: Spoiler Edit: Spoiler local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } local prefabs = {} local start_inv = { } local function onbecamehuman(inst) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "mundy_speed_mod", 1) inst:DoPeriodicTask(1/10, function() dosunlightdmg(inst, 1/10) end) end local function onbecameghost(inst) inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "mundy_speed_mod") end local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) if inst:HasTag("playerghost") then onbecameghost(inst) else onbecamehuman(inst) end end local function dosunlightdmg(inst, dt) if TheWorld.state.isday --& notincave then inst.components.health:DoFireDamage(.05, false, true) end else if TheWorld.state.isdusk --& notincave then inst.components.health:DoFireDamage(.01, false, true) end end local common_postinit = function(inst) inst.MiniMapEntity:SetIcon( "mundy.tex" ) inst:AddTag("vampire") end local master_postinit = function(inst) inst.soundsname = "willow" inst.components.health:SetMaxHealth(125) inst.components.hunger:SetMax(175) inst.components.sanity:SetMax(200) inst.components.combat.damagemultiplier = 1 inst.components.hunger.hungerrate = 1.5 * TUNING.WILSON_HUNGER_RATE inst.components.locomotor.walkspeed = (5.5) inst.components.locomotor.runspeed = (9.5) inst.components.eater.foodprefs = { FOODTYPE.BLOOD, FOODTYPE.MEAT, FOODTYPE.GENERIC, } inst.OnLoad = onload inst.OnNewSpawn = onload end return MakePlayerCharacter("mundy", prefabs, assets, common_postinit, master_postinit, start_inv) Edited September 28, 2016 by whatsherface Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819426 Share on other sites More sharing options...
whismerhill Posted September 28, 2016 Share Posted September 28, 2016 what's your problem exactly ? and why didn't you post this as text ? (I use code javascript since there is no code lua for highlighting) as I said I don't own DST, a few things I see : -1 in DS, spider.lua they use GetClock():IsDay(), you'll have to check if TheWorld.state.isday is correct -2 you declared notincave somewhere ? or is notincave an available variable in DST to check if the player is in a cave ? when I wrote this originally, I thought you'd understand that this was not real code but shortcuts for the checks that had to be done : in DS in cave_entrance.lua the code GetWorld():IsCave() returns if the current world is currently a cave but you'll have to check for an equivalent for DST, or if this one is still available. -3 line 36 it missing the end of the starting if line 32 -4 current content of line 37 & following should be pushed to line 39 and line 37 is missing the end of the function started line 31 and finally here's a thread I found randomly : might or might not help you : Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819439 Share on other sites More sharing options...
whatsherface Posted September 28, 2016 Author Share Posted September 28, 2016 11 hours ago, whismerhill said: what's your problem exactly ? and why didn't you post this as text ? (I use code javascript since there is no code lua for highlighting) as I said I don't own DST, a few things I see : -1 in DS, spider.lua they use GetClock():IsDay(), you'll have to check if TheWorld.state.isday is correct -2 you declared notincave somewhere ? or is notincave an available variable in DST to check if the player is in a cave ? when I wrote this originally, I thought you'd understand that this was not real code but shortcuts for the checks that had to be done : in DS in cave_entrance.lua the code GetWorld():IsCave() returns if the current world is currently a cave but you'll have to check for an equivalent for DST, or if this one is still available. -3 line 36 it missing the end of the starting if line 32 -4 current content of line 37 & following should be pushed to line 39 and line 37 is missing the end of the function started line 31 and finally here's a thread I found randomly : might or might not help you : Whoops. Sorry I thought It might have been easier then a wall of text to have an Image. My bad. I'll edit the previous post right away. ^^ Right now the error I'm getting is: Spoiler [string "../mods/DST TF2 Tumblr Community OC Pack/scripts/prefabs/mundy...."]:32: 'then' expected near '&' I understand NotInCave is a shortcut, I've been trying to find the real code for what I need. I had only been leaving it there as a placeholder. Duh! I can't believe I forgot the Ends there. I'll definitely check out the Thread. I'm sorry If i'm not as competent with coding as I should be. Thank you for having patience with me. Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819607 Share on other sites More sharing options...
whismerhill Posted September 28, 2016 Share Posted September 28, 2016 np, it's just I was like wtf is his problem to begin with ? xD Spoiler if ImUsingWallofTextInSpoiler then ItsMuchBetter = true else DontForgetTheCodeTagToo = true end Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819612 Share on other sites More sharing options...
whatsherface Posted September 28, 2016 Author Share Posted September 28, 2016 14 minutes ago, whismerhill said: np, it's just I was like wtf is his problem to begin with ? xD Hide contents if ImUsingWallofTextInSpoiler then ItsMuchBetter = true else DontForgetTheCodeTagToo = true end Whoops! I'll fix that...again. ^^ I'll keep looking through the DST code for the caves part of what I'm looking for. Right now the Error I'm getting is: Spoiler 37: 'end' expected (to close 'function' at line 33) near 'else' Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819614 Share on other sites More sharing options...
whismerhill Posted September 28, 2016 Share Posted September 28, 2016 (edited) dude either you're like, wayyyy tired or you need glasses or something xD (joke inside) hint : Spoiler local function dosunlightdmg(inst, dt) | if TheWorld.state.isday --& notincave | | then inst.components.health:DoFireDamage(.05, false, true) | end <= ????? | else | | if TheWorld.state.isdusk --& notincave | | | then inst.components.health:DoFireDamage(.01, false, true) | | end | end ??? I added cosmetic vertical bars to show the point but of course you don't use them in the code also of note you seem to be doing low dmg over short period of time, although I'm certain it causes no problem, if it was me I'd increase the dmg a bit, and reduce the periodicity example if you're doing .05 dmg each tenth of a second, you could instead do .5 dmg each second or .25 dmg each half second or even 2 dmg every 4 seconds. That's purely a choice though and hardly breaks anything that I know of. Edited September 28, 2016 by whismerhill missed that you had an end which should not be there Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819615 Share on other sites More sharing options...
whatsherface Posted September 28, 2016 Author Share Posted September 28, 2016 56 minutes ago, whismerhill said: dude either you're like, wayyyy tired or you need glasses or something xD (joke inside) hint : Hide contents local function dosunlightdmg(inst, dt) | if TheWorld.state.isday --& notincave | | then inst.components.health:DoFireDamage(.05, false, true) | end | else | | if TheWorld.state.isdusk --& notincave | | | then inst.components.health:DoFireDamage(.01, false, true) | | end | end ??? Both probably. I'm going to take a nap before I get even more frustrated. @_@ Spoiler local function dosunlightdmg(inst, dt) if TheWorld.state.isday --& notincave then inst.components.health:DoFireDamage(.05, false, true) end else if TheWorld.state.isdusk --& notincave then inst.components.health:DoFireDamage(.01, false, true) end end end Now I'm getting a: 'end' expected (to close 'function' at line 33) near 'else'. When I put the extra end there like this: local function dosunlightdmg(inst, dt) if TheWorld.state.isday --& notincave then inst.components.health:DoFireDamage(.05, false, true) end end else if TheWorld.state.isdusk --& notincave then inst.components.health:DoFireDamage(.01, false, true) end end end I get: '<eof>' expected near 'else'. Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819627 Share on other sites More sharing options...
whismerhill Posted September 28, 2016 Share Posted September 28, 2016 (edited) the syntax is : if then else end else is optional, one end per function, one end per if there's too much ends here don't take error messages to the letter, they are hints not absolute rules, it can't know what you were trying to achieve & which way it should be corrected. correct syntax but go sleep dude & if you need them go buy glasses too local function dosunlightdmg(inst, dt) if TheWorld.state.isday --& notincave then inst.components.health:DoFireDamage(.05, false, true) else if TheWorld.state.isdusk --& notincave then inst.components.health:DoFireDamage(.01, false, true) end end end if you have trouble with indenting stuff , may I suggest other ways to work around it: example of dosunlightdmg with less indentation : local function dosunlightdmg(inst, dt) if TheWorld.state.isnight then return end -- this here escapes the whole function right away --& notincave if TheWorld.state.isday then inst.components.health:DoFireDamage(.05, false, true) return end -- above we escaped again with a return as what we needed is done and the rest of the function is useless if that condition was met inst.components.health:DoFireDamage(.01, false, true) -- due to the returns this line will get executed only if both other conditions fail which means it's dusk basically end -- and there we have it only a single indentation, no huge pyramids Edited September 28, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819629 Share on other sites More sharing options...
whatsherface Posted September 28, 2016 Author Share Posted September 28, 2016 3 hours ago, whismerhill said: the syntax is : if then else end else is optional, one end per function, one end per if there's too much ends here don't take error messages to the letter, they are hints not absolute rules, it can't know what you were trying to achieve & which way it should be corrected. correct syntax but go sleep dude & go buy glasses too local function dosunlightdmg(inst, dt) if TheWorld.state.isday --& notincave then inst.components.health:DoFireDamage(.05, false, true) else if TheWorld.state.isdusk --& notincave then inst.components.health:DoFireDamage(.01, false, true) end end end I took my nap and I got my trusty glasses. My working (Thanks to you) code is this now. It successfully causes fire damage during the day and dusk, except when the player is in a cave. Now all that's left for this first perk is to replace the placeholder "NoUmbrellaOrShelter" so that the character can avoid this damage by standing under shelter or holding an umbrella. Time to start digging through code again! ^^ Spoiler local function dosunlightdmg(inst, dt) if TheWorld.state.isday and GetWorld():IsCave() == nil --& NoUmbrellaOrShelter then inst.components.health:DoFireDamage(.05, false, true) else if TheWorld.state.isdusk and GetWorld():IsCave() == nil --& NoUmbrellaOrShelter then inst.components.health:DoFireDamage(.01, false, true) end end end Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-819710 Share on other sites More sharing options...
whismerhill Posted September 29, 2016 Share Posted September 29, 2016 you can further simplify this, if you wish as follows : Hide contents local function dosunlightdmg(inst, dt) if TheWorld.state.isday and not GetWorld():IsCave() --& NoUmbrellaOrShelter then inst.components.health:DoFireDamage(.05, false, true) elseif TheWorld.state.isdusk and not GetWorld():IsCave() --& NoUmbrellaOrShelter then inst.components.health:DoFireDamage(.01, false, true) end end the else can be transformed into an "elseif" which removes one level of indentation and instances of : GetWorld()IsCave() == nil you can write : not GetWorld()IsCave() On Second thought I'm not a pro LUA user but I think I would rework it even further local function dosunlightdmg(inst, dt) if not GetWorld():IsCave() --[[ and not Umbrella and not Shelter --]] then if TheWorld.state.isday then inst.components.health:DoFireDamage(.05, false, true) elseif TheWorld.state.isdusk then inst.components.health:DoFireDamage(.01, false, true) end end end reason for this last version : we avoid checking cave, umbrella & shelter twice and it's also simpler if you have to make conditions edits, since you will have only a single line to maintain instead of two. just need to replace "umbrella" & "shelter" with the proper checks Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-820079 Share on other sites More sharing options...
Maris Posted September 29, 2016 Share Posted September 29, 2016 Can you show your art of vampire and bloodbags? Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-820113 Share on other sites More sharing options...
whatsherface Posted September 29, 2016 Author Share Posted September 29, 2016 (edited) 8 hours ago, whismerhill said: you can further simplify this, if you wish as follows : Reveal hidden contents local function dosunlightdmg(inst, dt) if TheWorld.state.isday and not GetWorld():IsCave() --& NoUmbrellaOrShelter then inst.components.health:DoFireDamage(.05, false, true) elseif TheWorld.state.isdusk and not GetWorld():IsCave() --& NoUmbrellaOrShelter then inst.components.health:DoFireDamage(.01, false, true) end end the else can be transformed into an "elseif" which removes one level of indentation and instances of : GetWorld()IsCave() == nil you can write : not GetWorld()IsCave() On Second thought I'm not a pro LUA user but I think I would rework it even further local function dosunlightdmg(inst, dt) if not GetWorld():IsCave() --[[ and not Umbrella and not Shelter --]] then if TheWorld.state.isday then inst.components.health:DoFireDamage(.05, false, true) elseif TheWorld.state.isdusk then inst.components.health:DoFireDamage(.01, false, true) end end end reason for this last version : we avoid checking cave, umbrella & shelter twice and it's also simpler if you have to make conditions edits, since you will have only a single line to maintain instead of two. just need to replace "umbrella" & "shelter" with the proper checks I'll post again when I figure out the checks for those ^^ Thanks. 6 hours ago, Maris said: Can you show your art of vampire and bloodbags? I'm still working on the actual in game art but here's what I have for the select screen portrait. I used the vanilla Mosquito Sack and made it look a little bit fuller for the bloodbag art. Spoiler Good news and bad news I figured out how to check if the character is holding an umbrella or not by giving the character a tag when holding it and preventing the sun damage if they have that tag. Bad news is that the caves got borked somehow? Yesterday the code I had was working just fine, but now I'm getting a "attempt to call IsCave(): a nil value." Even with the updated code you gave me... Back to the drawing board. Edited September 29, 2016 by whatsherface Link to comment https://forums.kleientertainment.com/forums/topic/70402-help-and-questions-about-creating-a-new-character/#findComment-820182 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now