afetogbo Posted March 9, 2015 Share Posted March 9, 2015 (edited) I found this code in the consolecommands.lua-- Show server announcements:-- To send a one time announcement: c_announce(msg)-- To repeat a periodic announcement: c_announce(msg, interval)-- To cancel a periodic announcement: c_announce()function c_announce(msg, interval) if msg == nil then if TheWorld.__announcementtask ~= nil then TheWorld.__announcementtask:Cancel() TheWorld.__announcementtask = nil end elseif interval == nil then TheNet:Announce(msg) else if TheWorld.__announcementtask ~= nil then TheWorld.__announcementtask:Cancel() end TheWorld.__announcementtask = TheWorld:DoPeriodicTask(interval, function() TheNet:Announce(msg) end, 0) endendlocal function doreset() StartNextInstance({ reset_action = RESET_ACTION.LOAD_SLOT, save_slot = SaveGameIndex:GetCurrentSaveSlot() })endSo i thought it would be cool to make a mod to set up server announcements with a one time set up. I can't figure out how to get it to work though. I tried so many things. All I can come up with is a mod with a command lua to do all the announcements you want in one command. but that isn't the kind of automation I want. Edited March 9, 2015 by afetogbo Link to comment Share on other sites More sharing options...
rezecib Posted March 9, 2015 Share Posted March 9, 2015 @afetogbo, Hmm, I'm guessing you want it to save the running announcements between sessions and restart them when the world/server gets restarted? Link to comment Share on other sites More sharing options...
afetogbo Posted March 10, 2015 Author Share Posted March 10, 2015 well basically the idea was an announcement ticker that boots with the server and every 5 to 10 mins spams some info about forums and what not. Link to comment Share on other sites More sharing options...
afetogbo Posted March 10, 2015 Author Share Posted March 10, 2015 so I gave up on that project for now and got to work on my pigqueen. if you can offer anyway of improving this code i would thank you.local function ontradeforgold(inst, item) inst.SoundEmitter:PlaySound("dontstarve/pig/PigKingThrowGold") for k = 1, item.components.tradable.goldvalue do math.randomseed(os.time()) math.random() local gem_qual = math.random(1000) local count_gem = item.components.tradable.goldvalue if gem_qual >= 901 then local nug = SpawnPrefab("orangegem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) elseif gem_qual >= 801 and gem_qual <= 900 then local nug = SpawnPrefab("yellowgem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) elseif gem_qual >= 651 and gem_qual <= 800 then local nug = SpawnPrefab("greengem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) elseif gem_qual >= 501 and gem_qual <= 650 then local nug = SpawnPrefab("purplegem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) elseif gem_qual >= 301 and gem_qual <= 500 then local nug = SpawnPrefab("redgem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) elseif gem_qual >= 51 and gem_qual <= 300 then local nug = SpawnPrefab("bluegem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) else local nug = SpawnPrefab("orangegem", item.components.tradable.goldvalue) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) end endendit does what it needs to do however it throws all the gems in the same stack instead of spreading it out like gold. i spent many hours trying to figure out a way to get it to spray the stack but just don't know lua well enough. Link to comment Share on other sites More sharing options...
rezecib Posted March 10, 2015 Share Posted March 10, 2015 (edited) @afetogbo, This appears to do the trick for announcements being saved and reloaded.modmain:AddPrefabPostInit("world_network", function() local TheWorld = GLOBAL.TheWorld if not TheWorld.ismastersim then return end TheWorld.net:AddComponent("announcementtracker") local old_c_announce = GLOBAL.c_announce GLOBAL.c_announce = function(msg, interval) old_c_announce(msg, interval) TheWorld.net.components.announcementtracker:Register(msg, interval) endend)scripts/components/announcementtracker:local AnnouncementTracker = Class(function(self, inst) self.inst = inst self.announcement = {}end)function AnnouncementTracker:Register(message, interval) if message == nil then self:Cancel() elseif interval ~= nil then self.announcement.message = message self.announcement.interval = interval endendfunction AnnouncementTracker:Cancel() self.announcement = {}endfunction AnnouncementTracker:OnSave() return { message = self.announcement.message, interval = self.announcement.interval, }endfunction AnnouncementTracker:OnLoad(data) self.announcement.message = data.message self.announcement.interval = data.interval c_announce(self.announcement.message, self.announcement.interval)endreturn AnnouncementTracker As for your pigqueen, you're repeating a lot of code that you don't need to repeat:local function ontradeforgold(inst, item) inst.SoundEmitter:PlaySound("dontstarve/pig/PigKingThrowGold") for i = 1, item.components.tradable.goldvalue do local gem_qual = math.random(1000) local prefab = "orangegem" if gem_qual > 900 then prefab = "orangegem" elseif gem_qual > 800 then prefab = "yellowgem" elseif gem_qual > 650 then prefab = "greengem" elseif gem_qual > 500 then prefab = "purplegem" elseif gem_qual > 300 then prefab = "redgem" elseif gem_qual > 50 then prefab = "bluegem" end local nug = SpawnPrefab(prefab) local pt = Vector3(inst.Transform:GetWorldPosition()) + Vector3(0, 4.5, 0) nug.Transform:SetPosition(pt:Get()) local down = TheCamera:GetDownVec() local angle = math.atan2(down.z, down.x) + (math.random() * 60 - 30) * DEGREES local sp = math.random() * 4 + 2 nug.Physics:SetVel(sp * math.cos(angle), math.random() * 2 + 8, sp * math.sin(angle)) endend Edited March 11, 2015 by rezecib Link to comment Share on other sites More sharing options...
afetogbo Posted March 11, 2015 Author Share Posted March 11, 2015 the announcement thing is cool you should post that mod. the pig queen thing. I put math.randomseed(os.time()) because without it mathrandom will always have the same results. granted it is only on sever restart but still. I wanted it to get a new seed every time. I also added the math.random() before the 1000 because the first random seems to be around the same with each tick of the seed. so like 270 next tick 271 next tick 272. With the math.random above it then it is less predictable.With that wouldn't it be a blue gem if the number is bigger then 51 That is why i put an upper bound on it. I tried something similar to that and it kept saying prefab was not declared. I think I know what i did wrong. just tested and it works fine.still throws everything out in one stack. Next I need to figure out meteor shower. I want to add custom rocks to it. Like tungsten and the copper iron. Link to comment Share on other sites More sharing options...
rezecib Posted March 11, 2015 Share Posted March 11, 2015 I put math.randomseed(os.time()) because without it mathrandom will always have the same results. That is not correct... The game already sets a seed (see main.lua), anyway, otherwise no random events in the game would work properly. I just tested some calls to math.random(1000) and got different results every time. With that wouldn't it be a blue gem if the number is bigger then 51 That is why i put an upper bound on it. No. Because these are elseifs, only one of those statements will be executed. So... it checks the first condition, if it was greater than 900, it'll make it an orange gem. Because that was true, the rest of the elseifs are skipped. As for why the gems aren't being thrown out in different directions, the code is identical to the pig king, so I don't know why that would happen. Print out some of the intermediate values and see what they are. Link to comment Share on other sites More sharing options...
afetogbo Posted March 11, 2015 Author Share Posted March 11, 2015 put this in your modworldgenmain.luaprint ("random number is " .. math.random(1000))print ("random number is " .. math.random(1000))print ("random number is " .. math.random(1000))print ("random number is " .. math.random(1000))print ("random number is " .. math.random(1000))print ("random number is " .. math.random(1000)) first load[00:00:00]: Mod: workshop-401709749 (Afetopia EXMG) Loading modworldgenmain.lua [00:00:01]: random number is 101 [00:00:01]: random number is 251 [00:00:01]: random number is 820 [00:00:01]: random number is 429 [00:00:01]: random number is 47 [00:00:01]: random number is 195 second load[00:00:01]: Mod: workshop-401709749 (Afetopia EXMG) Loading modworldgenmain.lua [00:00:01]: random number is 101 [00:00:01]: random number is 251 [00:00:01]: random number is 820 [00:00:01]: random number is 429 [00:00:01]: random number is 47 [00:00:01]: random number is 195 third load[00:00:01]: Mod: workshop-401709749 (Afetopia EXMG) Loading modworldgenmain.lua [00:00:02]: random number is 101 [00:00:02]: random number is 251 [00:00:02]: random number is 820 [00:00:02]: random number is 429 [00:00:02]: random number is 47 [00:00:02]: random number is 195 I have been working with modworldgenmain.lua mostly so i figured it was the same with modmain. but it isn't. I guess the randomseed doesn't get generated until the map is created. Then i put it into the local function levelpreint and it was after[00:00:25]: scripts/worldgen_main.lua(79,1) SEED = 1426036492 (i thought this was the map seed. doh!) so yah i guess it is totally not needed. damn that would have saved me like 5 hours of research. oh well now i know how to use that. Link to comment Share on other sites More sharing options...
afetogbo Posted March 11, 2015 Author Share Posted March 11, 2015 Okay it was something i did. it is working perfectly. I understand why it wasn't doing it right for me. it is sweet to see different color gems spraying out. Link to comment Share on other sites More sharing options...
afetogbo Posted March 16, 2015 Author Share Posted March 16, 2015 the pig queen is working perfect even got some artwork and anim for her now Link to comment Share on other sites More sharing options...
SenL Posted March 16, 2015 Share Posted March 16, 2015 That's cool (pigqueen). Is she going to be a unique (only one in the map)?If yes, could you share how you do that code? (I haven't done anything in/about world/map gen) 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