Different impact zones for a sprite

  • Thread starter Thread starter ChaosWarlord
  • Start date Start date
C

ChaosWarlord

Guest
I want to use different pain/fall animations according to where are hitten.

A player/enemy can suffer an attack to his head, torso, sensitive zone, legs (and also a chance to get a stomp to their feet) playing a right animation.

Can it be done with scripts?
 
Most certainly. The lasthit property can be used to get exact coordinates of a collision, and from there it's just a matter of doing some math vs. the receiving entity's height and acting accordingly. Here's a very old example of how I did it in on of my projects (note this is for blocking poses, but hit pains obviously use the same principal:

Code:
void block(void vEntity){

	/*
	block
	Damon Vaughn Caskey
	2010_07_31
	~2011_02_25

	Universal blocking function.

	vEntity:	Calling entity.
	*/

    void vAttacker  = getlocalvar("attacker");                                              //Attacking entity.
    int  iHeight;                                                                           //Caller height.
    int  iHitY;                                                                             //Last hit Y.
    int  iAni;																				//Caller animation.
    int  fY;                                                                                //Attacker Y location.
    int  iBase;                                                                             //Attacker base Y.
    int  iBlockAni;                                                                         //Final block animation.
    int  iTime		= openborvariant("elapsed_time");                                       //Elapsed game time.
    int  iKeylst;																			//Time of last Special press.

	if(!vEntity){	vEntity = getlocalvar("self");	}

	iAni		=	getentityproperty(vEntity, PROP_ANIMATION_ID);									//Get caller animation.
	iKeylst		=	getentityvar(vEntity, IDXE_KEY1SP);												//Get last time Special Key was pressed.

    //Fatal Fury style proximity blocking. If entity is blocking (not an attack with autoblock),
    //switch to the appropriate block animation based on height of incomming attack.
    if (iAni == A_BLOCK																		//In block animation?
        || iAni == AC_BLOCKNOR
        || iAni == AC_BLOCKLOW
        || iAni == AC_BLOCKMID
        || iAni == AC_BLOCKHIGH)
    {
        iHeight = getentityproperty(vEntity, "height") + getentityproperty(vEntity, "base");		//Get current height + base.
        iHitY   = openborvariant("lasthita");                                               //Get Y axis of last hit.

        if (iHitY < iHeight * 0.3)                                                          //Below 30% of height?
        {
            iBlockAni = AC_BLOCKLOW;                                                           //Low block.
        }
        else if (iHitY < iHeight * 0.75)                                                    //Below 75% of height?
        {
            iBlockAni = AC_BLOCKMID;                                                           //Middle block.
        }
        else                                                                                //Attack is at or above 75% of height.
        {
            fY          = getentityproperty(vAttacker, "a");                                //Get attacker height.
            iBase       = getentityproperty(vAttacker, "base");                             //Get attacker base.

            if ((fY - iBase) > 1)                                                           //Attacker airborne?
            {
                iBlockAni = AC_BLOCKHIGH;                                                      //High block.
            }
            else
            {
                iBlockAni = AC_BLOCKNOR;                                                       //Normal block (BLOCKPAIN).
            }
        }

        ani0009(vEntity, iBlockAni, -1);														//Apply block animation.
    }
}

DC
 
That's really old code and there are better ways to do it now, but it should still do the job. Enjoy.

DC
 
Thanks for the tip, DC

About this:
openborvariant("lasthita"); 

Everytime I see a new openborvariant. Where we can find the list with ALL variants?
Just ot the source code?

Edit:

Is this the full list?

"background",
"blockade",
"branchname",
"count_enemies",
"count_entities",
"count_npcs",
"count_players",
"current_branch",
"current_level",
"current_palette",
"current_scene",
"current_set",
"current_stage",
"effectvol",
"elapsed_time",
"ent_max",
"freeram",
"game_paused",
"game_speed",
"gfx_x_offset",
"gfx_y_offset",
"gfx_y_offset_adj",
"hResolution",
"in_cheat_options",
"in_control_options",
"in_gameoverscreen",
"in_halloffamescreen",
"in_level",
"in_load_game",
"in_menuscreen",
"in_new_game",
"in_options",
"in_selectscreen",
"in_showcomplete",
"in_sound_options",
"in_start_game",
"in_system_options",
"in_titlescreen",
"in_video_options",
"lasthita",
"lasthitc",
"lasthitt",
"lasthitx",
"lasthitz",
"levelheight",
"levelpos",
"levelwidth",
"lightx",
"lightz",
"maxanimations",
"maxattacktypes",
"maxentityvars",
"maxglobalvars",
"maxindexedvars",
"maxplayers",
"maxscriptvars",
"models_cached",
"models_loaded",
"musicvol",
"nofadeout",
"nojoin",
"nopause",
"nosave",
"noscreenshot",
"numpalettes",
"pakname",
"pause",
"pixelformat",
"player",
"player1",
"player2",
"player3",
"player4",
"player_max_z",
"player_min_z",
"sample_play_id",
"scrollmaxx",
"scrollmaxz",
"scrollminx",
"scrollminz",
"self",
"shadowalpha",
"shadowcolor",
"skiptoset",
"slowmotion",
"slowmotion_duration",
"smartbomber",
"soundvol",
"textbox",
"ticks",
"totalram",
"usedram",
"vResolution",
"viewporth",
"viewportw",
"viewportx",
"viewporty",
"vscreen",
"waiting",
"xpos",
"ypos",
 
Back
Top Bottom