Jump to content
RAINBOW

IsoObject : Making my own IsoObjects? : OnFillWorldObjectContextMenu : Affecting the world

Recommended Posts

Okay!

 

In my endeavour to create a "Boltcutter" item, I'm comfortable with creating my own sprite, and it acting as an inventory item-

 

There's 2 things I need to know however that relate to "Affecting the world" which are:

 

1:  I have FORGOTTEN! the name of the lua file that the "OnGameBoot" event uses to cycle through literally everything on the map, I had it last night at 2am, but forgot to put it in my notes! (If anyone can help I'd appreciate that!)

 

2:  Creating my own IsoObject.  I'm happy that I can overwrite the "OnFillWorldObjectContextMenu.fetch" when a player right clicks a square, but ultimately what I am looking for is where the

 

"v:getSprite():getProperties();"

 

is originally set.  (v is just the instance of the IsoObject right clicked in the fetch.)

 

Once I know where the IsoObject:setProperties() takes place, I should be able to dig out the "Default" Chain link fence sprites.  I ran all of the methods I could find in the javadoc to try and dig out any kind of unique identifier I could-

 

Perhaps the IsoObjectType is set in the map editing suite somewhere?

 

Anyway, I'd bet this would be a useful thread to anyone actually wanting to affect the world, in particular default items. 

 

Cheers in advance!

Share this post


Link to post
Share on other sites

I should probably clarify, I tried doing "GetSprite" calls, "GetName()" and things, and I couldn't seem to grab anything "Unique" to a chain link fence.

 

for example, when debugging, a "getObjectName();" returns simply "IsoObject".  Nothing unique to the fence.  

Share this post


Link to post
Share on other sites

1:  I have FORGOTTEN! the name of the lua file that the "OnGameBoot" event uses to cycle through literally everything on the map, I had it last night at 2am, but forgot to put it in my notes! (If anyone can help I'd appreciate that!)

Download WinGrep and use it to search for stuff in the game Lua sources.

 

For creating world objects, you might want to see how the Erosion mod for example does its thing. Properties of tiles are set somewhere in TileZed AFAIK.

 

In general, when you don't know how something, grep through the game sources for related words (esp. if you know the game has similar functionality), or look at how other mods do things.

Share this post


Link to post
Share on other sites

Well, let's start from the beginning.

Here is some (runnable) code. Tell me what v is:
 

local function contextMenu(_player, _context, _worldObjects)    print ("contextMenu.lua\\contextMenu\n")        _context:addOption("Hi!", nil, nil, nil)        for i,v in ipairs(_worldObjects) do        square = v:getSquare();        square:StartFire()    endendEvents.OnFillWorldObjectContextMenu.Add(contextMenu)

Share this post


Link to post
Share on other sites

Enigma:

 

"v is the "IsoObject" that I right click on"

 

Harraka: 

 

Ah! So you -can- set the properties of a tile in Tilezed somewhere... Okay, first on the agenda is download the EROSION mod.  Take a look under the hood there.

 

Thanks guys. Back in a tick

Share this post


Link to post
Share on other sites

Enigma.  Wow.  You completely nailed what I was after- Here's a screenie of what I needed returned, and now thanks to you I have!

 

Yay_zps8289e9f9.png

 

fencing_01_50 is indicative of the "Military Grade" fence that is one of the default fence objects that people can use in their maps.

 

I thought about being selfish, and writing a wee bit of code that would only work when I make my own map, but there's no reason(now I have this) that I can't make it universal, so it grabs the sprite from a right click, and package it in a "Bolt cutter" mod.

 

All I added was a "v:getSprite():getName();" and right clicked the military fence in my test map!

 

I've also learned something here, using a for loop in lua to cycle through a table!  For anyone wondering what I was doing wrong, here's the important bit of code that Enigma linked:

 

    for i,v in ipairs(_worldObjects) do        square = v:getSquare();        square:StartFire()    end

 

I had neglected that worldobjects was a table value.  The for loop acts here like a "ticker tape dispenser" pulling out the required part, so that the letter v (the IsoObject in this case) becomes relevant.  

Share this post


Link to post
Share on other sites

with this loop, is it also possible to change properties of already existing world objects?

 

like the IsoObject type, or specific settings like isHoppable or isDoor? Because for my building mod i would require to create windows as "IsoWindow" to make them functional. however, build 25 creates all new worldobject by default as "IsoThumpable". As this step is done with java functions, i can not tailor them to my needs.

 

and last question:

 

I had neglected that worldobjects was a table value.

are there any more detailed informations about that?

Share this post


Link to post
Share on other sites

Enigma, what do all these "Nils" represent?

 

_context:addOption("Hi!", nil, nil, nil)

 

I thought I'd be able to plug in "ISTimedActionQueue.add(TAFenceChop:new(_player, v, 50)" here, no joy though.:

 

 
_context:addOption("Hi!", ISTimedActionQueue.add(TAFenceChop:new(_player, v, 50), nil, nil)

 

Whats the code for removing a context option?

Share this post


Link to post
Share on other sites

 

Enigma, what do all these "Nils" represent?

_context:addOption("Hi!", nil, nil, nil)

I thought I'd be able to plug in "ISTimedActionQueue.add(TAFenceChop:new(_player, v, 50)" here, no joy though.:

 

 
_context:addOption("Hi!", ISTimedActionQueue.add(TAFenceChop:new(_player, v, 50), nil, nil)

Whats the code for removing a context option?

 

 

From the mod-help rules:

 

Show some effort

While we are glad to help any way we can, don't expect us to write your mods for you.

 

No offense to you, but modding is about finding stuff out on your own too. It's how RJ learned modding this game, it's how I learned modding the game and it is how everyone else learns. It's totally fine to ask if you have issues, and as you already have seen we are happy to help where we can, but don't expect us to give you perfectly working code for your mod ;)

Share this post


Link to post
Share on other sites

I only meant, what is the method for removing a context option?  I can't find a way to remove the context menu after I create it.

 

 

Contain it in a conditional statement (such as an if) that determines whether it's a valid option or not.

if somethingsomething then

 

addOption()

 

end

Share this post


Link to post
Share on other sites

Haha, excellent.  Sometimes a repeat post is needed with me.  Thanks for being patient.  

 

"Code" was definately a bad choice of words on my part, I was after a way to 'end' a context menu.  There is literally no documentation on this stuff, most of the stuff is commented in the code, and I am not averse to trawling through it- Incidentally,  I dug open the Erosion mod, and it utterly, utterly terrified me.  it was too big for me to make sense of what was going on, except on a micro level.- anyway, I'm never looking for complete solutions, but rather a "Way" of doing things.

 

I gotta mention as well, I'm COMPLETELY new to lua! I know my java, but I've no idea what I'm doing with lua.  It's proving not too bad, I mainly hit stupid syntax problems.  

 

I'm certain too this thread will prove useful to the community too, certainly later on, when the modding community REALLY explodes! After all its got a for loop cycling through a table value- AND a Timed Action! someone out there except me -must- be having similar probs.

 

I got my mod working now where when a player "Right clicks" on a tile with the default "Military Grade Fence" sprite, it will add a new property to it, (after checking it hasn't been done before) and bring up the Context option "Cut Fence".  From there it just fires debug statements, but it's not hard to alter the original sprite properties to a new an improved sprite(Image) of a cut hole in the fence.  (I hope!)

 

I'll need to add in the IsoProperty "IsClimbable" too, but hopefully that won't cause too many issues as that is pre-existing code.

Share this post


Link to post
Share on other sites

AH! Badtrix, I scrolled up and noticed your post- I neglected it the first few times I sought help here-

 


 IsoObject type, or specific settings like isHoppable or isDoor? Because for my building mod i would require to create windows as "IsoWindow" to make them functional. however, build 25 creates all new worldobject by default as "IsoThumpable". As this step is done with java functions, i can not tailor them to my needs.

 

IsDoor and IsWindow are DEFINATELY in there mate.  As for IsoThumpable- something either "IS" or "ISN'T" thumpable.  so you set your window objects(thumpable value) to TRUE.  Pre-existing code is the best thing I'm finding about this lua malarky! it's when you gotta write your own stuff it becomes hard, anyway, check out the lua files in the "require" field at the top- because you're a bit new, you might not realise that -all- the functions within the "require 'xxxfilename.lua'; at the top of (Some) of your code will ALSO be fully available in whatever one you are currently editing.  

 

In other words, keep open more than one window in your IDE (Notepad++, Eclipse, IntelliJIdea etc) when you have those require statements.  They are also known as "#includes" in some other languages.

Hope I helped a bit.  PM me anytime anyway, I'm pretty sure what I explained will help you out.


Just wanted to make sure of this too for you:


 set your window objects(thumpable value) to TRUE.

 

Where I say "True" make sure it's not the value "1".  This is NOT the same thing as true (Like in some other languages).  Also, did you know values don't default at "Zero", that lua has a unique identifier called "Nil".  It's pretty handy, but you'll find that out further on down the road.

Share this post


Link to post
Share on other sites

hey rainbow.

 

thanks. yeah, i made about the same conclusions when trying to figure out how lua works. my notepad++ has around 10 open files at any time, and now i'm also using JD decompiler to view those .class files. To create a new (functional) window, i need to call this function:

public IsoWindow(IsoCell cell, IsoGridSquare gridSquare, IsoSprite gid, boolean north)

However, i just need to find out how to create the needed IsoSprite parameter :P

 

But the problem of altering data of worldobjects is still actual in a similar way, as i run into a similar issue: http://theindiestone.com/forums/index.php/topic/7949-itemcontainerisoobject/

 

Problem is i really do not know how to solve that without altering .class files, which i guess is not possible to implement in mods :P

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...