#WindTurbine Modding
1 messages · Page 1 of 1 (latest)
Ok let me rephrase our current issue
- when we craft the item. It does not autodrop on the ground. It stays in inventory. Similarily to the steamgen mod we have the needed code there in the right place in the folder structure.
- when we manually drop it we get the error screen I posted above
and it becomes a normal generator
is it an IsoGenerator type?
the vanilla one checks if the generator is an IsoGenerator
afaik yes it does
@dark shale I setup a thread here for any help to make our mod function
-
CanBeDoneFromFloor:true,
in recipe, allows items to be added to the ground
2. can you look in console.txt / coop-console.txt for severe / stack trace logs?
not sure where your server logs are
this is the part of the code that is supposed to drop it
addOrDrop might work only with CanBeDoneFromFloor:true
^the pic of scripts you posted
this is the server side lua code
--**WindTurbineGenerator By Zefnoly And Anthropy **
if isClient() then return end
local function noise(message) print('MOWindTurbineGenerator.lua: '..message) end
function Recipe.OnCreate.WindTurbineGenerator(items, result, player)
result:getModData().windpower = 0 --Wind value on item creation in the world I think! Originally used for Water!
end
local function ReplaceExistingObject(object, fuel, condition)
local cell = getWorld():getCell()
local square = object:getSquare()
local item = InventoryItemFactory.CreateItem("WindTurbine.Generator")
if item == nil then
noise('Failed to create WindTurbine.Generator item')
return
end
item:setCondition(condition)
item:getModData().fuel = fuel
item:getModData().windpower = windpower
-- local index = object:getObjectIndex()
square:transmitRemoveItemFromSquare(object)
local javaObject = IsoGenerator.new(item, cell, square)
-- IsoGenerator constructor calls AddSpecialObject, probably it shouldn't.
-- square:AddSpecialObject(javaObject, index)
javaObject:transmitCompleteItemToClients()
end
local function NewWindTurbineGenerator(object) --decides what it has on creation
local fuel = 50 --Just testing to see if this happens with our generator
local condition = 100
ReplaceExistingObject(object, fuel, condition)
end
local PRIORITY = 5
MapObjects.OnNewWithSprite("windturbine_01_0", NewWindTurbineGenerator, PRIORITY)
Events.OnObjectAdded.Add(function(isoObject)
if instanceof(isoObject, 'IsoGenerator')then
NewWindTurbineGenerator(isoObject)
end
end)```
Oh?
Will see if that works
It could help if you sent the error log
The one you get when you click on 'Errors' on top of this screen
ok I might be wrong on that, I was thinking of something somebody else said before. Another person who made a normal generator recipe.
But this will only drop item if it exceeds the limit of your inventory
steamturbine mod did not have that in their script for their item
yet that LUA code worked there
Is it because the module name in our script does not say "WindTurbineGenerator" instead of "WindTurbine"?
Beacuse the turbine is called WindTurbineGenerator in our code all the time
the lua part
you call Recipe.OnCreate.WindTurbine but its called Recipe.OnCreate.WindTurbineGenerator in the lua file @dense pumice
https://steamcommunity.com/sharedfiles/filedetails/?id=2812037911&searchtext=generator+recipe
the addordrop code might not be good for generators, I think it was removing them in that mod
Ok now it crafts the normal generator. And it stil doesnt forcedrop
no idea what is going on atm xxD
when do you expect it to drop?
in debug you can fit unlimited number of generators in your inventory, they would drop if they don't fit
yeah but you normally cant get them in your inventory
when you right click a vanilla generator
it can only ever be in your arm slots
the steamgenerator mirrored this behavoir
to the point where they added lua code to prevent it from ending up in inventory upon crafting by using the line of code I provided
HandItems are in your inventory too, just saying
clientside
so you are saying you can put the vanilla generator in your inventory. Without "cheating it inn" and carry it around with it being there?
because I can only ever click "take generator" with it ending up in my arms
and if I try to drag it to the top of my inventory screen so it is out of my hands, you cant
let me check, but what I meant is: Items equipped in hand are considered to be in player's inventory
unless you use the cheat menu to spawn it in inventory
im trying right now
it has special behavoir
you cant even put it in backpack afaik. Only in vehicles and crate storage
I just said you can put it in crates and such
but you cant put it in the proper unequiped player inventory
it can always ever be carried in your hands
The vanilla one also weighs 40 so that could be an addition to why you cant put it in your inventory
you can have it in player inventory only if you use the item menu to put it there
I used to put generators in sits with low capacity, before they patched it 
Yea it forces it in the ISTakeGenerator action
ok I fixed the error
it was due to the script
thing is when I drop it now. Instead of getting error
it just drops the vanilla generator like before
also when I craft it. It crafts the vanilla generator. Not my windturbine gen
and if I spawn the windturbine gen item
it also drops the vanilla generator
at least we are not getting any errors
This does not forcedrop it
function ISCraftAction:addOrDropItem(item, ...)
local ret = {oldAddOrDropItem(self, item, ...)}
if item:getFullType() == 'WindTurbine.Generator' then
local gen = self.character:getCurrentSquare():getGenerator()
if gen then
updateSpriteAndModData(gen, item) --Not sure what does...
end
end
return unpack(ret)
end```
if it fits it doesn't drop
In godmode it will always fit
player inventory is 50
godmode is off
our current problem is stil that the tile ingame does not interact like it should and when we craft the item. It turns into a normal generator in inventory. And when we drop a forcespawned version of our item. It drops a normal generator
when I say tile. I mean if I use tilebrush
as I cant get the tile otherwise due to the item always dropping a normal gen
How do you set the tile?
I pickup generator, put it into a composter and transfer into player inventory. Generator is not equipped.
I think thats a hack
As I said, drag the item not right click.
Regardless... Our item does not drop our generator
but the vanilla one
and when I craft it after adding "Generator" on "WindTurbine" in our script it does not even craft our item anymore
but the vanilla generator
Maybe do setSprite()?
the server side map object code contains this
Events.OnObjectAdded.Add(function(isoObject)
if instanceof(isoObject, 'IsoGenerator')then
NewWindTurbineGenerator(isoObject)
end
end)```
Our goal now is really just to be able to write a mod that adds a "clone" of the vanilla generator that behaves like a seperate item and sprite ingame. So we can build from there...
Since the steamgen mod does that. With some minor adjustments to how it fuels and with references to how we can add our own values to the generatorinfowindow we reference and look at how it derives stuff
we get our tiles to work in the original steamgen mod by just renaming things. For learning purposes. So the tileset is not the issue here
basically our current problem is that...
When we craft our item now. It makes a normal generator item.
When we drop a forcefully spawned version of our item "due to crafting recipe not crafting it for some reason" it also drops a normal generator
to the recipe. By adding Generator on the name there. It creates the ingame generator
But if I just call that "WindTurbine" rather than "WindTurbineGenerator" it crafts out distinct item instead
I thought I had to call it "WindTurbineGenerator" because in our code that is what we call it most of the time
Could you maybe try to set its WorldObjectSprite to your tile? I know vanilla doesnt do it but maybe this way you can overwrite it
Additionally maybe call it something else
MapObjects.OnNewWithSprite <-- When a chunk is loaded first time from map and contains that sprite
Events.OnObjectAdded <-- When you place a moveable object, drop / transfer radio, etc (add prints to see if it triggers for generators)
I think you need to check transferItems
I think that is on clientside part of code
the transferitems
function ISInventoryTransferAction:transferItem(...)
local isWindTurbineGen = self.item:getFullType() == 'WindTurbine.Generator'
local isDropping = not self.destContainer or self.destContainer:getType() == 'floor'
local sqOccupied = self.character:getCurrentSquare():getGenerator()
if isWindTurbineGen and isDropping and sqOccupied then
return
end
local ret = {oldTransferItem(self, ...)}
if isWindTurbineGen and isDropping then
local gen = self.character:getCurrentSquare():getGenerator()
if gen then
updateSpriteAndModData(gen, item) --Not sure what does...
end
end
return unpack(ret)
end```
updateSpriteAndModData --sets the sprite for the steam generator and adds ModData
Does it use the code from the steamgen mod?
No. We referenced it. Took some functions we couldnt find in vanilla that we think are needed to make it work
Well yes then. It uses some code from steamgen mod for now
We are not quite sure how to derive from the vanilla game and make a distinct generator item
that is mainly what we want to do
should we then just copy all the vanilla code of that generator? Rather than deriving like steamgen mod does?
And rename things?
Is it an a different file?
What do you recommend us to do. If as a start on our mod. We just want to make a "clone" of the vanilla generator. That is crafted like a seperate item. Treated like a seperate item. And when dropped. Uses our tile?
without it replacing the original generator in any way when doing so?
No i mean for calling that function maybe you need to require it in the recipecode
it is once we have this clone we plan to modify it to our liking
recipes and all works
the item ingame works
but we just want it to be able to be dropped functioning like the vanilla generator. Without Beeeeing the vanilla generator but a seperate one using our tiles
so we can start modifying it to do what we want it to do in our mod after
Through the local x = require „Name of the file“ and then
x.updateSpriteAndModData
You figured this out yet?
Im curious to find out how you do it i havent read the whole thread
Can you shour main function
Show your*
Nah no I havent figured it out
I think referencing the steamgen mod was a bad idea from the start I guess... We have mostly figured out all the places the vanilla code contains generator based code
If im to do this im going to spawn a generator change its sprite but keep its property
Where are u at with this? Loke functions and asset
We just dont know how to use it to make a generator in the game that is treated like a seperate object
Which means adding it without it affecting vanilla generator in any way
Allowing us to eventually change it
Ahh ok well your approach is to determine where .... and then piece them together .. when im telling you to to just copy the whole thing
copying the vanilla generator code is not that simple
While some specific luas are specifically for the generator. Other parts of it is mixed in with bigger parts of the code
And the SteamGen mod just derived part of the vanilla code they need to change to add theirs. But they also made a new lua file that is not a modification of any vanilla lua
Well I want to have some fun for the remainder of this saturday. So gonna go on a hiatus for now
If your telling me my suggestion cant be done cuz you have tried it then i would like to know why it wont work
I think I gotta talk this out with my more knowledgeable coding buddy when he is back on but he seems distant at times too.
Ow ok . If you beed reference with im trying to tell you just check 3 of my mods for how i did it . Abd hope it helps u
Goodluck
Any of them generator related?
Just abt changing tile sprites
Abt generator idk screw that i can always copy a perfectly working generator no sweay. Why build one when theres already one out there and you can just modify the properties anyways
Safecreacker beartrap shows a sprite chnge .from close and open state
We planned to originally just modify the steamgen mod. First for learning purposes. But we would need permission from the modder first...
And we feel like that is wrong regardless. We want to/wish to make it from scratch foremost...
^updateSpriteAndModData, make a function that sets the sprite and add any relevant data you need
SteamGenerator.lua
Is that what we are missing?
maybe? issue and solution match each other
If you want to improve it, you could look into item script and WorldStaticModel.
Ah, AddWorldInventoryItem makes an IsoGenerator and adds it, makes sense now. I was thinking how this command was compatible and not throw errors.
When you put an item (not moveable object) to a square they are added with AddWorldInventoryItem command. If the fullType contains ".Generator" then instead of normal function it makes a new IsoGenerator, this obj always has the default sprite.
So how did the steamgen mod fix this?
"Tests"
updateSpriteAndModData function in SteamGenerator.lua
aha...
So basically... We where on to something...
I think I understand now
I think they assigned that stuff in a shared file called "GeneratorLEDs"
because their sprite could change texture
So we need to use this too then?
To make a different generator that uses our sprites?
what you need is:
hook to the transfer function, check if your item is moved to the floor, set sprite on the world object
triggerEvent('OnObjectAdded', object) --this is useful for SP and global object system, any other logic you have on that event
transmitUpdatedSprite --for MP
Is the modder for the steamgen mod here by any chance on this server?
@hazy citrus
We mainly just want to ask them if it is okay if we reference their mod to make things easier. We will make sure it wont conflict with his mod if players decide to use both. And would of course add him to contributors due to that... The structure of his mod seems to do many of the things we want. And we do know how to edit that mod to work differently and do what we want. But we will of course ask first
@hazy citrus you are the creator of the steamgen mod. right?
Yes
Wondered if that is okay? What I asked above?