Jump to content
Sign in to follow this  
Madin

Crate probability progress

Recommended Posts

Here is some junk code, that hopefully the more talented and imaginative coders can improve upon.

 

Background

This is based on my efforts to simulate older C&C games which had different probabilities of a crate spawning, depending on the type of crate surprise that was contained within.

I basically wanted this because I wanted to have more dramatic crate surprises (like nuke explosions), which need to have some kind of restriction.

 

The base of this of this code is the 'UnitCrateCollide'. And some code that Styg's showed me way back.

<!-- Basic object for all other unit crates 
 -->
<GameObject id="UnitCrateMP_Dummy" inheritFrom="UnitCrate" EditorName="UnitCrateMP_Dummy" Description="DESC:Crate">
 <DisplayName xai:joinAction="Replace">NAME:Crate</DisplayName>
 </GameObject>

Here is the test crate which inherits from the dummy crate:

<GameObject id="UnitCrateMP_Test" inheritFrom="UnitCrateMP_Dummy" EditorName="UnitCrateMP_Test">
<Behaviors>
 <UnitCrateCollide id="ModuleTag_CrateCollide" UnitCount="1" UnitType="CrateDummy_Test"/>
 </Behaviors>
 </GameObject>

Here is the invisible dummy object that is spawned, this objects purpose is to allow for the all important LUA interaction:

<GameObject id="CrateDummy_Test" Side="GDI" EditorSorting="STRUCTURE" CommandSet="EmptyCommandSet" KindOf="UNATTACKABLE NOT_AUTOACQUIRABLE IMMOBILE STRUCTURE RESIST_EMP IGNORED_IN_FINDPOSITIONAROUND IGNORE_FOR_VICTORY NO_COLLIDE" RadarPriority="NOT_ON_RADAR">
 <DisplayName>CrateDummy_Test</DisplayName>
 <ArmorSet Armor="NoArmor"/>
 <Draws/>
<Behaviors>
 <LifetimeUpdate id="ModuleTag_LifetimeUpdate" MinLifetime="0.1s" MaxLifetime="0.1s"/>
<CreateObjectDie id="ModuleTag_CreateObjectDieSmEXP" CreationList="OCL_SmallExplosion">
 <DieMuxData DeathTypes="ALL"/>
 <UpgradeRequired>Upgrade_SmallExplosion</UpgradeRequired>
 </CreateObjectDie>
<CreateObjectDie id="ModuleTag_CreateObjectDieMeEXP" CreationList="OCL_MediumExplosion">
 <DieMuxData DeathTypes="ALL"/>
 <UpgradeRequired>Upgrade_MediumExplosion</UpgradeRequired>
 </CreateObjectDie>
<CreateObjectDie id="ModuleTag_CreateObjectDieNuEXP" CreationList="OCL_NukeExplosion">
 <DieMuxData DeathTypes="ALL"/>
 <UpgradeRequired>Upgrade_NukeExplosion</UpgradeRequired>
 </CreateObjectDie>
 </Behaviors>
<AI>
 <AIUpdate id="ModuleTag_AIUpdate" AutoAcquireEnemiesWhenIdle="NO" AILuaEventsList="TestCratesFunctions"/>
 </AI>
<Body>
 <ActiveBody id="ModuleTag_Body" MaxHealth="9999999.0"/>
 </Body>
<Geometry IsSmall="true">
 <Shape Type="SPHERE" MajorRadius="1"/>
 </Geometry>
 <VisionInfo VisionRange="1" ShroudClearingRange="0"/>
 </GameObject>

Has you can see it has a 'LifetimeUpdate' so that it is only around for a limited time. It also importantly has an AI module, and you can see that it has a number of 'CreateObjectDie' modules that require upgrades to trigger.

 

Here is the Scriptevent:

    <EventList Name="TestCratesFunctions" Inherit="BaseScriptFunctions">
		<EventHandler EventName="OnCreated" ScriptFunctionName="OnTestCrateCreated" DebugSingleStep="false"/>
    </EventList>

A very simple 'Oncreated' based event.

 

Now to LUA:

function OnTestCrateCreated(self)
        local num =     GetRandomNumber()
        if num <= 0.6 then
        ObjectGrantUpgrade( self, "Upgrade_SmallExplosion" )
        elseif num <= 0.9 then
        ObjectGrantUpgrade( self, "Upgrade_MediumExplosion" )
        else -- if num  > 0.9 then
        ObjectGrantUpgrade( self, "Upgrade_NukeExplosion" )
        end
end

Here you can see where the probabilities are set, and also how the upgrades that trigger the 'CreateObjectDie' are given.

The OCL created from that module are what hold the actual crate surprises, whether that is explosions, units, health, attribute boost ETC.

Here is a look at one of the explosion surprises:

<ObjectCreationList id="OCL_MediumExplosion">
<CreateObject Disposition="RELATIVE_ANGLE USE_WATER_SURFACE" DestinationPlayer="" Options="IGNORE_ALL_OBJECTS">
 <CreateObject>CrateDummy_UnitCrateMP_ExplosiveMedium</CreateObject>
 </CreateObject>
 </ObjectCreationList>

The OCL.

<GameObject id="CrateDummy_UnitCrateMP_ExplosiveMedium" Side="Neutral" EditorSorting="UNIT" CommandSet="EmptyCommandSet" KindOf="IMMOBILE INERT UNATTACKABLE NO_COLLIDE" RadarPriority="NOT_ON_RADAR">
 <ArmorSet Armor="NoArmor"/>
 <Draws/>
<Behaviors>
<SlowDeath id="ModuleTag_Death" DestructionDelay="0.1s">
 <DieMuxData DeathTypes="ALL"/>
 </SlowDeath>
<FireWeaponWhenDead id="ModuleTag_FireWeaponWhenDead" InitiallyActive="true" DeathWeapon="LargeCrateExplosiveWeapon">
 <DieMuxData DeathTypes="ALL"/>
 </FireWeaponWhenDead>
 <LifetimeUpdate id="ModuleTag_LifetimeUpdate" MinLifetime="0.1s" MaxLifetime="0.1s"/>
 </Behaviors>
<Body>
 <ActiveBody id="ModuleTag_Body" MaxHealth="9999999.0"/>
 </Body>
 <VisionInfo VisionRange="0" ShroudClearingRange="0"/>
 </GameObject>

The dummy object which has a limited life, and a 'FireWeaponWhenDead' module which gives us both the explosion and the damage!

 

It goes without saying that the code would be a lot more lengthy depending on how many unique crate surprises you have, but you get the basic idea.

Edited by Madin

Share this post


Link to post

You could just edit the GenericCrateSpawner to add more new crates to its spawn list. Thus you wouldn't need any upgrades and LUA. It's nice if you just want one object to do more stuff, but it makes it just more complicated.

Share this post


Link to post

You could just edit the GenericCrateSpawner to add more new crates to its spawn list. Thus you wouldn't need any upgrades and LUA. It's nice if you just want one object to do more stuff, but it makes it just more complicated.

True, but I was looking for something more precise than adding more to a list.

 

For example if I had a Nuke crate, how often would I have to increase all the other crates in order to insure that it showed up less than 1% of the time?

I see that you are good at maths, but for me, having a numerical fraction to input is easier.

Share this post


Link to post

True, it would have been nice if they had a probability attribute.

Share this post


Link to post

fireweponwhendead does have a probability attribute, if you would couple that with a deathtype, that could be an option?

 

edit:maybe not, having when probability trigger wont exclude another from triggering aswell iirc. Altho if your lua number < 9 and < 6 wont both upgrades be granted aswell?

 

At this point i cant think of a better way of doing it, i had an idea of using randommodelconditions to trigger something like this once, wich would work but would involve alot more of copypasting sameblocks of code depending on how many different crate types there where. iirc the benefit was that idealy no 2 or more effects could trigger at the same time.

Edited by Ravendark

Share this post


Link to post

Altho if your lua number < 9 and < 6 wont both upgrades be granted aswell?

No.

I have read why in LUA users wiki, but I have long since forgotten.

Lauren can probably tell you.

Share this post


Link to post

"This is because once one matches, the if statement skips checking the other conditions."

 

founded in the lua tutorials myself.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×