PDA

View Full Version : [REQUEST] Respawn on typing !spawn


soulreaper1o1
12-09-2011, 05:21
Hay, well the title is self explanatory.
I'm looking for a plugin that allows players will respawn if they type !spawn.
An additional option (if possible) restriction on the number of times this command can be used.

Best Regards,
Soul Reaper

Tylerst
12-09-2011, 06:25
Easy to do, but which game?

and how often do you want the restriction limit to reset? map change, round end, etc

soulreaper1o1
12-09-2011, 06:37
Counter strike Source
each round restriction...umm 2 should be enough

Impact123
12-09-2011, 07:38
This should just work fine for you.


#include <sourcemod>
#include <cstrike>
#pragma semicolon 1



#define SPAWNSLIMIT 2
new iPlayerRespawns[MAXPLAYERS+1];



public Plugin:myinfo =
{
name = "Player Respawn",
author = "Impact",
description = "Let players respawn 2 times per round.",
version = "1.0.1",
url = "http://forums.alliedmods.net/showthread.php?p=1616430"
}



public OnPluginStart()
{
RegConsoleCmd("sm_spawn", Command_Spawn);
HookEvent("round_end", OnRoundEnd);
}



public Action:Command_Spawn(client, args)
{
if(client >0 && IsClientConnected(client) && IsClientInGame(client))
{
if(iPlayerRespawns[client] < SPAWNSLIMIT)
{
if(!IsPlayerAlive(client))
{
CS_RespawnPlayer(client);
PrintToChat(client, "You have been respawned");
iPlayerRespawns[client]++;
}
else
{
PrintToChat(client, "You must be dead to respawn yourself");
}
}
else
{
PrintToChat(client, "You have reached the limit of %d respawns this round", SPAWNSLIMIT);
}
}

return Plugin_Handled;
}



public Action:OnRoundEnd(Handle:event, String:name[], bool:dontBroadcast)
{
ResetSpawns();
}



public OnMapEnd()
{
ResetSpawns();
}



ResetSpawns()
{
new len = sizeof(iPlayerRespawns);
for(new i; i<len; i++)
{
iPlayerRespawns[i] = 0;
}
}


Feel free to edit and compile it with the webcompiler (http://www.sourcemod.net/compiler.php)

Yours sincerely
Impact

soulreaper1o1
12-09-2011, 08:44
thank you for taking the time and writing the plugin. It works great

soulreaper1o1
12-20-2011, 06:23
hay, i just noticed i cant use the command through console
can you please add that feature too

Thanks

Impact123
12-20-2011, 06:27
You can:
Chat:

!spawn
/spawn
!sm_spawn
/sm_spawn

Console:
sm_spawn

Oh, i fixed a typo in the eventcallback, post above updated.

Yours sincerely
Impact

soulreaper1o1
12-20-2011, 06:28
oh silly me

Thanks for the quick reply

soulreaper1o1
12-20-2011, 13:46
is it possible to add more/less spawns for specific steam IDs ?
can u add that feature in this ?

PS. sorry for so many edits.

Thanks, i appreciate the help.

Impact123
12-20-2011, 13:52
Sure it is, but for this you mostly use keyvalues or SQL and for now i don't want to use them.
I maybe could do it with adminflags if you want.

Yours sincerely
Impact

soulreaper1o1
12-20-2011, 15:36
adminflags...hmm
i guess that will do the job, i'll just make custom flags for extra spawns

Impact123
12-20-2011, 16:10
Here is the basic writeup, i will look tomorrow how it can be done the most efficient way if i don't forget, for now it has some redundant code.
I will see how i cache who is admin.

#include <sourcemod>
#include <cstrike>
#pragma semicolon 1



#define SPAWNSLIMIT 2
#define ADMINSPAWNSLIMIT 5
new SPAWNFLAG = ADMFLAG_KICK;



new iPlayerRespawns[MAXPLAYERS+1];



public Plugin:myinfo =
{
name = "Player Respawn",
author = "Impact",
description = "Let players respawn 2 times per round.",
version = "1.0.2",
url = "http://forums.alliedmods.net/showthread.php?p=1616430"
}



public OnPluginStart()
{
RegConsoleCmd("sm_spawn", Command_Spawn);
HookEvent("round_end", OnRoundEnd);
}



public Action:Command_Spawn(client, args)
{
if(client >0 && IsClientConnected(client) && IsClientInGame(client))
{
if(iPlayerRespawns[client] < SPAWNSLIMIT || GetUserFlagBits(client) & SPAWNFLAG == SPAWNFLAG && iPlayerRespawns[client] < ADMINSPAWNSLIMIT)
{
if(!IsPlayerAlive(client))
{
CS_RespawnPlayer(client);
PrintToChat(client, "You have been respawned");
iPlayerRespawns[client]++;
}
else
{
PrintToChat(client, "You must be dead to respawn yourself");
}
}
else
{
PrintToChat(client, "You have reached the limit of %d respawns this round", GetUserFlagBits(client) & SPAWNFLAG == SPAWNFLAG ? ADMINSPAWNSLIMIT : SPAWNSLIMIT);
}
}

return Plugin_Handled;
}



public Action:OnRoundEnd(Handle:event, String:name[], bool:dontBroadcast)
{
ResetSpawns();
}



public OnMapEnd()
{
ResetSpawns();
}



ResetSpawns()
{
new len = sizeof(iPlayerRespawns);
for(new i; i<len; i++)
{
iPlayerRespawns[i] = 0;
}
}


Yours sincerely
Impact

TnTSCS
12-20-2011, 17:37
You should look at CheckCommandAccess (http://docs.sourcemod.net/api/index.php?fastload=show&id=497&)

if(iPlayerRespawns[client] < SPAWNSLIMIT || CheckCommandAccess(client, "allow_respawns", ADMFLAG_CUSTOM1) && iPlayerRespawns[client] < ADMINSPAWNSLIMIT)

Then you could set "allow_respawns" (or whatever command you put there) to have whatever admin flag you want, just use admin_overrides.cfg

I think it was Bacardi who turned me to using CheckCommandAccess for stuff like this - that way, it's super easy for the server admin to change/alter the flag you set in your code

Impact123
12-21-2011, 04:47
I thought about that too, but at the end the requester should decide what he like, i only code it the way he like.
I just try to find an efficient way to cache who is admin or not without to make too much unneeded operations.
I looked at the antiflood plugin, which uses the same way to determinate who is admin and who not, and there it is called on OnClientFloodCheck, and that can be a lot, so i don't think that's too much weight in the operation.

Yours sincerely
Impact