Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function AttackWarning() {}
- AttackWarning.prototype.Schema =
- "<a:component type='system'/><empty/>";
- AttackWarning.prototype.Init = function()
- {
- this.suppressionRange = 150;
- this.suppressionSeconds = 40;
- // Other attacks within this time and distance will not trigger the warning
- this.suppressionTransferRange = 50;
- // Any attacks within this range will replace the previous attack suppression
- this.suppressedList = [];
- };
- AttackWarning.prototype.NotifyAttack = function(attacker, target)
- {
- var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player);
- var cmpOwnership = Engine.QueryInterface(target, IID_Ownership);
- if (cmpPlayer.GetPlayerID() != cmpOwnership.GetOwner()) {
- // Only warn about people attacking me
- return;
- }
- var cmpPosition = Engine.QueryInterface(target, IID_Position);
- if (!cmpPosition || !cmpPosition.IsInWorld())
- return;
- var entityPosition = cmpPosition.GetPosition();
- var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
- var currentTime = cmpTimer.GetTime();
- for (var i = 0; i < this.suppressedList.length; i++)
- {
- var event = this.suppressedList[i];
- // Check if the current event has timed out
- if (currentTime - event.time > 1000 * this.suppressionSeconds)
- {
- this.suppressedList.splice(i, 1);
- i--;
- continue;
- }
- // If this is within suppression distance of the event then check if the event should be updated
- // and then return
- var dist = Distance(event.position, entityPosition);
- if (dist < this.suppressionRange)
- {
- if (dist < this.suppressionTransferRange)
- {
- event.position = {x: entityPosition.x, z: entityPosition.z};
- event.time = currentTime;
- }
- return;
- }
- }
- warn("Player " + cmpPlayer.GetPlayerID() + ": You are under attack!");
- this.suppressedList.push({position:{x: entityPosition.x, z: entityPosition.z}, time: currentTime});
- };
- Engine.RegisterComponentType(IID_AttackWarning, "AttackWarning", AttackWarning);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement