I tried your code ffbj. It works, though the PvP item restriction has a few nuances that make it more complex than it should be. This is with the heartbeat SetPCDislike, and Lightfoot8's GetNearestCreature:
problem 1:PvP begins
Opponent turns red after 6 seconds (heartbeat)
Player sets opponent to "like" in the player list
Player drinks potion in between heartbeats, healed
Opponent turns red after 6 seconds
repeat
problem 2:A hostile player is nearby
Potions and scrolls are disabled when attacking a monster
problem 3:Drinking potion(s) right before combat (heartbeat creates a delay)
Casting scrolls(s) at another PC right before combat
problem 4:Someone turns everyone in the server hostile
When in the same area as other players, all of the other players now have potions/scrolls disabled
I might just give up and disable potions/scrolls during all combat, using GetIsInCombat.
I tried my original idea of using GetIsPC, GetLastAttacker etc. for detecting PvP, and it's even buggier
spell hook code:#include "x2_inc_switches"
const int FIRST = 1;
void main()
{
object oSpellTarget = GetSpellTargetObject();
int oSpellItem = GetBaseItemType(GetSpellCastItem());
if (GetIsInCombat() &&
GetNearestCreature
(
CREATURE_TYPE_PLAYER_CHAR,
PLAYER_CHAR_IS_PC,
OBJECT_SELF,
FIRST,
CREATURE_TYPE_REPUTATION,
REPUTATION_TYPE_ENEMY
) != OBJECT_INVALID
)
{
//is your spell a potion or scroll?
if (oSpellItem == BASE_ITEM_POTIONS ||
oSpellItem == BASE_ITEM_ENCHANTED_POTION ||
oSpellItem == BASE_ITEM_SPELLSCROLL ||
oSpellItem == BASE_ITEM_ENCHANTED_SCROLL ||
oSpellItem == BASE_ITEM_ENCHANTED_WAND
)
{
SetModuleOverrideSpellScriptFinished ();
SendMessageToPC(OBJECT_SELF, "Potions and scrolls during PvP combat have been disabled");
}
}
}
heartbeat code:void main()
{
// Loop through PCs.
object oPC = GetFirstPC();
while (oPC != OBJECT_INVALID)
{
// See if oPC's last attack target is a PC.
object oTarget = GetAttackTarget(oPC);
object oAttacker = GetLastAttacker(oTarget);
if (GetIsPC(oAttacker) && GetIsPC(oTarget))
{
SetPCDislike(oAttacker, oTarget);
}
oPC = GetNextPC();
}
}
Alternate spell hook PvP detection without using GetNearestCreature:see comments for bugs
#include "x2_inc_switches"
void main()
{
object oSpellTarget = GetSpellTargetObject();
object oAttackTarget = GetAttackTarget();
object oLastAttacker = GetLastAttacker();
int oSpellItem = GetBaseItemType(GetSpellCastItem());
if (GetIsInCombat() &&
oSpellItem == BASE_ITEM_POTIONS ||
oSpellItem == BASE_ITEM_ENCHANTED_POTION ||
oSpellItem == BASE_ITEM_SPELLSCROLL ||
oSpellItem == BASE_ITEM_ENCHANTED_SCROLL ||
oSpellItem == BASE_ITEM_ENCHANTED_WAND
)
{
// potions refuse to work when using this, permanently disabled even outside of PvP
// also, oLastAttacker will disable scrolls/potions indefinitely until PC is attacked by a monster
if (GetIsPC(oSpellTarget) || GetIsPC(oAttackTarget) || GetIsPC(oLastAttacker))
{
SetModuleOverrideSpellScriptFinished ();
SendMessageToPC(OBJECT_SELF, "Potions and scrolls during PvP combat have been disabled");
}
}
}
In order to test this, I have to start a server and join with two clients, and restarting/rejoining for every test. It's very tedious compared to just hitting F9
Thanks for your help so far
Modifié par r8_, 28 août 2012 - 03:43 .