custom card code

Tio Akima

New member
Messages
349
Points
0
Age
36
Discord
TioAkima#0636
Github
Tio Akima
Emulator
Hello guys, I'm trying to make a card that adds ATK when the player is low on life (low hp)
Is there any such letter with this theme for me to follow as an example?
 

Do you think this is possible?

 
no.1, my 1st impression is run status_calc_pc everytime player receive hits or healing, which will be server resources heavy
OnPCStatCalcEvent already deem very resource heavy, and you want to make this heavier LOL

no.2, even I want to write this for fun
when player login, sd->battle_status.max_hp is 0, and can cause server crash
when I changed to sd->status.max_hp, that is the player's base hp, if the player have bMaxHP bonus then it will calculate wrongly

#include "common/hercules.h"
#include "map/pc.h"
#include "common/utils.h"
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"

HPExport struct hplugin_info pinfo = {
"bAtkBaseonHPRate",
SERVER_TYPE_MAP,
"0.1",
HPM_VERSION,
};

struct player_data {
int atk_baseon_hprate;
};

int ATK_BASEON_HP_RATE = 0;

int pc_bonus_pre( struct map_session_data **sd, int *type, int *val ) {
if ( *sd == NULL )
return 0;
// ShowDebug( "%d %d %d %d\n", (*sd)->base_status.lhw.atk, (*sd)->battle_status.hp, (*sd)->status.max_hp, (*sd)->battle_status.max_hp );
if ( *type == ATK_BASEON_HP_RATE ) {
if ( (*sd)->state.lr_flag != 2 ) {
int bonus = (*sd)->base_status.lhw.atk + ( 99 - ( (*sd)->battle_status.hp *100 / ((*sd)->battle_status.max_hp +1) ) ) * *val;
(*sd)->base_status.lhw.atk = cap_value(bonus, 0, USHRT_MAX);
}
// ShowDebug( "%d\n", (*sd)->base_status.lhw.atk );
hookStop();
}
return 0;
}

void pc_damage_post( struct map_session_data *sd, struct block_list *src, unsigned int hp, unsigned int sp ) {
if ( sd == NULL )
return;
status_calc_pc(sd, SCO_FORCE);
return;
}

void pc_heal_post( struct map_session_data *sd, unsigned int hp, unsigned int sp, int type ) {
if ( sd == NULL )
return;
status_calc_pc(sd, SCO_FORCE);
return;
}

HPExport void plugin_init (void) {
ATK_BASEON_HP_RATE = map->get_new_bonus_id();
script->set_constant( "bAtkBaseonHPRate", ATK_BASEON_HP_RATE, false, false );
addHookPre( pc, bonus, pc_bonus_pre );
addHookPost( pc, damage, pc_damage_post );
addHookPost( pc, heal, pc_heal_post );
}

EDIT: some minor trick to calculate division by 1 instead of 0, kinda hacky

Do you think this is possible?
no
not recommend

EDIT2: but if you want the bonus only at certain HP threshold like only activate below 15% hp, then it might be more ... practical

 
Last edited by a moderator:
The server I GM for uses empty autobonuses to refresh condition checks. 100% autobonus when attacking or being hit works rather well for red-health builds. However! There is a limit of 10 autobonuses one player can have at a time, so unless you can increase it and recompile, I suggest to use it sparingly and on slots where card granted autobonuses already happen. Also, I am not really sure how server resource heavy these are. ;o

autobonus "{  }",1000,1000,BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL,"{  }";
autobonus2 "{  }",1000,1000,BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL,"{  }";
if(Hp < MaxHp/4) {
    bonus bAtkRate,3;
    bonus bMatkRate,3;
}

 
atk.jpg


can be done easily enough

just by switching 

in status.c 

ctrl + f , find SC_AUTOBESERK

look for these 

st->max_hp>>2


change them to this

st->max_hp*0.75


now autobeserk applies at 75% hp

ok to remove the toggle, im not sure off the top of my head but i dont see why not

so using this you need to:

make a new SC_CARDEFFECT

just copy impositio manus for straight ATK

or keep is like provoke but without the defense reduction

now you just gotta figure out how to make it a passive instead of toggled 

 
no.1, my 1st impression is run status_calc_pc everytime player receive hits or healing, which will be server resources heavy
OnPCStatCalcEvent already deem very resource heavy, and you want to make this heavier LOL

no.2, even I want to write this for fun, also impossible
when player login, sd->battle_status.max_hp is 0, and can cause server crash
when I changed to sd->status.max_hp, that is the player's base hp, if the player have bMaxHP bonus then it will calculate wrongly

#include "common/hercules.h"
#include "map/pc.h"
#include "common/utils.h"
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"

HPExport struct hplugin_info pinfo = {
"bAtkBaseonHPRate",
SERVER_TYPE_MAP,
"0.1",
HPM_VERSION,
};

struct player_data {
int atk_baseon_hprate;
};

int ATK_BASEON_HP_RATE = 0;

int pc_bonus_pre( struct map_session_data **sd, int *type, int *val ) {
if ( *sd == NULL )
return 0;
ShowDebug( "%d %d %d %d\n", (*sd)->base_status.lhw.atk, (*sd)->battle_status.hp, (*sd)->status.max_hp, (*sd)->battle_status.max_hp );
if ( *type == ATK_BASEON_HP_RATE ) {
if ( (*sd)->state.lr_flag != 2 ) {
int bonus = (*sd)->base_status.lhw.atk + ( (*sd)->battle_status.hp *100 / (*sd)->status.max_hp ) * *val;
(*sd)->base_status.lhw.atk = cap_value(bonus, 0, USHRT_MAX);
}
ShowDebug( "%d\n", (*sd)->base_status.lhw.atk );
hookStop();
}
return 0;
}

void pc_damage_post( struct map_session_data *sd, struct block_list *src, unsigned int hp, unsigned int sp ) {
if ( sd == NULL )
return;
status_calc_pc(sd, SCO_FORCE);
return;
}

void pc_heal_post( struct map_session_data *sd, unsigned int hp, unsigned int sp, int type ) {
if ( sd == NULL )
return;
status_calc_pc(sd, SCO_FORCE);
return;
}

HPExport void plugin_init (void) {
ATK_BASEON_HP_RATE = map->get_new_bonus_id();
script->set_constant( "bAtkBaseonHPRate", ATK_BASEON_HP_RATE, false, false );
addHookPre( pc, bonus, pc_bonus_pre );
addHookPost( pc, damage, pc_damage_post );
addHookPost( pc, heal, pc_heal_post );
}



no
Oh I see.
Thanks for the explanation Annie
It's really sad. It would be a very interesting mechanic.

The server I GM for uses empty autobonuses to refresh condition checks. 100% autobonus when attacking or being hit works rather well for red-health builds. However! There is a limit of 10 autobonuses one player can have at a time, so unless you can increase it and recompile, I suggest to use it sparingly and on slots where card granted autobonuses already happen. Also, I am not really sure how server resource heavy these are. ;o

autobonus "{  }",1000,1000,BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL,"{  }";
autobonus2 "{  }",1000,1000,BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL,"{  }";
if(Hp < MaxHp/4) {
    bonus bAtkRate,3;
    bonus bMatkRate,3;
}
interesting o/

atk.jpg


can be done easily enough

just by switching 

in status.c 

ctrl + f , find SC_AUTOBESERK

look for these 

st->max_hp>>2


change them to this

st->max_hp*0.75


now autobeserk applies at 75% hp

ok to remove the toggle, im not sure off the top of my head but i dont see why not

so using this you need to:

make a new SC_CARDEFFECT

just copy impositio manus for straight ATK

or keep is like provoke but without the defense reduction

now you just gotta figure out how to make it a passive instead of toggled 
um very interesting I will follow your tips and try to make a letter with this passive effect
LOL

 
The server I GM for uses empty autobonuses to refresh condition checks. 100% autobonus when attacking or being hit works rather well for red-health builds. However! There is a limit of 10 autobonuses one player can have at a time, so unless you can increase it and recompile, I suggest to use it sparingly and on slots where card granted autobonuses already happen. Also, I am not really sure how server resource heavy these are. ;o

autobonus "{  }",1000,1000,BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL,"{  }";
autobonus2 "{  }",1000,1000,BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL,"{  }";
if(Hp < MaxHp/4) {
    bonus bAtkRate,3;
    bonus bMatkRate,3;
}
test with

{
Id: 5083
AegisName: "Red_Tailed_Ribbon"
Name: "Red Ribbon"
Type: "IT_ARMOR"
Buy: 20
Weight: 200
Def: 2
Loc: "EQP_HEAD_TOP"
EquipLv: 45
ViewSprite: 167
Script: <" bonus bMdef,10; autobonus2 "{ if(Hp < MaxHp/4) bonus bAtk, 10000; }", 1000, 5000, BF_WEAPON|BF_MAGIC|BF_MISC|BF_NORMAL|BF_SKILL; ">
},


it works, but the bAtk bonus only give you for the <duration> in seconds ...
if the duration too high, like 1 day, lol ... if the player already recover the hp, the bAtk will still be there



ok 1 more try
https://github.com/AnnieRuru/Release/blob/master/plugins/bAtkWhenLowHP.c
this one can be use on live server

EDITING --- found a bug OK done

 
Last edited by a moderator:
Oh I see.
Thanks for the explanation Annie
It's really sad. It would be a very interesting mechanic.

interesting o/

um very interesting I will follow your tips and try to make a letter with this passive effect
LOL
its not really difficult and i see what you guys are talking about, you can pm me if you want

im not sure what the max skill db is though, but im sure theres a easy way to use this skill and use a bunch of different SC_'s for different cards

good luck sir 

 
Last edited by a moderator:
Back
Top