Ok most of it works now, with a couple of problems still, but minor.
make a trigger with OnEnter Script:
(I don’t know how to post code on these forums and yes, I know my code is ugly :-))
void main()
{
object oEnter = GetEnteringObject();
string cover = GetLocalString(OBJECT_SELF,"cover");
int type = GetLocalInt(OBJECT_SELF,"type");
SetLocalInt(oEnter,"cover_" + cover,TRUE);
SetLocalInt(oEnter,"type_" + cover,type);
SendMessageToPC(oEnter,"you are now in " + cover + " cover");
}
OnExit script:
void main()
{
object oEnter = GetEnteringObject();
string cover = GetLocalString(OBJECT_SELF,"cover");
SetLocalInt(oEnter,"cover_" + cover,FALSE);
SetLocalInt(oEnter,"type_" +cover,0);
SendMessageToPC(oEnter,"You are now outside cover");
}
Put these variables on the trigger:
NAME TYPE VALUE
cover string north (or south, east or west, the direction that is covered.)
type int 4 (AttackDecrease applied to attacker while you are covered.)
A creature that uses this needs the following script “pc_attacked” in OnPhysicalAttacked event:
void main()
{
object oPC = OBJECT_SELF;
object oAttacker = GetLastAttacker();
int cover_north = GetLocalInt(OBJECT_SELF,"cover_north");
int type_north = GetLocalInt(OBJECT_SELF,"type_north");
int cover_south = GetLocalInt(OBJECT_SELF,"cover_south");
int type_south = GetLocalInt(OBJECT_SELF,"type_south");
int cover_west = GetLocalInt(OBJECT_SELF,"cover_west");
int type_west = GetLocalInt(OBJECT_SELF,"type_west");
int cover_east = GetLocalInt(OBJECT_SELF,"cover_east");
int type_east = GetLocalInt(OBJECT_SELF,"type_east");
vector v = GetPosition(oAttacker) - GetPosition(OBJECT_SELF);
if(cover_north == TRUE && v.y > 0.0)
{
effect eDecr = EffectAttackDecrease(type_north);
DelayCommand(4.0,ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eDecr,oAttacker,3.0));
// DEBUG
AssignCommand(oAttacker,SpeakString("My attack decreased!"));
}
if(cover_south == TRUE && v.y < 0.0)
{
effect eDecr = EffectAttackDecrease(type_south);
DelayCommand(4.0,ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eDecr,oAttacker,3.0));
AssignCommand(oPC,SpeakString("cover south fired!"));
}
if(cover_west == TRUE && v.x < 0.0)
{
effect eDecr = EffectAttackDecrease(type_west);
DelayCommand(4.0,ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eDecr,oAttacker,3.0));
AssignCommand(oPC,SpeakString("cover west fired!"));
}
if(cover_east == TRUE && v.x > 0.0)
{
effect eDecr = EffectAttackDecrease(type_east);
DelayCommand(4.0,ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eDecr,oAttacker,3.0));
AssignCommand(oPC,SpeakString("cover east fired!"));
}
}
and finally if you want the pc to use this as well, you need to set “pc_attacked” to run on your PC too.
to test it make a trigger with this onenter script:
void main()
{
object oPC = GetEnteringObject();
int iDoOnce = GetLocalInt(OBJECT_SELF, "DoOnce");
if (iDoOnce == FALSE )
{
AssignCommand(oPC,SpeakString("I'm ready!"));
SetEventScript(oPC,EVENT_SCRIPT_CREATURE_ON_MELEE_ATTACKED,"pc_attacked");
}
SetLocalInt(OBJECT_SELF,"DoOnce",TRUE);
}
Now…problems:
The AttackDecrease doesn’t fire in time for the first attack, and will linger for 1 attack after leaving cover. Removing the delay doesn’t fix this.
Anybody have an idea to fix that?
Still need to make a check that attacker is using a ranged weapon, no cover against melee attacks
and people with many attacks per round will have problems… for my purpose this is fine though.
/Pap