Get number of players in actual .map file?

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Get number of players in actual .map file?

Post by Gwledig »

Hi I was wondering if there's any way of checking if a particular side exists, not as set by the joining of a player in lobby, but from the .map itself, i.e. check if the side is set in the map?
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Get number of players in actual .map file?

Post by Ravana »

Since map is effectively text file you could check if it includes numbers in format of

Code: Select all

1 Xos       , 5 Xos
, that Xos is just from example I used, can be any terrain code, need to exclude border_size=1 though.
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: Get number of players in actual .map file?

Post by Gwledig »

thanks, can you be a bit more specific how you would do this in an event, scenario toplevel etc or what?
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Get number of players in actual .map file?

Post by Ravana »

Code: Select all

	[event]
		name=moveto
		first_time_only=no
		{VARIABLE map "{~add-ons/Maps_by_Inanna/maps/huge_empty.map}"}
		[if]
			[variable]
				name=map
				contains=2
			[/variable]
			[then]
				[lua]
					code=<< wesnoth.message("lua","2 found") >>
				[/lua]
			[/then]
			[else]
				[lua]
					code=<< wesnoth.message("lua","2 not found") >>
				[/lua]
			[/else]
		[/if]
		[if]
			[variable]
				name=map
				contains=4
			[/variable]
			[then]
				[lua]
					code=<< wesnoth.message("lua","4 found") >>
				[/lua]
			[/then]
			[else]
				[lua]
					code=<< wesnoth.message("lua","4 not found") >>
				[/lua]
			[/else]
		[/if]
		
	
	[/event]
Something like this, though mind border then.
Tested to not cause oos.
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: Get number of players in actual .map file?

Post by Gwledig »

thanks Ravana I'll see if I can get this to detect the number of players in a randomly generated map & set the players in the scenario dynamically.... otherwise you can select a random map with 4 players but the game lobby shows 6 cos its defined in the scenario, then when the game starts odd things happen, so i think I need to modify the random generator scenario to place players on a wider range of hexes as well as detecting & auto updating the scenario so erroneous game lobby player slots don't show up, as there will only be the number of spawn points available as set by the host who configured the random map........ the idea of using a random map for the scenario is looking a bit of a pain....
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: Get number of players in actual .map file?

Post by Gwledig »

Ravana can you also tell me the best kind of event to replace castle and keep tiles with grass? This doesn't seem to work for the random map generator scenario, not sure why -

Code: Select all

#define REFRESH_SCREEN
[event]
name=turn 1 refresh  
first_time_only=no
[redraw]  
side=1-6
[/redraw]

[terrain]
[and]
terrain=*^K* # here is the filter criterion
[/and]
terrain=Gg # and the new terrain
[/terrain]
[terrain]
[and]
terrain=*^C* # here is the filter criterion
[/and]
terrain=Gg # and the new terrain
[/terrain]


fire_event=yes
[/event]
#enddef
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Get number of players in actual .map file?

Post by Ravana »

Prestart event would work best, I dont think you need redraw then either. That depends on when you change map, just make sure this happens later.

Havent dealt with terrain filtering but Im not sure if it is allowed to start with * there.
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: Get number of players in actual .map file?

Post by Gwledig »

sorry I should have just done some work and testing, got it sorted in the end, start or prestart and this syntax

Code: Select all

#define REMOVE_CASTLES
[event]
name=prestart
first_time_only=yes

[terrain]
[and]
terrain=K* # here is the filter criterion
[/and]
terrain=Gg # and the new terrain
[/terrain]
[terrain]
[and]
terrain=C* # here is the filter criterion
[/and]
terrain=Gg # and the new terrain
[/terrain]



fire_event=yes
[/event]
#enddef
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: Get number of players in actual .map file?

Post by James_The_Invisible »

Just a side note: fire_event=yes in [event] does nothing at all as far as I know. I noticed that you add it to your events, it is useless.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Get number of players in actual .map file?

Post by Ravana »

Notice that some people indeed create maps with keeps and castles as overlays. One way is storing whole map and then using contains= for each hex.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Get number of players in actual .map file?

Post by Sapient »

Why not just use [store_starting_location] ?
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: Get number of players in actual .map file?

Post by Gwledig »

The main thing I am still trying to figure out is how to get the game lobby to show the correct number of slots available in the actual map, for a random map where the host can modify the number of players, so the random map scenario.cfg might be set to 6 [side] slots, allowing for 6 players, but the host could make a game with my random map scenario and change this to 4 or even 2, then when the game lobby appears it will show 6 slots due to 6 [side] tags in the scenario, then when 6 players join you will get weird stuff happening because there are only, say 4 spawn points on the map. So I am trying to dynamically set the number of [side] tags in the scenario to reflect the number of spawn points set in the random map.
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: Get number of players in actual .map file?

Post by Gwledig »

As far as I can tell from the wesnoth wiki, the code

Code: Select all

fire_event=yes
is used for custom events with your own custom event name=xxxx I have just added it as part of an event templater which I copied and pasted, it's harmless and just kicks in the event at the point when it's called where a core supported event name isn't present.
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Get number of players in actual .map file?

Post by Ravana »

From what I understand fire_event=yes is for when you do something with wml that normally would happen in game, like killing unit.
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: Get number of players in actual .map file?

Post by James_The_Invisible »

@Gwledig I cannot remember reading this anywhere and it actually sounds like an outdated info to me. Events with custom names are supported without it since I remember. Can I ask where you have read it?
Actually is used for things that Ravana outlined. Other actions when this makes sense is selecting, moving, harming, recalling, unstoring units and capturing villages via WML.
Post Reply