Intro
Nada de especial, apenas um pequeno tutorial explicando como fazer um sistema "HeadShot", eu não reivindico isso como um esforço, já que é muito fácil e rápido ... Mas como não consegui encontrar nenhum tutorial decente, pensei ... vamos fazer isso.Contente
- Explicando OnPlayerTakeDamage , já que vamos precisar dele.
- Mini-script do sistema HeadShot.
- Proteção de equipe (não pode atingir a mesma equipe).
- Ativar / desativar o sistema HeadShot.
- Spam anti-headShot (parece estranho?)
Vamos começar
Para este tutorial, vamos nos basear no retorno de chamada OnPlayerTakeDamage .
Descrição de acordo com a página wiki:
Citar:
| Este callback é chamado quando um jogador sofre dano. |
Esse explica quase tudo ... mas vamos examiná-lo profundamente com seus parâmetros:
Código PHP:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
- playerid - jogador que sofreu danos.
- issuerid - Jogador que deu dano (The Shooter), pode ser INVALID_PLAYER_ID se o dano foi causado por ele mesmo.
- Float: amount - Quantidade em Float, de muito dano que o jogador sofreu (não é necessário em nosso caso, mas você pode usá-lo para outras coisas ... como rótulos na cabeça "Damage -amount")
- weaponid - ID da arma que foi usada durante o dano.
- parte corporal - a parte corporal onde o jogador foi atingido (0,3z +)
Código
Precisamos de uma variável global chamada "HeadShotSystem", então vamos defini-la, em qualquer lugar fora de um callback / função (perto de includes?)
Código PHP:
boolean, server variable not player variable
new bool:HeadShotSystem;
Código PHP:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
// check if there was a shooter, weaponID was 34(Sniper) and bodypart was 9(Head)
if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
{
//checking if headshot system is ON.
if(HeadShotSystem == true)
{
// checks if both players have same team, except NO_TEAM. if not procced, otherwise send error message
//*A edit by our genius friend sickattack
if(GetPlayerTeam(issuerid) | GetPlayerTeam(playerid) == NO_TEAM || GetPlayerTeam(issuerid) != GetPlayerTeam(playerid))
{
//check if player is dead... if not proceed(by Gammix)
if (GetPlayerState(playerid) != PLAYER_STATE_WASTED)
{
//variables, first one to format the message, second and third contain player names.
new headmsg[128], dead[24], killer[24];
//on player's screen we show him a message for 3 seconds "HeadShot"
GameTextForPlayer(playerid, "~r~Head Shot",3000,4);
// same to issuer's screen
GameTextForPlayer(issuerid, "~r~Head Shot!",3000,4);
// we get the victims name with this function and store it into our previously made variable "dead";
GetPlayerName(playerid, dead, sizeof(dead));
// we get the victims name with this function and store it into our previously made variable "killer";
GetPlayerName(issuerid, killer, sizeof(killer));
//format the message, means we put that text into "headmsg".
format(headmsg, sizeof(headmsg), "{FFDC2E}%s (%i) Has Been Killed in a Headshot by %s (%i)!",dead, playerid, killer,issuerid);
// once we've formatted the message we're ready to send the message to all players!
SendClientMessageToAll(0xAA3333AA, headmsg);
//kill the player
SetPlayerHealth(playerid, 0.0);
//and tell the server that he's dead!
}
}
}
else
SendClientMessage(issuerid, -1, "That player is in your team!");
}
return 1;
}
Comando para ativar / desativar o sistema de headshot
*Otimizado por Sreyas
Código PHP:
COMMAND:seths(playerid, params[])
{
//replace with your admin system
if(IsPlayerAdmin(playerid))
{
HeadShotSystem = !HeadShotSystem;
new string11[109], pname[24];
GetPlayerName(playerid, pname, 24);
format(string11, sizeof(string11), "[Admin] Server admin %s(%d) has %s Headshot system!", pname,playerid,(HeadShotSystem)?("enabled"):("disabled"));
SendClientMessageToAll(-1, string11);
}
return 1;
}

0 Comentários