Author Topic: Spawn Protection Plugin  (Read 5567 times)

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Spawn Protection Plugin
« on: August 02, 2010, 10:46:35 AM »
I coded this and havent tested it but should work

adds 3 seconds of spawn protection, unless pretected fires gun that ends protection
« Last Edit: October 22, 2010, 08:53:57 AM by [Oddity]TeacherCreature »

iceman

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Spawn Protection Plugin
« Reply #1 on: August 05, 2010, 04:28:46 PM »
I could use this on some maps we have on rotation. "weapon_fire" does not exist in TF2 apparently.


Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Spawn Protection Plugin
« Reply #2 on: August 05, 2010, 06:51:51 PM »
it wanst made for tf2 lol, and there are sourcemod protection plugins if u need it for tf2

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Spawn Protection Plugin
« Reply #3 on: August 05, 2010, 08:55:48 PM »
Make it 2 seconds or playerhurt ?
i dont know TF2

Shark_267

  • Newbie
  • *
  • Posts: 41
  • Admin Arsenall.net
    • View Profile
Re: Spawn Protection Plugin
« Reply #4 on: October 22, 2010, 12:14:17 AM »
I coded this and havent tested it but should work

adds 3 seconds of spawn protection, unless pretected fires gun that ends protection
In the new version this Plug-in doesn't work. Update please.

[Oddity]TeacherCreature

  • Sr. Member
  • ****
  • Posts: 467
    • View Profile
Re: Spawn Protection Plugin
« Reply #5 on: October 22, 2010, 08:54:32 AM »
updated

In the future I think the SMX file will still work even if there is an update, either way it should work fine now

Shark_267

  • Newbie
  • *
  • Posts: 41
  • Admin Arsenall.net
    • View Profile
Re: Spawn Protection Plugin
« Reply #6 on: October 23, 2010, 05:21:34 PM »
updated

In the future I think the SMX file will still work even if there is an update, either way it should work fine now
Thanks.

Namolem

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Re: Spawn Protection Plugin
« Reply #7 on: January 27, 2011, 05:37:05 PM »
In one race i needed that function:

Code: [Select]
public APLRes:AskPluginLoad2(Handle:myself,bool:late,String:error[],err_max)
{
CreateNative("W3RemoveSpawnVoodoo",NW3RemoveSpawnVoodoo);
return APLRes_Success;
}
public NW3RemoveSpawnVoodoo(Handle:plugin,numParams)
{
new client=GetNativeCell(1);
if(ValidPlayer(client) && bVoodoo[client])
{
bVoodoo[client]=false;
}
return 0;
}

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #8 on: April 18, 2016, 10:54:44 AM »
Just wondering if this gives protection to those that respawn (orc, mage, warden). If it doesn't, this is exactly what I've been looking for!

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Spawn Protection Plugin
« Reply #9 on: April 19, 2016, 12:44:21 PM »
Just wondering if this gives protection to those that respawn (orc, mage, warden). If it doesn't, this is exactly what I've been looking for!
It doesn't. When the round starts everyone will be invincible for 5 seconds.
#war3source on gamesurge

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #10 on: April 20, 2016, 04:08:22 AM »
Sorry, I'm pretty noob with this stuff, I just checked the code and saw this, wouldn't this mean when players respawn (orc, warden or players revived by mage) they will get 3 seconds of protection?

Code: [Select]
public OnWar3EventSpawn(client)
{
bVoodoo[client]=true;
CreateTimer(3.0,EndVoodoo,client);
}

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Spawn Protection Plugin
« Reply #11 on: April 20, 2016, 07:57:48 AM »
It's per spawn event which includes revivals

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #12 on: April 20, 2016, 09:16:50 AM »
Would there be a way of changing it so that it only happens at the very start of each round, so that revivals and respawns don't get the protection?

Code: [Select]
public OnWar3EventSpawn(client)
{
bVoodoo[client]=true;
CreateTimer(3.0,EndVoodoo,client);
}

public RoundStartEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
for(new i=1;i<=MaxClients;i++)
{
if(ValidPlayer(i,true))
{
bVoodoo[i]=true;
CreateTimer(5.0,EndVoodoo,i);
}
}
}

If I changed 3.0 to 0 and kept 5.0 as it was, would that work?

Ownz

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2437
  • chmod -R 777 *
    • View Profile
    • OwnageClan
Re: Spawn Protection Plugin
« Reply #13 on: April 21, 2016, 09:18:21 AM »
hook roundstart only to do the voodoo ability, and delete OnWar3EventSpawn function all together

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #14 on: April 21, 2016, 10:33:56 AM »
Sorry, I'm sure you have much better things to do than school noobs like myself but if I'm understanding you correctly and I want 5 seconds of rounstart-only spawn protection, should my code look like this?

Code: [Select]
/**
* File: War3Source_SpawnProtect.sp
* Description: Spawn protection.
* Author(s): [Oddity]TeacherCreature
*/

#pragma semicolon 1

#include <sourcemod>
#include "W3SIncs/War3Source_Interface"
#include <sdkhooks>
#include <sdktools>
#include <sdktools_functions>
#include <sdktools_tempents>
#include <sdktools_tempents_stocks>

new bVoodoo[66];

public Plugin:myinfo =
{
name = "War3Source Addon - Spawn Protection",
author = "[Oddity]TeacherCreature",
description = "Godmode temp.",
version = "1.0.0.0",
url = "warcraft-source.net"
}

public OnPluginStart()
{
HookEvent("weapon_fire", WeaponFire);
HookEvent("round_start",RoundStartEvent);
}

public Action:WeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
new userid=GetEventInt(event,"userid");
new index=GetClientOfUserId(userid);
if(index>0 && bVoodoo[index])
{
bVoodoo[index]=false;
}
}

public OnW3TakeDmgAll(victim,attacker,Float:damage)
{
if(IS_PLAYER(victim)&&IS_PLAYER(attacker)&&victim>0&&attacker>0) //block self inflicted damage
{
new vteam=GetClientTeam(victim);
new ateam=GetClientTeam(attacker);
if(vteam!=ateam)
{
if(bVoodoo[victim])
{
War3_DamageModPercent(0.0);
PrintHintText(victim,"Spawn Protection!");
PrintToConsole(attacker,"Enemy has Spawn Protection!");
}
}
}
}

public RoundStartEvent(client)
{
bVoodoo[client]=true;
CreateTimer(5.0,EndVoodoo,client);
}

public RoundStartEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
for(new i=1;i<=MaxClients;i++)
{
if(ValidPlayer(i,true))
{
bVoodoo[i]=true;
CreateTimer(5.0,EndVoodoo,i);
}
}
}

public Action:EndVoodoo(Handle:timer,any:client)
{
if(bVoodoo[client])
{
bVoodoo[client]=false;
}
}


Thanks for all the help so far!  :)

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Spawn Protection Plugin
« Reply #15 on: April 22, 2016, 07:27:31 PM »
That's pretty much it:

Code: [Select]
new SpawnProtection[MAXPLAYERSCUSTOM];

public OnPluginStart()
{
HookEvent("round_start", Event_RoundStart);
}

public Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast)
{
for(new i=1;i<=MaxClients;i++)
{
if(ValidPlayer(i))
{
SpawnProtection[i]=true;
CreateTimer(5.0,EndSpawnProtection,i);
}
}
}

public Action:EndSpawnProtection(Handle:timer,any:client)
{
if(ValidPlayer(client))
{
SpawnProtection[client]=false;
}
}

public OnW3TakeDmgBulletPre(victim,attacker,Float:damage)
{
if(ValidPlayer(victim) && ValidPlayer(attacker) && GetClientTeam(attacker)!=GetClientTeam(victim))
{
if(SpawnProtection[victim])
{
War3_DamageModPercent(0.0);
PrintToChat(victim,"Spawn Protection!");
PrintToChat(attacker,"Enemy has Spawn Protection!");
}
}
}

You had the OnWeaponFire event hooked to disable spawn protection - that would remove the protection for one player early if they fired their weapon at all...  Assuming you didn't want that included, otherwise you can re-add it back in.

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #16 on: April 24, 2016, 11:24:03 AM »
Works beautifully, thanks abgar! I've attatched my current version of the plugin. Spawn Protection is 7 seconds and I changed the messages slightly. Added TeacherCreature and yourself as author of course, thanks again for the help!
Now if I can figure out how to create a convar for the plugin (enabled/disabled) I think it'll be 100% finished, not the biggest problem though haha

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Spawn Protection Plugin
« Reply #17 on: April 24, 2016, 09:18:14 PM »
Just make these small changes, and leave the rest - that'll set the convar to enable / disable spawn protection.
Code: [Select]
new SpawnProtection[MAXPLAYERSCUSTOM];
new Handle:g_SpawnProtect;

public OnPluginStart()
{
HookEvent("round_start", Event_RoundStart);
g_SpawnProtect = CreateConVar("sm_spawnprotect","1","determines if spawn protection will be activated",FCVAR_REPLICATED);
}

public Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast)
{
if (GetConVarInt(g_SpawnProtect)==1)
{
for(new i=1;i<=MaxClients;i++)
{
if(ValidPlayer(i))
{
SpawnProtection[i]=true;
CreateTimer(7.0,EndSpawnProtection,i);
}
}
}
}
« Last Edit: April 25, 2016, 07:04:19 AM by abgar »

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #18 on: April 25, 2016, 06:22:27 AM »
You're too kind, abgar! Thanks again :)

Edit: Uploaded the updated version.
« Last Edit: April 25, 2016, 06:26:08 AM by mart3h »

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #19 on: April 30, 2016, 11:19:15 AM »
I just noticed that it's not actually working at the moment. sm_rcon sm_spawnprotect tells me that it's set to 1, but it's definitely not working. Is there something in the code I may have broken that you can see?

It's working now, I had to remove the plugin info, for some reason that's what was stopping it from working.
« Last Edit: May 02, 2016, 01:35:52 AM by mart3h »

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Spawn Protection Plugin
« Reply #20 on: May 02, 2016, 10:43:31 PM »
Well that's bizarre that the plugin info would be stopping it from working, unless there was a random extra quotation mark etc etc.
Glad it's working though :)

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #21 on: May 05, 2016, 09:32:34 AM »
I've just noticed that sometimes spawn protect, even tho it's set to 0, will be active for a player and will not end.
Even checked console: "sm_spawnprotect" = "0" ( def. "1" ) replicated                                  - determines if spawn protection will be activated
It's happened to others but just happened to myself and rejoining/killing myself doesn't fix it, only a server restart.
Any idea as to why this would be happening?

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Spawn Protection Plugin
« Reply #22 on: May 05, 2016, 10:16:17 AM »
Line 28 is missing array slot.

I translated to transitional syntax and fixed the problem. See attachment  ;)

#war3source on gamesurge

mart3h

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • evo.S//
Re: Spawn Protection Plugin
« Reply #23 on: May 05, 2016, 11:06:04 AM »
Too lovely, I really appreciate the help!