#WindTurbine Modding

1 messages · Page 1 of 1 (latest)

dense pumice
#

Ok let me rephrase our current issue

  1. 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.
  2. when we manually drop it we get the error screen I posted above
    and it becomes a normal generator
urban hatch
#

is it an IsoGenerator type?

#

the vanilla one checks if the generator is an IsoGenerator

dense pumice
#

@dark shale I setup a thread here for any help to make our mod function

frank canyon
#
  1.     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

dense pumice
#

this is the part of the code that is supposed to drop it

frank canyon
#

addOrDrop might work only with CanBeDoneFromFloor:true

#

^the pic of scripts you posted

dense pumice
#

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)```
dense pumice
#

Will see if that works

mental kiln
#

It could help if you sent the error log

#

The one you get when you click on 'Errors' on top of this screen

frank canyon
# dense pumice Oh?

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

dense pumice
#

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

urban hatch
#

you call Recipe.OnCreate.WindTurbine but its called Recipe.OnCreate.WindTurbineGenerator in the lua file @dense pumice

dense pumice
#

facepalm

#

You are right!

dense pumice
#

Ok now it crafts the normal generator. And it stil doesnt forcedrop

#

no idea what is going on atm xxD

frank canyon
#

when do you expect it to drop?

dense pumice
#

once the crafting is finished

#

that is what steamgen mod does

frank canyon
#

in debug you can fit unlimited number of generators in your inventory, they would drop if they don't fit

dense pumice
#

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

frank canyon
#

HandItems are in your inventory too, just saying

dense pumice
#

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

frank canyon
#

let me check, but what I meant is: Items equipped in hand are considered to be in player's inventory

dense pumice
#

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

frank canyon
#

put it in a crate or something

#

drag it

dense pumice
#

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

urban hatch
#

The vanilla one also weighs 40 so that could be an addition to why you cant put it in your inventory

dense pumice
#

you can have it in player inventory only if you use the item menu to put it there

frank canyon
#

I used to put generators in sits with low capacity, before they patched it drunk

urban hatch
#

Yea it forces it in the ISTakeGenerator action

dense pumice
#

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```
dense pumice
#

ah

#

wait

#

it shouldnt fit

#

inventory is 12

urban hatch
#

In godmode it will always fit

frank canyon
#

player inventory is 50

dense pumice
#

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

urban hatch
#

How do you set the tile?

frank canyon
#

I pickup generator, put it into a composter and transfer into player inventory. Generator is not equipped.

urban hatch
#

I think thats a hack

frank canyon
#

As I said, drag the item not right click.

dense pumice
#

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

urban hatch
#

Maybe do setSprite()?

dense pumice
#

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

urban hatch
#

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

frank canyon
#

I think you need to check transferItems

dense pumice
#

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```
frank canyon
#

updateSpriteAndModData --sets the sprite for the steam generator and adds ModData

urban hatch
#

Does it use the code from the steamgen mod?

dense pumice
#

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?

urban hatch
#

Is it an a different file?

dense pumice
#

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?

urban hatch
#

No i mean for calling that function maybe you need to require it in the recipecode

dense pumice
#

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

urban hatch
#

Through the local x = require „Name of the file“ and then

x.updateSpriteAndModData

thin sphinx
#

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*

dense pumice
#

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

thin sphinx
#

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

dense pumice
#

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

thin sphinx
#

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

dense pumice
#

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

thin sphinx
#

What happens if you change the sprite?

#

And its name

dense pumice
#

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

thin sphinx
#

If your telling me my suggestion cant be done cuz you have tried it then i would like to know why it wont work

dense pumice
#

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.

thin sphinx
#

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

dense pumice
thin sphinx
#

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

dense pumice
#

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...

frank canyon
#

^updateSpriteAndModData, make a function that sets the sprite and add any relevant data you need

#

SteamGenerator.lua

frank canyon
#

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.

dense pumice
#

What are these?

dense pumice
frank canyon
frank canyon
dense pumice
#

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

dense pumice
#

To make a different generator that uses our sprites?

frank canyon
#

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

dense pumice
#

Is the modder for the steamgen mod here by any chance on this server?

frank canyon
#

@hazy citrus

dense pumice
#

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

dense pumice
#

@hazy citrus you are the creator of the steamgen mod. right?

hazy citrus
#

Yes

dense pumice
hazy citrus
#

What do you want to do, precisely

#

"referencing" my mod could mean many things