Randomly targeting a enemy ship in system.

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderator: Committer

Message
Author
User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12249
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Randomly targeting a enemy ship in system.

#16 Post by Geoff the Medio » Sun Sep 18, 2016 5:10 pm

xlightwavex wrote:How would i generate a number from 1 to 10 and add it to the damage deduction to a ship...
Random probability = 0.5 is a condition that selects objects in the universe, which are fleets, ships, buildings, planets, system, or fields. Conditions are used for scope or activation of effectsgroups, specifying locations where ship parts or hulls or buildings can be produced, or where specials can be generated, and in some statistic calculations.

If you want a random number to use as one of the parameters to an effect, use RandomNumber(0.0, 10.0) or similar. This is an operation, which returns a number. 0.0 and 10.0 are parameters that can be constant numbers as in the example, or could be expressions, like 10.0 + 5.0 or 1 + Source.Population.

I think you're trying to script something too complicated to start with all at once... Maybe start with just getting the scope for your effect to work as desired, then worry about how to calculate what to set meter values to using expressions and randomness.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Randomly targeting a enemy ship in system.

#17 Post by xlightwavex » Sun Sep 18, 2016 7:08 pm

Geoff the Medio wrote: I think you're trying to script something too complicated to start with all at once... Maybe start with just getting the scope for your effect to work as desired, then worry about how to calculate what to set meter values to using expressions and randomness.
NumberOf number = NUMBER condition = CONDITION

Matches at most NUMBER objects that match CONDITION. If fewer than NUMBER objects match CONDITION, all such objects are matched. If more than NUMBER objects match CONDITION, NUMBER such objects are randomly selected and matched.
Ok so far i have this i have no idea if it will actually work i need to generate a sitrep to see i guess. The only thing i know is it doesn't error im not sure if this actually ends up with a ship being given to numberOf or not.

Code: Select all

BuildingType
    name = "BLD_PLANET_GUN"
    description = "BLD_PLANET_GUN_DESC"
    buildcost = 25
    buildtime = 5
    location = And 
	[
        Planet
        Not Contains Building name = "BLD_PLANET_GUN"
		Not Planet type = [GasGiant]
        OwnedBy empire = Source.Owner
    ]
	effectsgroups = 
	[
        EffectsGroup 
		scope = NumberOf number = 1 condition = And 
		[
		        Contains Planet And
			    [
			       Building name = "BLD_PLANET_GUN"
				   OwnedBy empire = Source.Owner
			    ]
			    Contains Ship And 
				[
				   OwnedBy affiliation = EnemyOf empire = Source.Owner
				]
		]
	    effects = 
		[
            SetStructure value = Value - RandomNumber(10.0, 20.0)
        ]
	]

Post Reply