Jump to content

RoboMat's Modding Tutorials (Updated 12/11/2013)


RoboMat

Recommended Posts

Yes looks like a rounding error from Coordinate Viewer. I will remove the rounding function. Originally the purpose of the Coordinate Viewer was to find and report bugs in the PZ-Map and small rounding errors weren't a problem.

Thank you for reporting :)

Link to comment
Share on other sites

Just wanted to say thank you for all this information. I've been watching videos and reading up trying to learn LUA to make something myself. Doesn't seem that bad once you get the idea. Also just browsing the JavaDoc gives you plenty of ideas of what's capable. Keep this thing updated, nice central place to go for essential modding information. 

 

Edit: After thinking a bit, why do you think the point values for RGB are from 0 to 1? And not 0-255 like any regular color selector. I think a visual palette selector for color would be a great addition. I wonder if this can be changed or was done for a reason.

Link to comment
Share on other sites

  • 4 weeks later...

Just wanted to say thank you for all this information. I've been watching videos and reading up trying to learn LUA to make something myself. Doesn't seem that bad once you get the idea. Also just browsing the JavaDoc gives you plenty of ideas of what's capable. Keep this thing updated, nice central place to go for essential modding information. 

 

Edit: After thinking a bit, why do you think the point values for RGB are from 0 to 1? And not 0-255 like any regular color selector. I think a visual palette selector for color would be a great addition. I wonder if this can be changed or was done for a reason.

Hey everyone, I noticed that several of you were a bit confused towards the RGB 0 to 1 aspect. Let me explain, Think of 0 as 0 percent. Now think of 1 as 100 percent. At what percent do you want the red to show? .70 would be 70 percent red to show or 178.5 (.70*255). To explain, there is a ratio (relationship) between our numbers. This ratio is 1=255 (a nice easy ratio). So lets say you want a level of 200. All you have to do since we know the ratio is 1 = 255 is divide 200 by 255 and we get 0.7843, which we round to 0.78. In addition, this number is any example of a float number =-). Hope this helps.

 

I also wanted to mention awesome job on the tutorial RoboMat, saw you in the announcement this week and your name just keeps on popping up everywhere. I am actual taking a look at some of your code to study because I am planing on making a mod for myself. Any how thanks for the help mate.

Link to comment
Share on other sites

Thanks for the nice words, that's why I'm doing this :)

We had some discussion why some numbers use integers instead of floats and part of the reason could be that type conversion and "the other thingy of which I can't remember the proper name atm" could hit the performance, so keeping the variables as floats could ease that pain.

saw you in the announcement this week and your name just keeps on popping up everywhere.

Announcement?! o.O

P.S.: There'll probably be an update by the end of the week.

Link to comment
Share on other sites

  • 3 weeks later...

Thank you RoboMat! As I have plenty of time at the moment, I decided to take a little dive into PZ modding. Because it's been a fricking long time since I had something to do with programming, your guide has opened the first door for me. Thank you!

 

Right now I'm surfing the web for tutorials and manuals about java to understand the source code. It's pretty hard for me and my brain hurts a little but I will not give up until I'll have unleashed my average-fun-ish mods above humanity!! :geek: *refueling with coffee*

 

To be more specific, I'm reading all the character/health related parts right now to find out how healing works and to know which things I have to alter with my lua code, yay!

Link to comment
Share on other sites

  • 3 weeks later...

You mean this one?

 

function zomboid.walkToObject(_player, _object, _cancelTA)    local player = _player;    local object = _object;    local tile = _object:getSquare();    local cancel = _cancelTA;    -- Abort all current Timed Actions.    if cancel then        ISTimedActionQueue.clear(player);    end    -- Pathfinding and starting the actual walking.    if not AdjacentFreeTileFinder.isTileOrAdjacent(player:getCurrentSquare(), tile) then        local adjacent = AdjacentFreeTileFinder.FindWindowOrDoor(tile, object);        if adjacent then            ISTimedActionQueue.add(ISWalkToTimedAction:new(player, adjacent));            return true;        end        return false;    end    return true;end

 

This should actually also work as a "moveToTile" function.

Link to comment
Share on other sites

Thanks, but I'm still feeling confused as to how the world is organized and how I can interact with it.  I'm requesting an addition to this tutorial - an explanation of how the world is organized in terms of cells and tiles and grid squares and their relationships to each other.  What are the main world objects and methods?  I'm just not sure I understand how the world is organized and what methods I should use.  Is this documented somewhere?

Link to comment
Share on other sites

Thanks, but I'm still feeling confused as to how the world is organized and how I can interact with it.  I'm requesting an addition to this tutorial - an explanation of how the world is organized in terms of cells and tiles and grid squares and their relationships to each other.  What are the main world objects and methods?  I'm just not sure I understand how the world is organized and what methods I should use.  Is this documented somewhere?

 

The player character/characters are part of IsoPlayer, you can find the class in the JavaDocs

All methods directly relating to the player can be found there or in its superclasses.

In order to call an IsoPlayer method, it has to be executed from an IsoPlayer..... for example:

`getPlayer() will return Player 1Player = getPlayer();`we want to move the player to an adjacent grid squarePlayer:setX(Player:getX() + 1);

However if you wanted to interact with a container you have find the specific container object & call methods from its class & superclasses....

Unfortunately, finding the required classes & methods makes up 75% of modding PZ & asking RoboMat to document the "main objects & methods" is asking a little much.

 

My only advise would be to look through the existing lua files to try & find something relating to what you are trying to do then, once you've found the object class you want to interact with, try & familiarise yourself with the methods associated with that class.

If your having trouble finding anything specific, feel free to post in the modding help section & myself or the other modders here will try to help you out as best we can :)

 

EDIT:

LuaManager.class is a good place to start because its methods can be called outside of an object, but you will need a java decompiler to find the majority of the methods.... LuaManager in the JavaDocs is REALLY limited for some reason

Edited by ExcentriCreation
Link to comment
Share on other sites

Thank you very much for your detailed response, ExcentriCreation.  I didn't mean to sound demanding or ask for too much, just a section that covers it at some level - I think it would really help newbies like myself. 

 

I've already begun work on a mod myself using the information I've been digging up from the java docs and, of course, looking at other people's code.  Thanks again.

Link to comment
Share on other sites

  • 4 weeks later...

Ok I am having trouble for some reason and I am not sure why. I have read and followed the initial tutorial post. I have even gone and rea dup in other posts about mods and loading / running them. But I am having some toruble still. I believe I have my folder structure right:

 

t6YRPpZ.jpg

 

And when I load the game (Iwillbackupmysave branch) I can see and load the mod in the mod menu. However when I am in game it does not appear to be recognizing, or running the code inside the mode

local function addItems(_keyPressed)    local key = _keyPressed;    print(key);    --we test for the right key    if key == 25    then        local player = getSpecificPlayer(0); --Java: get player one        local inv = player:getInventory(); --Java access player inventory        --java: Add the actual items to inventory        inv:AddItem("Base.Axe");        inv:AddItem("Base.RippedSheets");        inv:AddItem("camping.TentPeg");    endend--will be fired whenever we press a keyEvents.OnKeyPressed.Add(addItems);

What is the best way to trouble shoot mods not workign once in game? I have tried loading in debug mode and opening the debug console, but even in the list of lua files I cannot find my AddItems.Lua file.

 

When I press a key it doesn't seem to do anything and doesn't print anythign anywhere that I can tell.

 

Sorry if this has been asked a million times before, just trying to get the hang of gettign abasic mod in game and working, after that I swear the noob quesitons will drop to a minimum!

Link to comment
Share on other sites

Try putting your 'Mods' folder in 'media/lua/client'. TIS changed their folder structure for multiplayer.

 

This might not be totally relevant to the original post, (due to not talking about the actual mod you wrote a tutorial about, but it's an general question) but my mod will run perfectly fine in the main menu; but not in-game?

I tried to place it in /media/lua/client - without success. Still isn't run when I'm in the actual game.

 

(I did read this; http://theindiestone.com/forums/index.php/topic/6615-lua-mod-changes-required-in-25/)

Link to comment
Share on other sites

  • 2 weeks later...

I'm eagerly awaiting your next post in this tutorial RoboMat, I'm hoping you will show a successful example of overloading a function.


Also, sec_goat- The only difference between your folder structure there, and mine- is your "Mods/" folder is capitalised.  Mine is spelled with a lower case 'm'.  so "C:\Users\User\Zomboid\mods\SanctuaryMod\media\lua\mods\SanctuaryMod" is where my custom stuff lies within.  

 

Your code works fine.

Link to comment
Share on other sites

I'm eagerly awaiting your next post in this tutorial RoboMat, I'm hoping you will show a successful example of overloading a function.

When I'm going to update it, the post probably won't be about overloading functions since this tutorial isn't about Lua ;D

Lua by default doesn't allow overloading of functions. You could use table constructors, simple if-else statements, initialise variables with default values if the parameter is omitted (I mostly do this as it's pretty easy and quick to write) ... just to name a few possibilities.

The beauty about Lua is that it allows you to do stuff on your own instead of forcing a certain paradigma on you.

EDIT:

Just found this if you need further reading material on how overloading can be achieved.

Link to comment
Share on other sites

I've written my own tutorial which leads on from your excellent "custom profession/custom trait" tutorial.  It shows how I personally "Hook" into the lua files to create my custom code.

 

Alot of people will be familiar now with the basics, I think, and are eagerly awaiting your next part! 

 

If you wish to check out my tutorial, you can find it here, on my makeshift website-

 

http://www.sanctuary-pz.com/#!tutorialvegetarian/c1su

 

It (hopefully) shows how you can hook into the custom right click function and associated methods, in this example "ISEatFoodAction" or in other words, how to execute code whenever a player finishes eating something.  

 

Note: it's designed for intermediate scripters/programmers, but it is very comprehensive, so give it a go even if you are a beginner, remember, ultimately, all I do in the whole thing is use the Ctrl+F or "Search" function to find key terms.  But it gives a pretty good idea of navigating through the whole lua/java stuff.

Link to comment
Share on other sites

  • 2 weeks later...

That is the worst place to stop a tutorial ;_;

When is this gonna be updated?

I'm trying to get into modding, but so far none of my attempts has yielded results :| and this guide is really good. But I can't get it to work on build 25a, which I'm currently using. Can someone explain to me if modding for build 25 changed or broke or if I'm just doing modding wrong?

Thanks.

-Sejemus

Link to comment
Share on other sites

  • 4 months later...
  • 5 months later...

I cannot get any .lua based mods to work.

 

Specifically I tried the dry towels mod, and couple attempts at modding myself.

 

Here is the simple intro mod (that for me does nothing):

 

function sayHello()
playerlog = getSpecificPlayer(0);
playerlog.Say("Hello");
end
 
Events.EveryTenMinutes.Add(sayHello);
 
 
I placed this inside of my mods folder %%Zomboid\mods\helloworld\media\lua
 
I setup the mod.info and poster.png in the helloworld root folder.
 
The mod info file:
 
name=Hello World (1.0.0)
poster=poster.png
description=Test where player 0 says Hello World every 10 in game minutes
id=helloworld
url=www.google.com
 
 
When booting, the mod appears in the mod list, with poster working.  I double click to activate (checkmark appears).
 
I start a Beginner survival game.  I would expect to have my character say 'Hello' every 10 minute in game interval.
 
Any advice?

 

 

Link to comment
Share on other sites

  • 4 months later...

If you've been following this tutorial for build 32 like i have, you will have noticed that it doesn't work in the current build.

 

There are 4 problems I've found:

The folder structure has changed.

The clothing choices don't seem to work. Not required either.

The spawnpoints don't seem to work but don't worry, they are not required.

The ProfessionFactroy.addProfession now requires a 4 element array instead of a 3 element array.

 

Fixes for problems 1, 2, 3 & 4:

✓ Make sure your folder structure is like this... \MyMod\media\lua\shared\NPCs\MyCustomProfession.lua

 Delete all clothing functions/events from the script.

 Look at the profession in RoboMat's lockpicking mod. It contains a working example of defining spawn points for a custom profession in build 32.

 Trait Factory command should be like this;

local myprofession = ProfessionFactory.addProfession("myprofession", "My Custom Profession", "profession_myprofession", -4);

Type: Used to identify the profession internally in the game's code. (STR)

• Name: Human readable name that apprears in the game's menus etc. (STR)

• Icon Name: Name of the custom icon to be displayed in the game. (STR)

• Starting Points: Define how many points the player will start with. Accepts negative values. (INT)

 

Without the 4th value, your game will throw an error in the console.

 

Some other key points I've found out:

 

The Profession Icon;

✓ PNG

✓ 8bit per channel
✓ Transparent background
✓ 64x59 pixel resolution
✓ Good photoshop filters to use are Posterize and Black & White
✓ Put it in this location \MyMod\media\textures\profession_myprofession.png
 
• The Trait Icon;
✓ PNG
✓ 8bit per channel
✓ Transparent background
✓ 18x18 pixel resolution
✓ Put it in this location \MyMod\media\ui\Traits\trait_mytrait.png
 
• Setting Extra Parameters;
✓ myprofession:addFreeTrait("Desensitized");
✓ myprofession:addXPBoost(Perks.Cooking, 1)
✓ myprofession:getFreeRecipes():add("Make Cake Batter");
✓ myprofession:setDescription("Can bake cakes\n+1 Cooking\nDesensitized")

 

Spawn points and clothing can be safely removed from the final script, as you will just spawn at a random, predefined location and you can choose the gear you wear in the menus. It would be best to define your own, I just haven't got around to that yet, so I can't teach it.
 
So far, my script looks like this:

--[[ drugdealerProfession.lua Author:Date Created: Modified By:Date Modified: ]]-- require'NPCs/MainCreationMethods'; -- TRAITSlocal function initTraits()TraitFactory.addTrait("paranoia", "Paranoia", 0, "Constantly under a state of Panic without drugs.", true)end -- PROFESSIONlocal function initProfession()local drugdealer = ProfessionFactory.addProfession("drugdealer", "Drug Dealer", "profession_drugdealer", -4);drugdealer:addFreeTrait("paranoia");drugdealer:addXPBoost(Perks.Cooking, 1)drugdealer:addXPBoost(Perks.Farming, 1)drugdealer:addXPBoost(Perks.Lightfoot, 1)drugdealer:addXPBoost(Perks.Sneak, 1)drugdealer:setDescription("Can cultivate Cannabis and bake Space Cakes\n+1 Cooking\n+1 Farming\n+1 Lightfooted\n+1 Sneak\nParanoia")end -- DO SOMETHING IN-GAMElocal function paranoidDebuff()local p = getPlayer();if p:HasTrait("paranoia") thenp:Say("I need to find my next fix!");end end -- EVENTSEvents.OnGameBoot.Add(initTraits);Events.OnGameBoot.Add(initProfession);Events.OnGameStart.Add(paranoidDebuff);


 

I have plans to expand the script. Currently I'm having problems with moodles and interpreting java docs into real syntax. I need to grab a hold of the panic moodle on the player and crank it up if he has the paranoid trait. Any help will be much appreciated.

 
Here's some free icons i made that anyone can use for any purpose.
post-17863-0-38564300-1437247460.png
post-17863-0-18797200-1437247471.png
Link to comment
Share on other sites

  • 3 weeks later...

so helpfull. just a couple of question. is it possible to make one profession say different things to other ones. and is it possible to make an item one weight for one profession and another for everyone else. only i am making a mod inspired by marvel and i wanted mjolnir to only be usable by the profession odinson. or a trait if it is easier. like honourable. also. my items are showing up but my professions are not. and all of my traits are profession traits. how do i get them to show up on the list.

Link to comment
Share on other sites

...my items are showing up but my professions are not...

 

Post your current script on here and we'll take a look, use the spoiler and code tags.

Also post the file path to your script, it will show us the folder structure you are using.

Hold shift+right click on your script and click on copy as path, paste it here.

 

 

 

...all of my traits are profession traits. how do i get them to show up on the list...

 

Change the end value to false.

TraitFactory.addTrait("paranoia", "Paranoia", 0, "Constantly under a state of Panic without drugs.", true)
Link to comment
Share on other sites

  • 4 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...