Skip to content

Add possibility of modifying dynamic objects behavior #784

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

forkerer
Copy link
Contributor

@forkerer forkerer commented Jan 20, 2019

This pull request aims to add possibility of modifying behavior of dynamic objects. This includes properties like their mass, particle effects played by them, if their explode or not, etc. By now mta has setObjectProperty() function implemented, but it's limited to custom created objects, and doesn't allow to change behavior of original world objects. All default properties, along with simple documentation, can be found in object.dat in GTA SA data folder. All changed properties are restored to default once user leaves server.

1. Property groups used by certain models IDs

SA by default contains 160 property groups for dynamic objects, multiple models can share single properties group, i've added possibility to change which group is used by which model, which required addition of those 3 functions:

-- Returns properties group used by given model ID, will return 0 if model isn't dynamic, as it's defaulted to that in engine
engineGetModelPhysicalPropertiesGroup(modelID) 

-- Changes which property group given model will use
engineSetModelPhysicalPropertiesGroup(modelID, groupID)

-- Restores model to default state
engineRestoreModelPhysicalPropertiesGroup(modelID)

I didn't notice any change when i've changed group id's of static objects (or any non dynamic stuff in CModelInfo table), but game is stable when those are changed for them, so i didn't disable ability to do so.

2. Properties themselves

There are multiple adjustable properties for each group, most of the changes made in them are visible after object is created, so most changes require you to get far away from object, and back to become visible.
Those 3 functions were created to give ability to modify those properties:

-- Property setters
engineSetObjectGroupPhysicalProperty(groupID, objectgroup-modifiable property, [...args] )

-- Property getters
engineGetObjectGroupPhysicalProperty(groupID, objectgroup-modifiable property)

-- Used to restore default property values
engineRestoreObjectGroupPhysicalProperties(groupID)

Those are the modifiable properties, along with their lua names and types:

enum eObjectGroup::Modifiable
{
    MASS,                //mass                         float
    TURNMASS,            //turn_mass                    float
    AIRRESISTANCE,       //air_resistance               float
    ELASTICITY,          //elasticity                   float
    BUOYANCY,            //buoyancy                     float
    UPROOTLIMIT,         //uproot_limit                 float
    COLDAMAGEMULTIPLIER, //col_damage_multiplier        float
    COLDAMAGEEFFECT,     //col_damage_effect            eObjectGroup::DamageEffect
    SPECIALCOLRESPONSE,  //special_col_response         eObjectGroup::CollisionResponse
    CAMERAAVOID,         //avoid_camera                 bool
    EXPLOSION,           //cause_explosion              bool
    FXTYPE,              //fx_type                      eObjectGroup::FxType
    FXOFFSET,            //fx_offset                    CVector
    FXSYSTEM,            //fx_system                    takes string, uses FxSystemBlueprint
    SMASHMULTIPLIER,     //smash_multiplier             float
    BREAKVELOCITY,       //break_velocity               CVector
    BREAKVELOCITYRAND,   //break_velocity_randomness    float
    BREAKMODE,           //break_mode                   eObjectGroup::BreakMode
    SPARKSONIMPACT       //sparks_on_impact             bool
};

The specialized properties enums looks like so:

enum DamageEffect // Dictates which damage effect is applied to object on collision
{
    NO_EFFECT = 0,          //none              Object doesn't change at all once it's damaged
    CHANGE_MODEL = 1,       //change_model      Some of the objects change model on collision, those use this
    SMASH_COMPLETELY = 20,  //smash             Object is smashed
    CHANGE_THEN_SMASH = 21, //change_smash      First CHANGE_MODEL, afterwards smash on collision
    BREAKABLE = 200,        //breakable         Object is breakable normally
    BREAKABLE_REMOVED = 202 //breakable_remove  object.dat says: '(ie. never regenerated after destroyed)'
};

enum CollisionResponse // How object responds to being collided with
{
    NO_RESPONSE, //none
    LAMPPOST,    //lamppost
    SMALLBOX,    //small_box
    BIGBOX,      //big_box
    FENCEPART,   //fence_part
    GRENADE,     //grenade
    SWINGDOOR,   //swingdoor
    LOCKDOOR,    //lockdoor
    HANGING,     //hanging
    POOLBALL     //poolball
};

enum FxType // Dictates when particles will be created when colliding with object
{
    NO_FX,                //none
    PLAY_ON_HIT,          //play_on_hit
    PLAY_ON_DESTROYED,    //play_on_destroyed
    PLAY_ON_HIT_DESTROYED //play_on_hitdestroyed
};

enum BreakMode // Dictates how object can be damaged, info from object.dat:
{
    NOT_BY_GUN, //not_by_gun    'not breakable by gun'
    BY_GUN,     //by_gun        'breakable'
    SMASHABLE,  //smashable     'smashable'
};

Fx system:

Any particle system included in SA could be used by dynamic objects, but after testing i noticed that looping particle systems stay on map forever (even after leaving server), so i had to disable ability to use those, only non looping system are acceptable by fx_system property, those are: (from effects.fxp file)

wallbust,
shootlight,
puke,
explosion_door,
explosion_crate,
explosion_barrel,
blood_heli,
tree_hit_palm,
tree_hit_fir,
water_swim,
water_splsh_sml,
water_splash_big,
water_splash,
water_hydrant,
tank_fire,
riot_smoke,
gunsmoke,
gunflash,
explosion_tiny,
explosion_small,
explosion_molotov,
explosion_medium,
explosion_large,
explosion_fuel_car,
exhale,
camflash,
prt_wake

3. Test resource

DOWNLOAD: props.zip
I'm including simple resource containing editor for those properties, that looks like that:

image

Simply start resource, and write /showgui to make it visible, same command to hide it back again.

Properties editor:
-- Changes properties of given group
Model editor:
-- Gives ability to change properties group used by given model
Presets:
-- Some simple presets, and ability to restore properties of all groups.
-- Given presets are: make everything explode, make everything easy to destroy, make everything undestroyable

Kamil Marciniak added 29 commits January 10, 2019 17:32
- changed the way of how backup ObjectDynamicInfo works
- added functions to get/set/restore model dynamic properties group
- some other small changes
also added missing property change
@forkerer forkerer added the enhancement New feature or request label Jan 20, 2019
@forkerer
Copy link
Contributor Author

Lua API seems reasonable. Is it possible to create additional object groups or is it limited to the default set of groups?

Limited to default 160 groups, dunno how many references to current table location are in the gta sa, and current amount is plenty for what's needed i think.

@patrikjuvonen patrikjuvonen added this to the Backlog milestone Feb 23, 2019
patrikjuvonen and others added 2 commits February 23, 2019 14:58
1. Added const modfier to functions where possible
2. Changed constructor to use initializer list
3. Removed unnecessary call to ChangeSafeguard() from one of the getters
Copy link
Contributor

@patrikjuvonen patrikjuvonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. Looks good to me!

I'm looking at this line: https://github.com/multitheftauto/mtasa-blue/pull/784/files?w=1#diff-72a39fa83b01cb9bbbfc41c8928ac793R1343 and right now I have PR #299 open for current LOD functions that crash the client if passed an ID of 20000+. You seem to error out if the ID is not between 0 and 20000. Can you give a little more context on why this is? I'm trying to understand what's beyond 19999 that makes it crash the client so I can figure out a permanent solution with good context for the other issue.

@qaisjp commented:

If there is an underlying bug with CGameSA::GetModelInfo then that should be fixed instead.

I'm trying to figure out how to give closure to this 20000 issue.

@forkerer
Copy link
Contributor Author

forkerer commented Feb 23, 2019

As far as I'm aware, (and in the IDB i'm using), 20000 is original size of that array in gta sa, trying to change physical properties of anything above that crashes the client. I think the additional space reserved in CGameSA (up to 26000) was made either by mistake, or in case of mta team wanting to expand some limits.

@patrikjuvonen
Copy link
Contributor

Found something old but interesting regarding dynamic objects on the Wiki: https://wiki.multitheftauto.com/wiki/Dynamic_object

Copy link
Member

@sbx320 sbx320 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. I added some comments, but other than that it should be good.

Only issue apart from that would be the discussion on changing result on usage errors in scripting #821

Kamil Marciniak added 2 commits April 14, 2019 09:50
Calling of internal functions without _asm blocks
Const specifier in range loops where needed
Replaced pointers with std::unique_ptrs
Fixed inconsistency with bad arguments checking in some lua functions
@forkerer forkerer requested a review from sbx320 April 14, 2019 08:31
@ghost
Copy link

ghost commented Apr 14, 2019

Nice work! Does the collision properties work for custom objects? I'm planning to make CColModel object based rather than model based.

@forkerer
Copy link
Contributor Author

Since most of the properties are assigned in object constructor, based on model group ID, it should work without problems on custom models that replace dynamic objects. I haven't tested that tho so can't be sure.

Copy link
Member

@sbx320 sbx320 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just needs a decision on the script error thing...

@ghost
Copy link

ghost commented May 24, 2019

Once this PR is merged, modelers can use this to generate breakable models: https://github.com/DK22Pac/v2saconv

@patrikjuvonen patrikjuvonen modified the milestones: Backlog, 1.6 Sep 2, 2019
Copy link
Contributor

@patrikjuvonen patrikjuvonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These errors should be changed accordingly (#821 (comment)).

@patrikjuvonen patrikjuvonen self-assigned this Sep 2, 2019
@forkerer
Copy link
Contributor Author

forkerer commented Sep 2, 2019

@patrikjuvonen Done :)

@patrikjuvonen
Copy link
Contributor

Great job! 👍 Thank you for the PR =)

@patrikjuvonen patrikjuvonen merged commit 03b4914 into multitheftauto:master Sep 2, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants