RedHairedHero Posted September 30, 2017 Share Posted September 30, 2017 I would put the stuff I mentioned into the for loop instead of outside of it. Also add prints for each value to make sure they're being generated properly. Print(x) Print (z) Print (_other) Print (_inst) Link to comment Share on other sites More sharing options...
. . . Posted September 30, 2017 Author Share Posted September 30, 2017 Hahaha, sorry I derped out I put the code in the for loop which only happens for players who are 12 distance so the code wouldn't work because it would only check for players in 12 range not 60, but now it's fixed. Thanks for your help man !! Spoiler local far_players = GLOBAL.FindPlayersInRange(x, y, z, (60), true) for a, p in pairs(far_players) do local _other = Point(p.Transform:GetWorldPosition()) local _inst = Point(inst.Transform:GetWorldPosition()) local x = _inst.x - _other.x local z = _inst.z - _other.z if x <= 60 and x > 12 or x < -12 and x >= -60 or z <= 60 and z > 12 or z < -12 and z >= -60 then print("test1") p:DoTaskInTime(.7, function(p) print("test2") p.components.talker:Say(GetString(inst, "ANNOUNCE_DEERCLOPS")) end) end end Link to comment Share on other sites More sharing options...
. . . Posted September 30, 2017 Author Share Posted September 30, 2017 (edited) Okay so I ran into a new problem if you guys can help me out, sorry for all the trouble ! So, I want to give quotes for every character to say something different, now the problem is I tried to add some new quotes into my modmain.lua, like so! STRINGS.CHARACTERS.WILSON.ANNOUNCE_DAEMONROAR = "That sounded crazy!!" STRINGS.CHARACTERS.WATAN.ANNOUNCE_DAEMONROAR = "There can only be one!" STRINGS.CHARACTERS.GENERIC.ANNOUNCE_DAEMONROAR = "W-What WAS that?!" but I get a crash when I try to boot up world saying " attempt to index field '?' (a nil value) " I probably didn't add a new quote the correct way. One more thing, would it be possible to have multiple quotes for a string? Like e.g. I want GENERIC characters to have like 3 different things it could say for "ANNOUNCE_DAEMONROAR" instead of only 1 ! Would that be possible or is it not? Since I see in speech file some quotes have multiple things like when you carry something heavy. Thanks again !! Edited September 30, 2017 by SuperDavid Link to comment Share on other sites More sharing options...
Serpens Posted October 1, 2017 Share Posted October 1, 2017 Unfortunately I do not remember the thread anymore... but I did answer the STRING question quite detailed few months ago. Also searching my posts I do not find it... and I can't remember my response anymore But maybe you can search for my posts. I think I answered something with GetRandomItem. Maybe also STRINGS is in my response. Google and default forum search did not found anything, but maybe you are more skilled to search. (I heard google can also search in a specific website, but don't know how) Comment about the "Point(inst.Transform:GetWorldPosition())" solution and your actual code: You really should have simply used the code I gave you in first response It is the same, except you directly get the distance with one single call, instead of calculating with x,y,z Link to comment Share on other sites More sharing options...
. . . Posted October 1, 2017 Author Share Posted October 1, 2017 2 hours ago, Serpens said: Comment about the "Point(inst.Transform:GetWorldPosition())" solution and your actual code: You really should have simply used the code I gave you in first response It is the same, except you directly get the distance with one single call, instead of calculating with x,y,z That code checks distance same as RedHairedHero code? Sorry I'm dumb & I don't understand where I would put your code or what I would replace with it now xD.. This is my code now, sorry xD! Spoiler local function Roar_Start(inst) if not inst.components.health:IsDead() and inst.sg:HasStateTag("roaring") then local x, y, z = inst.Transform:GetWorldPosition() local players = GLOBAL.FindPlayersInRange(x, y, z, (12), true) local far_players = GLOBAL.FindPlayersInRange(x, y, z, (60), true) local entities = GLOBAL.TheSim:FindEntities(x, y, z, 12, {"_health", "_combat"}, {"player", "veggie", "hive", "soundproof", "wall", "perfect", "shadow", "shadowminion", "shadowchesspiece"}) if inst.components.health and not inst.components.health:IsDead() then for i = 0.7, 1.8, 0.1 do -- Start at i = 0.7 and go to 1.8 in 0.1 steps, repeats 12 times. inst:DoTaskInTime(i, function(inst) if not inst.components.health:IsDead() and inst.sg:HasStateTag("roaring") then local fx = SpawnPrefab("groundpoundring_fx") if fx ~= nil then fx.Transform:SetPosition(x, y, z) end end end) for a, p in pairs(players) do p:DoTaskInTime(i, function(p) if p.soundproof == nil and not p:HasTag("playerghost") and p.components.health and not p.components.health:IsDead() and inst.components.health and not inst.components.health:IsDead() and p.watan == nil then Roar_Player_Damage(p) end end) end for _, v in pairs(entities) do v:DoTaskInTime(i, function(v) if not inst.components.health:IsDead() and inst.sg:HasStateTag("roaring") then Roar_Damage(v) end end) end end end for o, m in pairs(far_players) do local _other = Point(m.Transform:GetWorldPosition()) local _inst = Point(inst.Transform:GetWorldPosition()) local x = _inst.x - _other.x local z = _inst.z - _other.z if x <= 60 and x > 12 or x < -12 and x >= -60 or z <= 60 and z > 12 or z < -12 and z >= -60 then m:DoTaskInTime(.7, function(m, data) m.components.talker:Say(GetString(m, "ANNOUNCE_CHARLIE")) end) end end end end 2 hours ago, Serpens said: Unfortunately I do not remember the thread anymore... but I did answer the STRING question quite detailed few months ago. Also searching my posts I do not find it... Hahaha, if you couldn't find it I definitely can't xD, I tried but this is all I found & it doesn't show how to add new quotes for announcements just quotes for examining items . I wish the search system wasn't so bad Link to comment Share on other sites More sharing options...
Serpens Posted October 1, 2017 Share Posted October 1, 2017 (edited) I just meant this distance line: distance = math.sqrt(inst:GetDistanceSqToInst(m)) -- GetDistanceSqToInst is distance^2 (depending on where you use it, you need of course "local" in front of it, see my code) At the moment you are checking x and z >12 and <60 so I think the result is a quadrat. But distance would be a cycle. (of course you can also get a cycle with x and z, but why making everything so complicated, when you simply can use this one line to get the distance) Found the thread with google searching for this: site:forums.kleientertainment.com serpens strings getrandomitem (but it was not really an answer to what you asked) But "indexing nil" means that you tried to make eg "nil.ANNOUNCE_DAEMONROAR" . So maybe your STRINGS.CHARACTERS.WATAN is not defined yet. So make sure you add the code in correct order. Watan does not exist in the game. So you are adding it the first time. So you first have to make: STRINGS.CHARACTERS.WATAN = {} And then you can add more, like: STRINGS.CHARACTERS.WATAN.ANNOUNCE_DAEMONROAR Edited October 1, 2017 by Serpens Link to comment Share on other sites More sharing options...
. . . Posted October 1, 2017 Author Share Posted October 1, 2017 5 hours ago, Serpens said: Spoiler But "indexing nil" means that you tried to make eg "nil.ANNOUNCE_DAEMONROAR" . So maybe your STRINGS.CHARACTERS.WATAN is not defined yet. So make sure you add the code in correct order. Watan does not exist in the game. So you are adding it the first time. So you first have to make: STRINGS.CHARACTERS.WATAN = {} And then you can add more, like: STRINGS.CHARACTERS.WATAN.ANNOUNCE_DAEMONROAR So I used this to add a new quote for generic characters, e.g. Wilson & he would announce my new quote but everything else he would say would be UNKNOWN_STRING:Blahblahblah, I think I overwrite all the quotes ? Is there a way to add new quotes for character like wilson, wx78 without them losing all their other quotes? Spoiler STRINGS.CHARACTERS.GENERIC = {} STRINGS.CHARACTERS.GENERIC.ANNOUNCE_DAEMONROAR = ("Scary") 5 hours ago, Serpens said: Spoiler I just meant this distance line: distance = math.sqrt(inst:GetDistanceSqToInst(m)) -- GetDistanceSqToInst is distance^2 (depending on where you use it, you need of course "local" in front of it, see my code) At the moment you are checking x and z >12 and <60 so I think the result is a quadrat. But distance would be a cycle. (of course you can also get a cycle with x and z, but why making everything so complicated, when you simply can use this one line to get the distance) So this code " distance = math.sqrt(inst:GetDistanceSqToInst(m)) -- GetDistanceSqToInst is distance^2 " should replace something in this code? Spoiler for o, m in pairs(far_players) do local _other = Point(m.Transform:GetWorldPosition()) local _inst = Point(inst.Transform:GetWorldPosition()) local x = _inst.x - _other.x local z = _inst.z - _other.z if x <= 60 and x > 12 or x < -12 and x >= -60 or z <= 60 and z > 12 or z < -12 and z >= -60 then m:DoTaskInTime(.7, function(m, data) m.components.talker:Say(GetString(m, "ANNOUNCE_DAEMONROAR")) end) end end and sorry thanks for helping & being patient with me & sorry I'm dumb ! Link to comment Share on other sites More sharing options...
Serpens Posted October 1, 2017 Share Posted October 1, 2017 1 minute ago, SuperDavid said: So I used this to add a new quote for generic characters, e.g. Wilson & he would announce my new quote but everything else he would say would be UNKNOWN_STRING:Blahblahblah, I think I overwrite all the quotes ? Is there a way to add new quotes for character like wilson, wx78 without them losing all their other quotes? Reveal hidden contents STRINGS.CHARACTERS.GENERIC = {} STRINGS.CHARACTERS.GENERIC.ANNOUNCE_DAEMONROAR = ("Scary") So this code " distance = math.sqrt(inst:GetDistanceSqToInst(m)) -- GetDistanceSqToInst is distance^2 " should replace something in this code? Reveal hidden contents for o, m in pairs(far_players) do local _other = Point(m.Transform:GetWorldPosition()) local _inst = Point(inst.Transform:GetWorldPosition()) local x = _inst.x - _other.x local z = _inst.z - _other.z if x <= 60 and x > 12 or x < -12 and x >= -60 or z <= 60 and z > 12 or z < -12 and z >= -60 then m:DoTaskInTime(.7, function(m, data) m.components.talker:Say(GetString(m, "ANNOUNCE_DAEMONROAR")) end) end end and sorry thanks for helping & being patient with me & sorry I'm dumb ! You have to do STRINGS.CHARACTERS.WATAN = {} , because Watan does not exist yet, so we have to create an empty "list" for all the string of watan. But for generic there is already a filled list. If you make = {} you are overriding it with an empty list, yes. To be 100% sure you can also add a simple check: if not STRINGS.CHARACTERS.WATAN then -- if it does not exist yet STRINGS.CHARACTERS.WATAN = {} end If you are not sure if something already exists or not, you can use this "if .. then" line, to only set it an empty list, if it does not exist yet. About the distance thing: Really? Please think just a little bit about it Imagine a 2D coordinate system from your math lessons (instead of x and y, you call them x and z). What is your actual code doing? It gets the x and z coordinate from watan (_inst.x) and the x and z coordiante from a player near him (_other.x). Then you are substracting them, to get the distance. You save it in x and z. And then you are checking if x (the distance) is between 12 and 60. Same for z. If you draw this in your coordinate system, you will notice that the result is a quadrat. You need some more advanced calculation, to transform it into a cycle this way. It is much more easier to simply use "distance". Simply forget about the "complicated function" math.sqrt(inst:GetDistanceSqToInst(m)). Just remember that it gets the distance between "inst" and "m". And now where could you use it in your code? I won't say more, even a little child should understand it now Link to comment Share on other sites More sharing options...
. . . Posted October 2, 2017 Author Share Posted October 2, 2017 1 hour ago, Serpens said: You have to do STRINGS.CHARACTERS.WATAN = {} , because Watan does not exist yet, so we have to create an empty "list" for all the string of watan. I don't want to add quotes for watan he already has a speech file & I included all new custom quotes in there ! Sorry if I said something that you misunderstood . 2 hours ago, Serpens said: About the distance thing: Really? Please think just a little bit about it Imagine a 2D coordinate system from your math lessons (instead of x and y, you call them x and z). What is your actual code doing? It gets the x and z coordinate from watan (_inst.x) and the x and z coordiante from a player near him (_other.x). Then you are substracting them, to get the distance. You save it in x and z. And then you are checking if x (the distance) is between 12 and 60. Same for z. If you draw this in your coordinate system, you will notice that the result is a quadrat. You need some more advanced calculation, to transform it into a cycle this way. It is much more easier to simply use "distance". Simply forget about the "complicated function" math.sqrt(inst:GetDistanceSqToInst(m)). Just remember that it gets the distance between "inst" and "m". And now where could you use it in your code? I won't say more, even a little child should understand it now I have less understanding than a little child, the burn is real ! Anyways for anyone that wants to add new quotes existing characters without editing their speech files all you have to do is put something like this in your modmain.lua, I wish I knew how to do it 3 days ago though ! STRINGS.CHARACTERS.WENDY.ANNOUNCE_ROAR = ("Spooky!") Link to comment Share on other sites More sharing options...
Serpens Posted October 2, 2017 Share Posted October 2, 2017 (edited) 8 hours ago, SuperDavid said: I don't want to add quotes for watan he already has a speech file & I included all new custom quotes in there ! Sorry if I said something that you misunderstood . I have less understanding than a little child, the burn is real ! Anyways for anyone that wants to add new quotes existing characters without editing their speech files all you have to do is put something like this in your modmain.lua, I wish I knew how to do it 3 days ago though ! STRINGS.CHARACTERS.WENDY.ANNOUNCE_ROAR = ("Spooky!") I told you about Watan, cause in your code was a line with WATAN.ANNOUNCE and the error message was "index nil". And the = {} was the answer to that problem, cause depending on your other code, this could be one reason for "index nil" error. Your code was this: STRINGS.CHARACTERS.WILSON.ANNOUNCE_DAEMONROAR = "That sounded crazy!!" STRINGS.CHARACTERS.WATAN.ANNOUNCE_DAEMONROAR = "There can only be one!" STRINGS.CHARACTERS.GENERIC.ANNOUNCE_DAEMONROAR = "W-What WAS that?!" And error message "index nil". Unfortunately you did not tell me which line. So I thought the announce line with WATAN was causing it. But obviously it was a different line, so it was not the problem. Does it also work to do STRINGS.CHARACTERS.WENDY.ANNOUNCE_ROAR = {"Spooky!","Oh no"} ? I think it should work, but not sure. Edited October 2, 2017 by Serpens Link to comment Share on other sites More sharing options...
. . . Posted October 2, 2017 Author Share Posted October 2, 2017 10 hours ago, Serpens said: And error message "index nil". Unfortunately you did not tell me which line. So I thought the announce line with WATAN was causing it. But obviously it was a different line, so it was not the problem. That crash happened because there is no "STRINGS.CHARACTERS.WILSON" Wilson uses "STRINGS.CHARACTERS.GENERIC", sorry about that, hahaha ! 10 hours ago, Serpens said: Does it also work to do STRINGS.CHARACTERS.WENDY.ANNOUNCE_ROAR = {"Spooky!","Oh no"} ? I think it should work, but not sure. Yes, it works if done like this, so can have multiple examine in a quote. Thank you ! Spoiler STRINGS.CHARACTERS.GENERIC.ANNOUNCE_ROAR = { "Scary", "Oh no", } Link to comment 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