this is a simple method.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "akcaliberg"
#define TASKID 1119
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Spawn,"player","HamPlayerSpawnPost",1)
register_event("DeathMsg","eDeath","a")
}
public HamPlayerSpawnPost(id) {
set_user_godmode(id, 1)
set_task(5.0,"RemoveGodmode",id+TASKID)
}
public eDeath() {
new victim = read_data(2)
set_user_godmode(victim,0)
if(task_exists(victim+TASKID)) remove_task(victim+TASKID)
}
public RemoveGodmode(id) {
id -= TASKID;
set_user_godmode(id,0)
}
But I think that is not recommended too.
Here is another method.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "akcaliberg"
#define TASKID 1119
#define PROTECTION_TIME 5
new LastTimeSpawned[33];
new iMaxPlayers;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Spawn,"player","HamPlayerSpawn_Post",1)
RegisterHam(Ham_TakeDamage,"player","HamTakeDamage_Pre",0)
iMaxPlayers = get_maxplayers()
}
public HamPlayerSpawn_Post(id) {
LastTimeSpawned[id] = get_systime();
}
public HamTakeDamage_Pre( victim, inflictor, attacker, Float:damage, type) {
if( 1 <= victim <= iMaxPlayers && (get_systime() - LastTimeSpawned[victim]) <= PROTECTION_TIME ) {
return HAM_SUPERCEDE
}
return HAM_IGNORED
}
It's not still the best way. I gave that methods to show you there are better ways to make a spawn protection. These can be inspiration for the beginners.
If you search you can find the advanced ones.