[sf2ce] Score Board - Plugin

If you are having problems finding or using cheats for an Emulator (particularly MAME/MESS) or have found a trick that you wish to share this is the place to do it. But please read the Cheat FAQ first.
Post Reply
yacsha
Posts: 13
Joined: Tue Nov 12, 2019 6:56 am
Location: Perú
Contact:

[sf2ce] Score Board - Plugin

Post by yacsha »

Here I leave a plugin I was working on, it is a Score Board for the fights in sf2ce. It works only when 2 human players are playing and is only reset when leaving the game. It is still in Beta, but I would like to hear your suggestions to improve it.

Thanks to POF for developing score board for 3 players in ssf2, which was the basic idea to develop this plugin.

Best Regards

archive: init.lua

Code: Select all

-- Score Board for SF2CE v1.0 - Nov-2019
-- Youtube channel: https://www.youtube.com/channel/UC-XTXmO-_bJ4M9yPfj1Xpvw
-- Thanks for 2013 Pau Oliva Fora for original idea and adapted by yacsha

local exports = {}
exports.name = 'ScoreBoard 1.0'
exports.version = '1.0'
exports.description = 'Score for SF2CE offline'
exports.license = 'The BSD 3-Clause License'
exports.author = { name = 'Yacsha' }

local scoreboard = exports

function scoreboard.startplugin()	

	local function draw_scores( space, screen)

		local date = os.date("%d/%m/%Y")		

		screen:draw_box(5, 0, 130, 14, 0x80202020, 0)
		screen:draw_box(150, 0, 250, 14, 0x80202020, 0)
		screen:draw_box(290, 0, 340, 14, 0x80202020, 0)	
		screen:draw_text(10,3, "TEAM PERU Scoreboard - " .. date )
		screen:draw_text(160,3, "Player1 (" .. p1_score .. ") VS Player2 (" .. p2_score ..")")
		screen:draw_text(300,3, "by Yacsha" )
	
		if not count_scores then
			return
		end

		local winner = who_wins(space)


		if (winner == 1) then
			p1_score = p1_score + 1
		elseif (winner == 2) then
			p2_score = p2_score + 1
		end


		return
	end

	function who_wins( space )

		prev_is_p1_human = is_p1_human
		prev_is_p2_human = is_p2_human

		is_p1_human = space:read_u8(0xFF864C)
		is_p2_human = space:read_u8(0xFF894C)
		

		prev_p1_sets_won = p1_sets_won
		prev_p2_sets_won = p2_sets_won

		p1_sets_won = space:read_u8(0xFF864E)
		p2_sets_won = space:read_u8(0xFF894E)


		if (((is_p1_human==1 and is_p2_human==0) or (is_p1_human==0 and is_p2_human==1) ) and (prev_is_p1_human==1 and prev_is_p2_human==1) ) then
			if (prev_p1_sets_won > prev_p2_sets_won) then
				return 1
			end
			if (prev_p2_sets_won > prev_p1_sets_won) then
				return 2
			end
		end

		return 0
	end

	function reset()

		count_scores = 1

		p1_sets_won = 0
		p2_sets_won = 0
		prev_p1_sets_won = 0
		prev_p2_sets_won = 0

		p1 = ""
		p2 = ""

		p1_char = 0
		p2_char = 0

		p1_color = 0
		p2_color = 0

		is_match_active = 0
		prev_is_match_active = 0

		p1_score = 0
		p2_score = 0

		is_p1_human = 0
		prev_is_p1_human = 0

		is_p2_human = 0
		prev_is_p2_human =  0

	end


	emu.register_start(function ()		
		cpu = manager:machine().devices[":maincpu"]
		
	end)


	emu.register_frame_done(function()

		space = cpu.spaces["program"]	

		screen = manager:machine().screens[":screen"]
		
		draw_scores(space, screen)

	end)

	emu.register_stop(function()
		reset()
	end)

	reset()

	


end

return exports

archive: plugin.json

Code: Select all

{
  "plugin": {
	"name": "scoreboard",
	"description": "ScoreBoard 1.0",
	"version": "1.0",
	"author": "Yacsha",
	"type": "plugin",
	"start": "false"
  }
}
a big fan of SF2CE :D
Youtube channel: Yacsha Games
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: [sf2ce] Score Board - Plugin

Post by crazyc »

Next version you'll be able to add a popup menu option to enter the player names (https://github.com/mamedev/mame/commit/ ... e4d54a40bb).
yacsha
Posts: 13
Joined: Tue Nov 12, 2019 6:56 am
Location: Perú
Contact:

Re: [sf2ce] Score Board - Plugin

Post by yacsha »

Good news crazyc, hopefully it can be used from the next MAME version. How would I have access to the names of the players to add them to the score board? Please, would you be so kind as to give me a hint?
a big fan of SF2CE :D
Youtube channel: Yacsha Games
crazyc
Posts: 31
Joined: Sat Apr 30, 2016 4:49 pm

Re: [sf2ce] Score Board - Plugin

Post by crazyc »

Look at the dummy plugin, https://github.com/mamedev/mame/blob/ma ... y/init.lua , to see how to create a menu then the patch above to see if the key press event is a unicode character.
Post Reply