Something new

Discussions, requests and appeals to lay open the Z source code

Moderator: Brad

DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-04-23, 18:15

APC wrote:
2019-04-23, 10:00
Really great mod. The zombies appear on the odges of the map? The AI factories were stopped.
Zombies were grunts or lasers?
The zombies appear randomly in an rectangle. The blue AI factory is stopped. Zombies are grunts.
Here is the entire code:

Code: Select all

function onGameStart()--This functions disabled the blue fort
	fort = getFort(BLUE)
	enableProduction(fort, false)
end

function GetClosestEnemy(X, Y)--This function finds the closet red unit for a given position
	best_distance = 999999999

	max = getObjectCount()
	for j=0, max-1 do
		obj_red = getObject(j)
		type = getType(obj_red)
			
		if getOwner(obj_red) == RED and (type == VEHILCE or type == ROBOT or type == CANNON) then
			x, y = getPosition(obj_red)

			distance_squared = (X-x)*(X-x) + (Y-y)*(Y-y)


			if distance_squared < best_distance then
				best_distance = distance_squared
				best = obj_red
			end
		end
	end

	return best
end


function spawnZombie()--This functions creates a zombie
	x = math.random(7*16, 70*16)--random X position
	y = math.random(10*16, 110*16)--random Y position
	obj = createObject(ROBOT, GRUNT, x, y, GREEN)

	enemy = GetClosestEnemy(x, y)
	enemy_x, enemy_y = getPosition(enemy)
	setWaypoint(obj, 0, enemy_x, enemy_y)

	setAttackDamage(obj, 0)--disable attack of zombie
end


function everySecond()--will be execute once per second
	spawnZombie()--create a zombie
	spawnZombie()--create anothe zombie

	max = getObjectCount()
	
	for i=0, max-1 do--check if one of our zombies needs to explode
		obj_green = getObject(i)

		if getOwner(obj_green) ~= GREEN then
			goto continue
		end

		X, Y = getPosition(obj_green)

		enemy = GetClosestEnemy(X, Y)
		enemy_x, enemy_y = getPosition(enemy)
		clearWaypoints(obj_green)
		setWaypoint(obj_green, 0, enemy_x, enemy_y)

		explode = false

		for j=0, max-1 do
			obj_red = getObject(j)
			
			if getOwner(obj_red) == RED then
				x, y = getPosition(obj_red)

				range_squared = 20*20

				distance_squared = (X-x)*(X-x) + (Y-y)*(Y-y)


				if distance_squared < range_squared then
					explode = true
					break
				end
			end
		end

		if explode then
			bomb = createMissile(X, Y, X, Y, 1)--Create an explosion (same as grenade)
			killObject(obj_green)
			break--Since the amount of units changed, break (just in case)
		end

		::continue::
	end
end
I hope to code is understandable also to non-programmers. That was my idea when creating the Lua <-> Zed Online API.
APC
Lieutenant
Lieutenant
Posts: 74
Joined: 2008-11-07, 16:18
Location: SLOVAKIA

Re: Something new

Post by APC » 2019-04-23, 20:47

The code looks clear and understandable. It would be simple to modify such scenarion as you made. But to write something like that from scratch would be difficult for me. But I can use interesting maps and scenarios as templates.
LUA was used also in Blitzkrieg game scenarios and it was my dream to find time and try to modify some of it. Now I have more motivation about LUA.
DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-04-24, 00:17

APC wrote:
2019-04-23, 20:47
The code looks clear and understandable. It would be simple to modify such scenarion as you made. But to write something like that from scratch would be difficult for me. But I can use interesting maps and scenarios as templates.
LUA was used also in Blitzkrieg game scenarios and it was my dream to find time and try to modify some of it. Now I have more motivation about LUA.
Great! Writing that from scretch is hard for someone not experience I agree.
I the next release I will include 3 maps with scripts. This zombie map, the tower defense map and a fog of war map.
I started writing a tutorial for the API here: https://sourceforge.net/p/zedonline/wiki/lua/ but its far from being complete.
I believe there are also a bunch a functions still missing that script writers will need ...

To edit scripts. Open the map in the Zed Online map editor (version >= 0.1.5). Under "view" there should be a Lua option.
There you can edit the code of the map. Maps containing scripts can only be saved in the .zmap not .map format.

By the way, you can also double left click or right click -> edit a map in the Windows explorer that also opens a map directly from the explorer.
APC
Lieutenant
Lieutenant
Posts: 74
Joined: 2008-11-07, 16:18
Location: SLOVAKIA

Re: Something new

Post by APC » 2019-04-24, 08:22

I will definitely try this new features of Zed Online maps format. Using scripts I can create AI which will match to specific map. My ide was to define defense zones for AI and zones where attack squads would be accumulated and then make frontal attack. Not attack one-by-one as the nowadays AI. Also positions for produced howitzers and Rocket artillery could be better optimized this way. Using random variables the scripted AI could be less predictable.

It would be interesting also having nowadays Zod Engine AI rewritten from source C to LUA included in specific map and just tweaked some parameters or add some minor changes to this universal AI according to the specifics of the map.
DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-04-26, 19:48

APC wrote:
2019-04-24, 08:22
I will definitely try this new features of Zed Online maps format. Using scripts I can create AI which will match to specific map. My ide was to define defense zones for AI and zones where attack squads would be accumulated and then make frontal attack. Not attack one-by-one as the nowadays AI. Also positions for produced howitzers and Rocket artillery could be better optimized this way. Using random variables the scripted AI could be less predictable.

It would be interesting also having nowadays Zod Engine AI rewritten from source C to LUA included in specific map and just tweaked some parameters or add some minor changes to this universal AI according to the specifics of the map.
Agreed! Porting the AI to Lua should be one of the next goals. This would also make it more open for anyone to develop/test their own AI.
Or let different AIs play against each other. The API needs I guess more functions first to write an entire AI in Lua though.
xxxXx
Tough
Tough
Posts: 9
Joined: 2018-04-22, 00:09
Are you a spam bot?: No

Re: Something new

Post by xxxXx » 2019-08-18, 10:39

I do hope adding new stuff becomes easy in the process. Some time ago I've made progress recreating the fire truck.

Image

For fun I tried concepting new units and structures, but beside single frames there is not much else.
APC
Lieutenant
Lieutenant
Posts: 74
Joined: 2008-11-07, 16:18
Location: SLOVAKIA

Re: Something new

Post by APC » 2019-09-09, 16:23

Nice fire truck. Animation would be similar to APC, but at least the wheels should move during drive and the chassis jumping above the wheels during travelling.
DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-10-06, 15:42

I think there should also be a water turret on the fire truck. I think I have see something like that in the game files.

Also, can you create graphics for the cargo truck?
Possibly with multiple frames? All tanks in the game have 3 frames of animation for when they are driving.
xxxXx
Tough
Tough
Posts: 9
Joined: 2018-04-22, 00:09
Are you a spam bot?: No

Re: Something new

Post by xxxXx » 2019-11-03, 10:43

Hi,

glad you like the sprites. Animating this won't be an issue - I just need to know what frames are needed (e.g. if wheels and the chassis should be separate sprites). The turret is a non-issue - its a dome (so looks the sane from all angles) with a small barrel.

The cargo truck is a different story, needs much work. But I'll try to create some sprites for a reference and show here. Also as far as I know there is only one sprite of the truck and unlike the firetruck it doesn't resemble any other unit in the game. If anyone knows other sprites I'd be very grateful.
DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-11-03, 12:03

xxxXx wrote:
2019-11-03, 10:43
glad you like the sprites. Animating this won't be an issue - I just need to know what frames are needed (e.g. if wheels and the chassis should be separate sprites). The turret is a non-issue - its a dome (so looks the sane from all angles) with a small barrel.
I think I saw something like a turret for the firetruck once. I have to go through the files. I agree, it's a non-issue, I could do that myself even.
xxxXx wrote:
2019-11-03, 10:43
The cargo truck is a different story, needs much work. But I'll try to create some sprites for a reference and show here. Also as far as I know there is only one sprite of the truck and unlike the firetruck it doesn't resemble any other unit in the game. If anyone knows other sprites I'd be very grateful.
For the firetruck I believe the animation should look the same as for the jeep:

Image
Image

So 2 frames of animation. Everything except the tires move 1 pixel up.

These are the two images I have of the cargo truck:

Image
Image

I guess it should behave similar to the APC:

Image
Image
Image

with 3 frames of animation:

Image
Image
Image

EDIT: looking at the cargo truck again, since it has wheels I think it should have 2 frames of animation.
So, we would need the chassis and the wheels in separate files and then move the chassis up and down 1 pixel for the animation.
xxxXx
Tough
Tough
Posts: 9
Joined: 2018-04-22, 00:09
Are you a spam bot?: No

Re: Something new

Post by xxxXx » 2019-11-03, 14:10

OK, a quick sample:

Image

Looking at this I kinda understand why they dropped this...
DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-11-03, 17:58

xxxXx wrote:
2019-11-03, 14:10
OK, a quick sample:

Image

Looking at this I kinda understand why they dropped this...
Wow, cool!! Can you make a version of the second image with the "door" closed.
Then I can make a little animation when robots enter the vehicle.

I guess they didn't completely drop it as they replaced it with the APC.
xxxXx
Tough
Tough
Posts: 9
Joined: 2018-04-22, 00:09
Are you a spam bot?: No

Re: Something new

Post by xxxXx » 2019-11-11, 13:02

OK, some small progress.

a variant with no doors:

Image

I tried adding the APC doors, but it looked off. If anyone wants to take another shot please do.

Anyhow if you guys like what is done so far, I'll finish the missing frames.

Best!
DaMarkov
Major
Major
Posts: 180
Joined: 2018-12-20, 16:17
Are you a spam bot?: No
Contact:

Re: Something new

Post by DaMarkov » 2019-11-11, 16:27

xxxXx wrote:
2019-11-11, 13:02
OK, some small progress.

a variant with no doors:

Image

I tried adding the APC doors, but it looked off. If anyone wants to take another shot please do.

Anyhow if you guys like what is done so far, I'll finish the missing frames.

Best!
Nice! Look very cool. I think if you add images for the other diagonal directions I can try to do the animation myself.
I would just move everything except the tires up & down by a pixel.

By the way, did you get my PM?
xxxXx
Tough
Tough
Posts: 9
Joined: 2018-04-22, 00:09
Are you a spam bot?: No

Re: Something new

Post by xxxXx » 2019-11-11, 17:10

I'll work on this later in the week, hopefully this will be done before the weekend.
If you can do animations it would be great. I'll have 2 hard weeks at work.

I missed your email, didn't notice the notification. Anyhow great work :)

Also the cargo truck will have separate wheels (like the jeep), so will be easier to animate.
Post Reply