Stable Build: 41.78.16 | IWBUMS Beta: 41.78.16 | Version history | Wiki
Follow us

News

Modding
January 12, 2012

Expanded Modding Support Details

Hello modding fans!

In this blogpost we’ll detail an addition to the modding support in the next update. In one word: LUA.

Project Zomboid now fully supports LUA scripts within the modding interface. In case you do not know what LUA is, it’s basically a programming language where the code is simply put in text files instead of being compiled into an exe, meaning it is open for modders to play about with, modify and learn from. Project Zomboid currently has a really simple scripting system for creating new inventory items and conversations or cutscenes, but the power of LUA goes way way beyond that.

Barring a few accidental omissions no doubt, the next version of Project Zomboid will allow modders near unlimited access to the entire inner workings of the game, opening up 10000x the mod possibilities. Modders will be able to code their own game logic to implement new game mechanics, item effects, or practically anything else they could dream up. There will of course be exceptions, particularly for the first version, but with the release of the LUA scripting we should see much more in-depth and powerful mods emerge in the weeks and months afterwards, with each update providing more and more power.

Here are a few (slightly silly) examples that should hopefully show a few things that are now open to modders:

1) Live map editing

This code adds a lua function as an event for ‘OnGameStart’ which cycles through the entire map, tile by tile, gets a list of every object on that tile and loops through those, and any with collidable properties it deletes. Modders can therefore modify the map in any way they like before or during the game.

function DeleteAllWalls()
	local world = GetWorld();
	local cell = world:GetCell();	

	if cell == nil then
	 print ("Failed to get cell");
	else
	 for x = 0, cell:GetWidth() do
	   for y = 0, cell:GetHeight() do
 	     for z = 0, cell:GetMaxFloors() do
		local square = cell:GetGridSquare(x, y, z);
		if square ~= nil then

		  local objects = square:GetTileObjects();

		  if(objects ~= nil) then
		    for k,v in ipairs(objects) do
		      local properties = v:GetProperties();
		      if(properties ~= nil) then
			if properties:Is(PropertyType.solid) or
			    properties:Is(PropertyType.solidtrans) or
			    properties:Is(PropertyType.collideN) or
			    properties:Is(PropertyType.collideW) then
				square:DeleteTileObject(v);

			end
		     end
		 end
	      end
	   end
	 end
       end
     end
   end
end

Events.OnGameStart.Add(DeleteAllWalls);

 

Result:

 

2) Direct graphics drawing: ESCAPE THE WILL

Here we add The Will Porter as a ghostly apparition that follows your mouse! This shows that, as well as draw into the isometric map with tiles, modders can now draw textures directly to the screen, allowing the potential for UI changes or other graphical mods.

x = 0;
y = 0;
function DrawTheWill()
	local texture = GetTexture("media/ui/will.png");
	local core = GetCore();

	if texture ~= nil then
		texture:render(x,y);
	end

	local centreX = x + (texture:GetWidth() / 2);
	local centreY = y + (texture:GetHeight() / 2);

	x = x + ( (GetMouseX() - centreX) / 5.0);
	y = y + ( (GetMouseY() - centreY) / 5.0);

end

Events.OnPostUIDraw.Add(DrawTheWill);

Result:

3) Item behaviours: EXPLODING APPLE OF DOOM

Here we add exploding suicide apples to the game! We add an event to the apple that when eaten will explode, killing those within a radius and setting fire to random tiles.

function DoExplodingApple(character, item)

   if item:GetType() == "Apple" then

      local radius = 30;
      local numFires = 300;

      local cell = GetWorld():GetCell();

      local objects = cell:GetObjects();
	for k,v in ipairs(objects) do
	   if character:DistTo(v) < radius and v:IsCharacter() then
		v:Kill(character);
	   end
	end

	GetSoundManager():PlayWorldSound("explode", character:GetSquare(), 0, 20, 1.0, false);

	for i = 0, numFires do
	   local sq = cell:GetGridSquare(ZombRand(character:GetX()-radius, character:GetX()+radius),
	  		                 ZombRand(character:GetY()-radius, character:GetY()+radius),
					 character:GetZ() );

	    if sq ~= nil then
		sq:StartFire();
	    end
	end
    end

end

Events.OnUseItem.Add(DoExplodingApple);

Result:

We couldn’t possibly have expected how many mods would become available for Project Zomboid so quickly. We were genuinely blown away, and cannot wait to see what the modders can do when they get their hands on this!

PREVIOUS

NEXT

#1- The Good Life

Modding | 20 June 2012
Stable Build: 41.78.16 | IWBUMS Beta: 41.78.16 | Version history | Wiki
Follow us