Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Natives for players #326

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

lozatto
Copy link

@lozatto lozatto commented Aug 16, 2024

The following natives were created:
rg_player_traceattack,
rg_player_takedamage,
rg_player_takehealth,
rg_player_killed,
rg_player_addpoints,
rg_is_player_alive,
rg_is_player_net_client,
rg_get_player_gun_position,
rg_is_player_bot

Tested✔

#include <amxmodx>
#include <fakemeta>
#include <reapi>

public plugin_init() {
	register_plugin("Natives", "1.0.0", "Lozatto")

	register_clcmd("say /ta", "@Command_TraceAttack")
	register_clcmd("say /td", "@Command_TakeDamage")
	register_clcmd("say /th", "@Command_TakeHealth")
	register_clcmd("say /k", "@Command_Killed")
	register_clcmd("say /ap", "@Command_AddPoints")
	register_clcmd("say /ipa", "@Command_IsPlayerAlive")
	register_clcmd("say /ipnc", "@Command_IsPlayerNetClient")
	register_clcmd("say /gpgp", "@Command_GetPlayerGunPosition")
	register_clcmd("say /ipb", "@Command_IsPlayerBot")

	RegisterHookChain(RG_CBasePlayer_TraceAttack, "@Player_TraceAttack_Pre", false)
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "@Player_TakeDamage_Pre", false)
	RegisterHookChain(RG_CBasePlayer_TakeHealth, "@Player_TakeHealth_Pre", false)
	RegisterHookChain(RG_CBasePlayer_Killed, "@Player_Killed_Pre", false)
	RegisterHookChain(RG_CBasePlayer_Killed, "@Player_Killed_Pre", false)
	RegisterHookChain(RG_CBasePlayer_AddPoints, "@Player_AddPoints_Pre", false)
}

@Command_TraceAttack(player) {
	new trace = create_tr2()
	rg_player_traceattack(player, player, 50.0, Float:{ 0.0, 0.0, 0.0 }, trace, DMG_GENERIC);
	free_tr2(trace)
}

@Command_TakeDamage(player) {
	rg_player_takedamage(player, player, player, 50.0, DMG_GENERIC);
}

@Command_TakeHealth(player) {
	rg_player_takehealth(player, 1000.0, DMG_GENERIC);
}

@Command_Killed(player) {
	rg_player_killed(player, player, DMG_ALWAYSGIB);
}

@Command_AddPoints(player) {
	rg_player_addpoints(player, 100, true)
}

@Command_IsPlayerAlive(player) {
	client_print_color(player, print_team_default, "isPlayerAlive: %d", rg_is_player_alive(player))
}

@Command_IsPlayerNetClient(player) {
	client_print_color(player, print_team_default, "isPlayerNetClient: %d", rg_is_player_net_client(player))
}

@Command_GetPlayerGunPosition(player) {
	new Float:src[3]
	src = rg_get_player_gun_position(player)
	client_print_color(player, print_team_default, "src: (%f, %f, %f)", src[0], src[1], src[2])
}

@Command_IsPlayerBot(player) {
	client_print_color(player, print_team_default, "isPlayerBot: %d", rg_is_player_bot(player))
}

@Player_TraceAttack_Pre(player, attacker, Float:damage, Float:direction[3], trace, damageType) {
	client_print_color(player, print_team_default, "@Player_TraceAttack_Pre(%d, %d, %f, %f, %f, %f, %d, %d)", player, attacker, damage, direction[0], direction[1], direction[2], trace, damageType)
}

@Player_TakeDamage_Pre(player, inflictor, attacker, Float:damage, damageType) {
	client_print_color(player, print_team_default, "@Player_TakeDamage_Pre(%d, %d, %d, %f, %d)", player, inflictor, attacker, damage, damageType)
}

@Player_TakeHealth_Pre(player, Float:health, damageType) {
	client_print_color(player, print_team_default, "@Player_TakeHealth_Pre(%d, %f, %d)", player, health, damageType)
}

@Player_Killed_Pre(player, attacker, gib) {
	client_print_color(player, print_team_default, "@Player_Killed_Pre(%d, %d, %d)", player, attacker, gib)
}

@Player_AddPoints_Pre(player, score, allowNegativeScore) {
	client_print_color(player, print_team_default, "@Player_AddPoints_Pre(%d, %d, %d)", player, score, allowNegativeScore)
}

@xiaodo1337
Copy link

You can do these with hamsandwich module

@wopox1337
Copy link
Collaborator

why don't you want to use Hamsandwich?

@JUNESYNGOTOFLEX
Copy link

you forgot rg_register_plugin()

@lozatto
Copy link
Author

lozatto commented Aug 29, 2024

#9 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants