Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //oCaster makes a dispel check vs oTargets spells
- void DoDispelCheck(object oCaster, object oTarget, int nCasterLevel, int nMaxSpells);
- //Used to determine the casterlevel nSpell should have when cast by oTarget
- int GetCasterLevelForSpell(object oTarget, int nSpell);
- int GetCasterLevelForSpell(object oTarget, int nSpell){
- return GetCasterLevel(oTarget);
- }
- void DoFeedback(object oCaster, object oTarget, int nRoll, int nCL, int nVs, int nSpell){
- if(!GetIsPC(oCaster) && !GetIsPC(oTarget)){
- return;
- }
- string sSpellName = GetStringByStrRef(StringToInt(Get2DAString("spells", "name", nSpell)));
- string sMessage = "<color=aqua>["+sSpellName+"]</color><color=white> D20 "+IntToString(nRoll)+" + " +IntToString(nCL) + " = "+IntToString(nRoll+nCL)+" vs: " + IntToString(nVs)+ "</color> ";
- if(nRoll + nCL > nVs){
- sMessage += "<color=green>Dispelled</color>";
- }
- else{
- sMessage += "<color=red>Not Dispelled</color>";
- }
- if(GetIsPC(oCaster))
- SendMessageToPC(oCaster, sMessage);
- if(GetIsPC(oTarget) && oCaster != oTarget)
- SendMessageToPC(oTarget, sMessage);
- }
- int Contains(object oObj, int nCnt, int nSpell, object oOwn){
- int n;
- for(n=0;n<nCnt;n++){
- if(GetLocalInt(oObj, "disp_spell_"+IntToString(n)) == nSpell &&
- GetLocalObject(oObj, "disp_owner_"+IntToString(n)) == oOwn){
- return TRUE;
- }
- }
- return FALSE;
- }
- void DoDispelCheck(object oCaster, object oTarget, int nCasterLevel, int nMaxSpells){
- int nLast=-1;
- object oLast=OBJECT_INVALID;
- int nCnt = 0;
- effect eEffect = GetFirstEffect(oTarget);
- while(GetIsEffectValid(eEffect)){
- if(GetEffectSubType(eEffect) == SUBTYPE_MAGICAL && !Contains(oCaster, nCnt, GetEffectSpellId(eEffect), GetEffectCreator(eEffect)) ){
- nLast = GetEffectSpellId(eEffect);
- oLast = GetEffectCreator(eEffect);
- SetLocalInt(oCaster, "disp_spell_"+IntToString(nCnt), nLast);
- SetLocalObject(oCaster, "disp_owner_"+IntToString(nCnt), oLast);
- nCnt++;
- }
- eEffect = GetNextEffect(oTarget);
- }
- int n, nRoll, nEffectCL;
- int nSuccesses=0;
- for(n=0;n<nCnt;n++){
- nLast = GetLocalInt(oCaster, "disp_spell_"+IntToString(n));
- oLast = GetLocalObject(oCaster, "disp_owner_"+IntToString(n));
- DeleteLocalInt(oCaster, "disp_spell_"+IntToString(n));
- DeleteLocalObject(oCaster, "disp_owner_"+IntToString(n));
- //Only dispel spells as long as we got allowed spells and said spell is a spell, otherwise only do cleanup
- if(nLast > -1 && (nMaxSpells <= 0 || nSuccesses < nMaxSpells)){
- nRoll = d20();
- nEffectCL = GetCasterLevelForSpell(oLast, nLast);
- DoFeedback(oCaster, oTarget, nRoll, nCasterLevel, 11 + nEffectCL, nLast);
- if(nRoll + nCasterLevel > 11 + nEffectCL){
- nSuccesses++;
- eEffect = GetFirstEffect(oTarget);
- while(GetIsEffectValid(eEffect)){
- if(GetEffectSubType(eEffect) == SUBTYPE_MAGICAL && GetEffectSpellId(eEffect) == nLast && GetEffectCreator(eEffect) == oLast){
- RemoveEffect(oTarget, eEffect);
- }
- eEffect = GetNextEffect(oTarget);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement