Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.36 KB | None | 0 0
  1.  
  2. // -- Spell Tracking v1.3 -- //
  3.  
  4. // -- Creslyn: greatwhitepossum@hotmail.com -- //
  5.  
  6. /******************************************************************************/
  7. /***************************** Constants **********************************/
  8. /******************************************************************************/
  9.  
  10. // Determine what method of storing tracking variables to use
  11. // * Set to 0 and it will use the module to store variables
  12. // * Set to 1 and it will use the item players possess with
  13. // the tag specified in the constant ST_VAR_STORAGE_ITEM
  14. // * Set to 2 and it will use the creature hide item
  15. const int ST_VAR_STORAGE = 2;
  16.  
  17. // If you want to use an item (non-drop is essential) such as
  18. // an emote ball/rod in players inventory to store the variables
  19. // you must specify the item's tag here
  20. const string ST_VAR_STORAGE_ITEM = "";
  21.  
  22. /******************************************************************************/
  23. /*********************** ****************************/
  24. /*********************** Function Declarations ****************************/
  25. /*********************** ****************************/
  26. /******************************************************************************/
  27.  
  28. // Track the number of times a spell has been cast since
  29. // the last time oCaster rested, only for player characters.
  30. void st_SpellCast(int nSpellId, object oCaster = OBJECT_SELF);
  31.  
  32. // Reset all tracking variables and note which spells
  33. // have been memorised for future use in determining
  34. // if a spell has been legitimately memorised for player
  35. // characters.
  36. // * Only call this in the OnPlayerRest (REST_EVENTTYPE_REST_FINISHED)
  37. // event script.
  38. void st_OnRestCompleted(object oCaster = OBJECT_SELF);
  39.  
  40. // Reset spell memorisations to the appropriate number
  41. // and wipe illegal spell memorisations on player entry.
  42. void st_SpellCheck(object oCaster = OBJECT_SELF);
  43.  
  44. // Check that oPlayer has a hide item equipped (for storing variables on)
  45. // and if not, create one and equip it on oPlayer. Also removes polymorph,
  46. // wildshape and shapechange effects on the player if such exist so as not
  47. // to allow those spell/abilities hides to interfere with spell tracking
  48. // (and to prevent an exploit with sorcerer/bard spells).
  49. // * Only call this in the OnClientEnter event script.
  50. // * Note: If not using creature hides to store tracking variables, you
  51. // can leave this function out of your OnClientEnter event script.
  52. void st_HideCheck(object oPlayer);
  53.  
  54. // Remove any temporary hit points from a polymorph/shapechange that
  55. // exceed oPlayer's maximum hit points. Only used in conjuction with
  56. // using the creature hide item to store variables
  57. void st_TempHPCheck(object oPlayer);
  58.  
  59. // Method of decrementing spells used to avoid loop errors
  60. void st_StripLoopDecrement(object oCaster, int nID, float fDelay = 0.1);
  61.  
  62. // Method of decrementing spells used to avoid loop errors
  63. void st_LegalLoopDecrement(object oCaster, int nID, int nCasts, float fDelay = 0.1);
  64.  
  65. // Wrapper function for getting tracking variables
  66. int st_GetInt(object oPlayer, string sVariable);
  67.  
  68. // Wrapper function for setting tracking variables
  69. void st_SetInt(object oPlayer, string sVariable, int nValue);
  70.  
  71. /******************************************************************************/
  72. /********************** ***************************/
  73. /********************** Function Implementation ***************************/
  74. /********************** ***************************/
  75. /******************************************************************************/
  76.  
  77. void st_SpellCast(int nSpellId, object oCaster = OBJECT_SELF)
  78. {
  79. if(GetIsPC(oCaster) && !GetIsDM(oCaster) && !GetIsDMPossessed(oCaster))
  80. {
  81. // Check that the spell was not cast from an item (stave, scroll, wand etc)
  82. if(!GetIsObjectValid(GetSpellCastItem()))
  83. {
  84. // Increment the variable holding the number of time this spell has been cast
  85. string sVar = "st_NumSpellCast_"+IntToString(nSpellId)+"_";
  86. int nCasts = st_GetInt(oCaster,sVar) + 1;
  87. st_SetInt(oCaster,sVar,nCasts);
  88. }
  89. }
  90. }
  91.  
  92. /******************************************************************************/
  93.  
  94. void st_OnRestCompleted(object oCaster = OBJECT_SELF)
  95. {
  96. int nID, nSpell;
  97. for(nID=0;nID<641;nID++)
  98. {
  99. if((nID >= 0 && nID <= 194) || 324 || (nID >= 340 && nID <= 356)
  100. || (nID >= 363 && nID <= 377) || (nID >= 387 && nID <= 396)
  101. || (nID >= 414 && nID <= 427) || (nID >= 429 && nID <= 463)
  102. || nID == 485 || nID == 486 || (nID >= 512 && nID <= 549)
  103. || nID == 569 || (nID >= 636 && nID <= 640))
  104. {
  105. // Set a spell as legally memorised
  106. nSpell = GetHasSpell(nID,oCaster);
  107. st_SetInt(oCaster,"st_SpellCastLegal_"+IntToString(nID)+"_",nSpell);
  108. }
  109. // Reset the variable tracking the number of times this spell was cast to 0
  110. st_SetInt(oCaster,"st_NumSpellCast_"+IntToString(nID)+"_",0);
  111. }
  112. }
  113.  
  114. /******************************************************************************/
  115.  
  116. void st_SpellCheck(object oCaster)
  117. {
  118. if(GetIsPC(oCaster) && !GetIsDM(oCaster) && !GetIsDMPossessed(oCaster))
  119. {
  120. int nID, nSpell, nLegal, nCasts;
  121. for(nID=0;nID<641;nID++)
  122. {
  123. if((nID >= 0 && nID <= 194) || 324 || (nID >= 340 && nID <= 356)
  124. || (nID >= 363 && nID <= 377) || (nID >= 387 && nID <= 396)
  125. || (nID >= 414 && nID <= 427) || (nID >= 429 && nID <= 463)
  126. || nID == 485 || nID == 486 || (nID >= 512 && nID <= 549)
  127. || nID == 569 || (nID >= 636 && nID <= 640))
  128. {
  129. nSpell = GetHasSpell(nID,oCaster);
  130. if(nSpell)
  131. {
  132. // Check if a spell was memorised legally (with resting)
  133. nLegal = st_GetInt(oCaster,"st_SpellCastLegal_"+IntToString(nID)+"_");
  134. if(nLegal)
  135. {
  136. // Remove any castings of the spell already used
  137. nCasts = st_GetInt(oCaster,"st_NumSpellCast_"+IntToString(nID)+"_");
  138. st_LegalLoopDecrement(oCaster, nID, nCasts);
  139. }
  140. // Spell was illegally memorised (not gained by resting)
  141. else
  142. {
  143. // Remove all castings of that spell
  144. st_StripLoopDecrement(oCaster, nID);
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151.  
  152. /******************************************************************************/
  153.  
  154. void st_HideCheck(object oPlayer)
  155. {
  156. // If not using hide items for variable storage, end the function here.
  157. if(ST_VAR_STORAGE != 2)
  158. return;
  159.  
  160. if(GetIsPC(oPlayer) && !GetIsDM(oPlayer) && !GetIsDMPossessed(oPlayer))
  161. {
  162. // If oPlayer does not have a creature hide equipped (ie. is a new
  163. // player) create one and equip it on oPlayer
  164. object oSkin = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPlayer);
  165. if(!GetIsObjectValid(oSkin))
  166. AssignCommand(oPlayer,ActionEquipItem(CreateItemOnObject("x2_it_emptyskin",oPlayer),INVENTORY_SLOT_CARMOUR));
  167. // Remove Polymorph/Shapechange/Wildshape effects as they interfere with
  168. // the removal of cast spells.
  169. effect ePoly = GetFirstEffect(oPlayer);
  170. int nType, bValid;
  171. while(GetIsEffectValid(ePoly))
  172. {
  173. nType = GetEffectType(ePoly);
  174. if(nType == EFFECT_TYPE_POLYMORPH || nType == EFFECT_TYPE_TEMPORARY_HITPOINTS)
  175. {
  176. RemoveEffect(oPlayer,ePoly);
  177. bValid = TRUE;
  178. }
  179. ePoly = GetNextEffect(oPlayer);
  180. }
  181. // Remove temporary hit points from a polymorph/shapechange that
  182. // exceed oPlayer's maximum hit points.
  183. if(bValid)
  184. DelayCommand(0.8,st_TempHPCheck(oPlayer));
  185. }
  186. }
  187.  
  188. /******************************************************************************/
  189.  
  190. void st_TempHPCheck(object oPlayer)
  191. {
  192. // Check if oPlayer's current hit points exceed his maximum hit points.
  193. int nHP = GetCurrentHitPoints(oPlayer);
  194. int nMaxHP = GetMaxHitPoints(oPlayer);
  195. if(nHP > nMaxHP)
  196. {
  197. // If so, remove the extra hit points over oPlayer's maximum hit points.
  198. nHP -= nMaxHP;
  199. ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(nHP),oPlayer);
  200. }
  201. }
  202.  
  203. /******************************************************************************/
  204.  
  205. void st_StripLoopDecrement(object oCaster, int nID, float fDelay = 0.1)
  206. {
  207. if(GetHasSpell(nID, oCaster))
  208. {
  209. DecrementRemainingSpellUses(oCaster, nID);
  210. DelayCommand(fDelay, st_StripLoopDecrement(oCaster, nID, fDelay));
  211. }
  212. }
  213.  
  214. /******************************************************************************/
  215.  
  216. void st_LegalLoopDecrement(object oCaster, int nID, int nCasts, float fDelay = 0.1)
  217. {
  218. if(GetHasSpell(nID, oCaster) && nCasts)
  219. {
  220. DecrementRemainingSpellUses(oCaster, nID);
  221. DelayCommand(fDelay, st_LegalLoopDecrement(oCaster, nID, --nCasts, fDelay));
  222. }
  223. }
  224.  
  225. /******************************************************************************/
  226.  
  227. int st_GetInt(object oPlayer, string sVariable)
  228. {
  229. object oHolder;
  230. int nReturn;
  231. switch(ST_VAR_STORAGE)
  232. {
  233. case 0: oHolder = GetModule(); break;
  234. case 1: oHolder = GetItemPossessedBy(oPlayer, ST_VAR_STORAGE_ITEM); break;
  235. case 2: oHolder = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPlayer); break;
  236. default: break;
  237. }
  238. if(GetIsObjectValid(oHolder))
  239. {
  240. string sVar = sVariable + GetName(oPlayer) + GetPCPlayerName(oPlayer);
  241. nReturn = GetLocalInt(oHolder, sVar);
  242. }
  243. return nReturn;
  244. }
  245.  
  246. /******************************************************************************/
  247.  
  248. void st_SetInt(object oPlayer, string sVariable, int nValue)
  249. {
  250. object oHolder;
  251. switch(ST_VAR_STORAGE)
  252. {
  253. case 0: oHolder = GetModule(); break;
  254. case 1: oHolder = GetItemPossessedBy(oPlayer, ST_VAR_STORAGE_ITEM); break;
  255. case 2: oHolder = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPlayer); break;
  256. default: break;
  257. }
  258. if(GetIsObjectValid(oHolder))
  259. {
  260. string sVar = sVariable + GetName(oPlayer) + GetPCPlayerName(oPlayer);
  261. SetLocalInt(oHolder, sVar, nValue);
  262. }
  263. }
  264.  
  265. void set_hide_props(object oPC)
  266. {
  267. //Make sure the hide is valid before we set prop strings on it.
  268. object oHide = GetItemInSlot(INVENTORY_SLOT_CARMOUR, oPC);
  269. if(GetIsObjectValid(oHide))
  270. {
  271. SetLocalString(oHide, "PW-pname", GetName(oPC));
  272. // SetLocalString(oHide, "PW-pacct", GetPCPlayerName(oPC));
  273. SetLocalString(oHide, "PW-ckey", GetPCPublicCDKey(oPC)); //anything else we might need later
  274. }
  275. }
  276.  
  277. /******************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement