Zombie Grinder is the debut game of TwinDrills, an indie game development duo made up of Tim 'Infini' Leonard and Jordan 'Jordizzle' Chewning. It's a multi-platform (windows, mac, Linux!) (also Free!) cooperative multiplayer arcade game, reminiscent in style and gameplay of retro games like 'Zombies Ate My Neighbors' and 'Super Smash TV!', but with the added benefit of some newer game mechanics - achievements, ranking, player-customization, rpg style stats and so forth. The game sports a variety of different game modes, from co-operative 'campaign' style levels, to wave maps and even the classic 'pvp' style game modes - deathmatch, capture the 'bag' and so forth. All of these mods are bristling with a variety of weapons and items, all lovingly displayed in Jordan's classic quirky pixel-art style.

Forum Thread
  Posts  
Spawning Items at Wave Number x (Games : Zombie Grinder : Forum : Modding / Map Design : Spawning Items at Wave Number x) Locked
Thread Options
Jul 26 2013 Anchor

Ok, I've been struggling with this for a while now. I'm trying to make it so that my map spawns a key on the xth number wave. I've tried looking at Wave.mc for help, but I honestly don't have any clue on how to get a variable from another script or even which variable is used for the wave count.

Any help would be greatly appreciated :3

Infinitus
Infinitus Developer
Jul 27 2013 Anchor

How you implement this function depends on what you want it to do. Simplest way is to set the game mode to wave, and use a map script to spawn the keys.
The easiest way to implement this is probably to create several key objects around your map in the editor, give them names like round5key, round10key, etc. Then despawn them when the map starts, and then respawn them as you get to each round (the wave game mode invokes a handy OnWaveStart event to hook into, nice and simple :P). A map script something like this would work;

function OnMapStart()
{
	if (IsServer())
	{
		DespawnPickup(FindEntityByName("round5Key"));
		DespawnPickup(FindEntityByName("round10Key"));
		DespawnPickup(FindEntityByName("round15Key"));
	}
}

function OnWaveStart(index)
{
	if (IsServer())
	{
		if (index == 5)
		{
			RespawnPickup(FindEntityByName("round5Key"));
		}
		else if (index == 10)
		{
			RespawnPickup(FindEntityByName("round10Key"));
		}
		else if (index == 15)
		{
			RespawnPickup(FindEntityByName("round15Key"));
		}
	}
}

--

Jul 27 2013 Anchor

:D Oh my god thank you! I didn't know what functions/methods were made so I had no idea on how to go about this. Thank you man! :D

Jul 27 2013 Anchor

*bonks self on head* Gah, so that's how you're supposed to use OnWaveStart. How is it that you make this look so easy?

That said, I find that Infini's code is a little brute forced - what if we did something like this?

var entityList; //Make multiple Lists if multiple types of keys.

function OnMapStart()
{
	if (IsServer())
	{
		//Despawn all pickups
		entityList = GetDerivedEntities("TChestKeyPickup"); //"TChestKeyPickup" for Chest Keys, "TKeyPickup" for dungeon Keys, "TKeycardPickup" for Keycards (all colours) - this is all assuming that these keys are not named.
		for (var i = 0; i < CountList(entityList); i++)
		{
			var e = ListAtIndex(entityList, i);
			DespawnPickup(e);
		}
	}
}

function OnWaveStart(index)
{
	if (IsServer())
	{
		if (index%5 == 0)
		{
			//Respawns a random Key
			var newKey = ListAtIndex(entityList, Rand(0, CountList(entityList) - 1));
			RespawnPickup(newKey);
		}
	}
}

My biggest problem with our code is that it does NOT despawn the key - this is different from Bag Collection which forces all bags to despawn when a new bag spawns. That means that with our current scripts, once the Key is spawned, it STAYS spawn, dependent on the Respawn Interval that you plugged in for the object (keys).

I guess we can fix that with something like this:

//Despawn pickups when a key is picked up
event OnPlayerPickupInventoryItem(client)  //Not sure if there are more variables
{
	if (IsServer())
	{
		for (var i = 0; i < CountList(entityList); i++)
			{
				var e = ListAtIndex(entityList, i);
				DespawnPickup(e);
			}
	}
}

//Respawns key if player is killed
event OnPlayerKilled(client, weapon, zombie)
{
	var key = GetClientInventoryItem(client, "TChestKeyPickup");  //Same warning applies
	if (IsServer())	
	{
		if (key != NULL)
		{
			RemoveClientInventoryItem(client, key);
			RespawnPickup(key);
		}
	}
}

//Respawns key if player disconnects
event OnClientDisconnect(client)
{
	var key = GetClientInventoryItem(client, "TChestKeyPickup"); //Same warning applies
	if (IsServer())	
	{
		if (key != NULL)
		{
			RemoveClientInventoryItem(client, key);
			RespawnPickup(key);
		}
	}
}

Mind you, Infini's code is far more likely to work out from the box than mine - I wouldn't be surprised if I messed up something or another typing this up. But I think that the theory is there, just not whether it is right (or if I did something stupid).

--

Jul 28 2013 Anchor

Actually when taking a second look at Infini's OnWaveStart, I haven't been able to get it to work correctly with various testing (mind you that I don't know anything about Infini's previous code and what gets called every tick) I tried just putting the [function OnWaveStart()] directly into my code, but I haven't been able to get it to work.

for example, this is an excerpt of my code:

function OnMapStart()
{
  if (IsServer())
  {
    DespawnPickup(FindEntityByName("exitKey"));
  }
}

function OnWaveStart(index)
{
  if (IsServer())
  {
    if (index == 1)
    {
      RespawnPickup(FindEntityByName("exitKey"));
    }
  }
}
<br />

Edited by: Fulkinator

Infinitus
Infinitus Developer
Jul 28 2013 Anchor

FYI I didn't test my code, that was off the top of my head, but it should work.

Give me a couple of minutes and I'll go check.

--

Jul 28 2013 Anchor

Question for Fulkinator: what map mode are you starting on? If you are doing something like wave_basement or wave_tiny where you start off with Objective map mode, then the script might not even work to begin with - since the function OnWaveStart(index) is a function that is only defined in Wave.mc (that is, only if the map is in Wave mode). If it is in any other mode, the map script is probably going to be like "Where's my OnWaveStart?" and probably blow up trying to find it.

The other issue I have with your current script is that you had your check for index == 1 -- this means that even though you despawned OnMapStart, the Wave.mc will only spend a tick or so on wave 0 before it starts onto wave 1 - and then your script will kick in and spawn the key -- far too short to determine if it works or not. Try changing it to index == 2 to check if the script works?

--

Jul 29 2013 Anchor

Yes, I was starting trying to get it to work for wave_basement, so it would start out as with Objective map mode. I had the :)index == 1 because since the waves didn't start until I pressed the button, it made it easy to test since I really don't have to fight to see if the code works.

Yea for now I'm assuming that since the script didn't start out as Wave, then the OnWaveStart function won't work at all :/
Oh well, thanks for trying guys, I'll figure something out eventually :)

P.S. Hey Infini, I have a functional version of wave_basement up right now without the zombie pips and chest like you wanted, as I was told through Bicell and Sudz

Jul 29 2013 Anchor

I got it~! It's been a LONG while since I've gotten my feet dirty with code, and I've been wondering why I've had my misgivings about our codes.

To put it very simple, OnWaveStart is a function that is defined only client-side. I was incorrect before, Infini used InvokeScriptEvent("OnWaveStart", WaveIndex); which essentially allows the client to give the wave achievements. Thus, any Server required code will simply never run. And I definitely do not suggest removing the check to see if it is Server or not - you might run into other weird things. You can try. It will probably mess up though.

So, the solution is one that I implemented back when I tried making Wave Gun Game - that is make a Mode-Script. This way, you have full control and ability to dictate what happens Client Side and what happens Server Side.

Here's a quick and simple map showing how I've done this:

Map file: Mediafire.com
Script file: Mediafire.com
Pastebin file: Pastebin.com

You will notice my old Gun Game Wave script in there - I kept it there so that I could have visual clues as to when the Server calls 'end of wave'. I've also left in a debugging line (BroadcastChat) in order to help... debug. As it stands, the medpack spawns at the start of wave 2, and does not ever despawn, but IT WORKS~!~! And just in case you guys have not figured out, my medpack is called mediSpawn. Lines to note: 123-130 is my spawn function, 294 is where I despawn, and 357 is where I call the spawn function. Please note that 357 is done in a server call (line 323) whereas where OnWaveStart is defined (line 377) is done in a client call (line 369, else of line 323).

PS: I also told you to put up a post about your map so to attract Infini's attention - mainly since I'm busy with real life work and Infini seems to have his own schedules, so forums are probably the best way to communicate. XP

Edited by: sudzzuds

--

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.