caldas
20th August 2020, 03:57
Guys, can anyone help me with anything?
I want to do a headshot counter, to avoid aimbots on the server. As soon as the counter is greater than an X value, the server kicks the player. The value always zeroes when the round ends (sd) or when he dies (in the case of a dm)
I don't know where to capture the death toll and validate whether it was a headshot or not.
maxdamage99
20th August 2020, 06:23
example on default gametype scripts.
new lines marked like suffix "//+new"
sd.gsc
Callback_PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration)
{
self endon("spawned");
self notify("killed_player");
if(self.sessionteam == "spectator")
return;
// If the player was killed by a head shot, let players know it was a head shot kill
if(sHitLoc == "head" && sMeansOfDeath != "MOD_MELEE")
sMeansOfDeath = "MOD_HEAD_SHOT";
if (!isDefined(attacker.Cheads)) //+new
attacker.Cheads = 0; //+new
self.Cheads = 0; //+new
// send out an obituary message to all clients about the kill
obituary(self, attacker, sWeapon, sMeansOfDeath);
self maps\mp\gametypes\_weapons::dropWeapon();
self maps\mp\gametypes\_weapons::dropOffhand();
self.sessionstate = "dead";
self.statusicon = "hud_status_dead";
if(!isdefined(self.switching_teams))
{
self.pers["deaths"]++;
self.deaths = self.pers["deaths"];
}
lpselfnum = self getEntityNumber();
lpselfguid = self getGuid();
lpselfname = self.name;
lpselfteam = self.pers["team"];
lpattackerteam = "";
attackerNum = -1;
if(isPlayer(attacker))
{
if(attacker == self) // killed himself
{
doKillcam = false;
// switching teams
if(isdefined(self.switching_teams))
{
if((self.leaving_team == "allies" && self.joining_team == "axis") || (self.leaving_team == "axis" && self.joining_team == "allies"))
{
players = maps\mp\gametypes\_teams::CountPlayers();
players[self.leaving_team]--;
players[self.joining_team]++;
if((players[self.joining_team] - players[self.leaving_team]) > 1)
{
attacker.pers["score"]--;
attacker.score = attacker.pers["score"];
}
}
}
if(isdefined(attacker.friendlydamage))
attacker iprintln(&"MP_FRIENDLY_FIRE_WILL_NOT");
}
else
{
attackerNum = attacker getEntityNumber();
doKillcam = true;
if(self.pers["team"] == attacker.pers["team"]) // killed by a friendly
{
attacker.pers["score"]--;
attacker.score = attacker.pers["score"];
}
else
{
attacker.pers["score"]++;
attacker.score = attacker.pers["score"];
if (sMeansOfDeath == "MOD_HEAD_SHOT") //+new
attacker.Cheads++; //+new
attacker thread checkHeadShotNumber(); //+new
}
}
lpattacknum = attacker getEntityNumber();
lpattackguid = attacker getGuid();
lpattackname = attacker.name;
lpattackerteam = attacker.pers["team"];
self notify("killed_player", attacker);
}
else // If you weren't killed by a player, you were in the wrong place at the wrong time
{
doKillcam = false;
self.pers["score"]--;
self.score = self.pers["score"];
lpattacknum = -1;
lpattackguid = "";
lpattackname = "";
lpattackerteam = "world";
self notify("killed_player", self);
}
logPrint("K;" + lpselfguid + ";" + lpselfnum + ";" + lpselfteam + ";" + lpselfname + ";" + lpattackguid + ";" + lpattacknum + ";" + lpattackerteam + ";" + lpattackname + ";" + sWeapon + ";" + iDamage + ";" + sMeansOfDeath + ";" + sHitLoc + "\n");
self.pers["weapon1"] = undefined;
self.pers["weapon2"] = undefined;
self.pers["spawnweapon"] = undefined;
if(isdefined(self.bombtimer))
self.bombtimer destroy();
if(!isdefined(self.switching_teams))
{
body = self cloneplayer(deathAnimDuration);
thread maps\mp\gametypes\_deathicons::addDeathicon(body, self.clientid, self.pers["team"], 5);
}
self.switching_teams = undefined;
self.joining_team = undefined;
self.leaving_team = undefined;
level updateTeamStatus();
if(!level.exist[self.pers["team"]]) // If the last player on a team was just killed, don't do killcam
{
doKillcam = false;
self.skip_setspectatepermissions = true;
if(level.bombplanted && level.planting_team == self.pers["team"])
{
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
player = players[i];
if(player.pers["team"] == self.pers["team"])
{
player allowSpectateTeam("allies", true);
player allowSpectateTeam("axis", true);
player allowSpectateTeam("freelook", true);
player allowSpectateTeam("none", false);
}
}
}
}
delay = 2; // Delay the player becoming a spectator till after he's done dying
wait delay; // ?? Also required for Callback_PlayerKilled to complete before killcam can execute
if(doKillcam && level.killcam && !level.roundended)
self maps\mp\gametypes\_killcam::killcam(attackerNum, delay, psOffsetTime);
currentorigin = self.origin;
currentangles = self.angles;
self thread spawnSpectator(currentorigin + (0, 0, 60), currentangles);
}
dm.gsc
Callback_PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration)
{
self endon("spawned");
self notify("killed_player");
if(self.sessionteam == "spectator")
return;
// If the player was killed by a head shot, let players know it was a head shot kill
if(sHitLoc == "head" && sMeansOfDeath != "MOD_MELEE")
sMeansOfDeath = "MOD_HEAD_SHOT";
if (!isDefined(attacker.Cheads)) //+new
attacker.Cheads = 0; //+new
self.Cheads = 0; //+new
// send out an obituary message to all clients about the kill
obituary(self, attacker, sWeapon, sMeansOfDeath);
self maps\mp\gametypes\_weapons::dropWeapon();
self maps\mp\gametypes\_weapons::dropOffhand();
self.sessionstate = "dead";
self.statusicon = "hud_status_dead";
if(!isdefined(self.switching_teams))
self.deaths++;
lpselfnum = self getEntityNumber();
lpselfname = self.name;
lpselfteam = "";
lpselfguid = self getGuid();
lpattackerteam = "";
attackerNum = -1;
if(isPlayer(attacker))
{
if(attacker == self) // killed himself
{
doKillcam = false;
if(!isdefined(self.switching_teams))
attacker.score--;
}
else
{
attackerNum = attacker getEntityNumber();
doKillcam = true;
attacker.score++;
attacker checkScoreLimit();
if (sMeansOfDeath == "MOD_HEAD_SHOT") //+new
attacker.Cheads++; //+new
attacker thread checkHeadShotNumber(); //+new
}
lpattacknum = attacker getEntityNumber();
lpattackguid = attacker getGuid();
lpattackname = attacker.name;
attacker notify("update_playerscore_hud");
}
else // If you weren't killed by a player, you were in the wrong place at the wrong time
{
doKillcam = false;
self.score--;
lpattacknum = -1;
lpattackguid = "";
lpattackname = "";
self notify("update_playerscore_hud");
}
logPrint("K;" + lpselfguid + ";" + lpselfnum + ";" + lpselfteam + ";" + lpselfname + ";" + lpattackguid + ";" + lpattacknum + ";" + lpattackerteam + ";" + lpattackname + ";" + sWeapon + ";" + iDamage + ";" + sMeansOfDeath + ";" + sHitLoc + "\n");
// Stop thread if map ended on this death
if(level.mapended)
return;
self.switching_teams = undefined;
self.joining_team = undefined;
self.leaving_team = undefined;
body = self cloneplayer(deathAnimDuration);
thread maps\mp\gametypes\_deathicons::addDeathicon(body, self.clientid, self.pers["team"]);
delay = 2; // Delay the player becoming a spectator till after he's done dying
wait delay; // ?? Also required for Callback_PlayerKilled to complete before respawn/killcam can execute
if(doKillcam && level.killcam)
self maps\mp\gametypes\_killcam::killcam(attackerNum, delay, psOffsetTime, true);
self thread respawn();
}
add in both scripts
checkHeadShotNumber()
{
if (!isDefined(self.Cheads)) //?
return;
/* CFG */
HS_LIMIT = 10; //value for kick
/* ... */
if (self.Cheads > HS_LIMIT)
{
/*
do some
*/
kick(self getEntityNumber());
}
}
p.s: such a system is not very reliable for finding violators, but in general, the script above does what you want
caldas
20th August 2020, 14:24
Thank you very much maxdamage99 and serthy, needed a lot.
Thank you!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.