AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   The Specialists - Brass Knuckles (Melee_Attack Usage) (https://forums.alliedmods.net/showthread.php?t=49273)

Calimaw 12-31-2006 03:02

The Specialists - Brass Knuckles (Melee_Attack Usage)
 
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <tsx> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw" new bool:g_brassknuckles[33] public plugin_init() {  register_plugin(PLUGIN, VERSION, AUTHOR)  register_clcmd("say /brassknuckles", "cmdBrassKnuckles") } public client_connect(id) g_brassknuckles[id] = false public Event_Death() g_brassknuckles[read_data(2)] = false   public cmdBrassKnuckles(id) {         if(!is_user_alive(id))                 client_print(id, print_chat, "The dead cannot buy items!")         else if(g_brassknuckles[id])                 client_print(id, print_chat, "What good would that do?")         else         {                 g_brassknuckles[id] = true                 client_print(id, print_chat, "You bought a pair of brass knuckles!")         }         return PLUGIN_HANDLED } public Melee_Attack (id, Float:time, Float:damage) {  client_print(id, print_chat, "You attack like viper! Rrrrr")  return PLUGIN_CONTINUE }

The above code is the begining of my very first plugin, and I'm still very terrible :P

The portion that doesnt work thus far is the very bottom block, at public Melee_Attack.

What it should do is display the message "You attack like viper! Rrrrrr!" (for testing) when using Kung Fu, and when you have the brass knuckles.

Currently I was just trying to get it to work with ANY melee attack regardless of knuckles or not, and I cant even get that working.

stupok 12-31-2006 04:08

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
Here's the progress I've made so far. It displays the message (5 times, anyone know why?) when the user presses the attack button and is using Kung Fu.

Code:
#include <amxmodx> #include <fakemeta> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function")         register_forward(FM_PlayerPreThink, "PlayerPreThink")         register_clcmd("say /brassknuckles", "cmdBrassKnuckles") } public client_connect(id) {     g_brassknuckles[id] = false     g_is_in_kungfu[id] = true } public Event_Death() {     new id = read_data(2)     g_brassknuckles[id] = false     g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) {     if(!get_msg_arg_int(1))     {         g_is_in_kungfu[msg_dest] = true     }     else     {         g_is_in_kungfu[msg_dest] = false     } }   public cmdBrassKnuckles(id) {         if(!is_user_alive(id))                 client_print(id, print_chat, "The dead cannot buy items!")         else if(g_brassknuckles[id])                 client_print(id, print_chat, "What good would that do?")         else         {                 g_brassknuckles[id] = true                 client_print(id, print_chat, "You bought a pair of brass knuckles!")         }         return PLUGIN_HANDLED } public PlayerPreThink(id) {     if(!is_user_alive(id))         return FMRES_IGNORED         if(pev(id,pev_button) & IN_ATTACK && g_is_in_kungfu[id])     {         client_print(id, print_chat, "You attack like viper! Rrrrr")     }         return FMRES_HANDLED }

Calimaw 12-31-2006 05:04

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
As to why it says it 5 times, Im not sure, but my first stab at it would be that the attack is repeated 4 times during its life time? Like if you strike at a wall with some one behind you, and you turn quickly enough, it will catch them too.

EDIT: Found out what it is. It's when you hold the button down it keeps repeating.

I don't know how to fix that yet, but I fixed a few other things.

Code:
#include <amxmodx> #include <fakemeta> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function") ///////////////////////// register_event("DeathMsg", "Event_Death", "a") ///////////////////////// register_forward(FM_PlayerPreThink, "PlayerPreThink") register_clcmd("say /brassknuckles", "cmdBrassKnuckles") } public client_connect(id) { g_brassknuckles[id] = false g_is_in_kungfu[id] = true } public Event_Death() { new id = read_data(2) g_brassknuckles[id] = false g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) { if(!get_msg_arg_int(1)) { g_is_in_kungfu[msg_dest] = true } else { g_is_in_kungfu[msg_dest] = false } }   public cmdBrassKnuckles(id) { if(!is_user_alive(id)) client_print(id, print_chat, "The dead cannot buy items!") else if(g_brassknuckles[id]) client_print(id, print_chat, "What good would that do?") else { g_brassknuckles[id] = true client_print(id, print_chat, "You bought a pair of brass knuckles!") } return PLUGIN_HANDLED } public PlayerPreThink(id) { if(!is_user_alive(id)) return FMRES_IGNORED /////////////////////////// else if(!g_brassknuckles[id]) return FMRES_IGNORED ///////////////////////////   if(pev(id,pev_button) & IN_ATTACK && g_is_in_kungfu[id]) { client_print(id, print_chat, "You attack like viper! Rrrrr") }   return FMRES_HANDLED }

Calimaw 12-31-2006 06:10

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
Code:
#include <amxmodx> #include <fakemeta> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function")     register_event("DeathMsg", "Event_Death", "a")     register_forward(FM_PlayerPreThink, "PlayerPreThink")     register_clcmd("say /brassknuckles", "cmdBrassKnuckles")     register_forward(FM_EmitSound, "EmitSound") } public plugin_precache() {         precache_sound("bknuckles/hit_01.wav")         precache_sound("bknuckles/swing_01.wav") } public client_connect(id) {     g_brassknuckles[id] = false     g_is_in_kungfu[id] = true } public Event_Death() {     new id = read_data(2)     g_brassknuckles[id] = false     g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) {     if(!get_msg_arg_int(1))     {         g_is_in_kungfu[msg_dest] = true     }     else     {         g_is_in_kungfu[msg_dest] = false     } }   public cmdBrassKnuckles(id) {         if(!is_user_alive(id))                 client_print(id, print_chat, "The dead cannot buy items!")         else if(g_brassknuckles[id])                 client_print(id, print_chat, "What good would that do?")         else         {                 g_brassknuckles[id] = true                 client_print(id, print_chat, "You bought a pair of brass knuckles!")         }         return PLUGIN_HANDLED } public PlayerPreThink(id) {     if(!is_user_alive(id))         return FMRES_IGNORED     else if(!g_brassknuckles[id])         return FMRES_IGNORED         if(pev(id,pev_button) & IN_ATTACK && g_is_in_kungfu[id])     {         client_print(id, print_chat, "You attack like viper! Rrrrr")     }         return FMRES_HANDLED } public EmitSound(id, channel, sample[]) {  if(!is_user_alive(id))   return FMRES_IGNORED  {   if(g_brassknuckles[id])   {    if(equal(sample,"player/kungfuhit.wav"))    {     emit_sound(id, CHAN_WEAPON, "bknuckles/hit_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)     return FMRES_SUPERCEDE    }    else if(equal(sample,"player/closecombat.wav"))    {     emit_sound(id, CHAN_WEAPON, "bknuckles/swing_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)     return FMRES_SUPERCEDE    }   }  }  return FMRES_IGNORED }

Made some more problems to solve, Im using Cheap_Suits CS Brass Knuckls plugin as a refference point to learn from, but alot of it is useless towards TS due to the differences in the mods, so If his isnt the correct way for TS, I dont know which is. This script won't compile on lines 85-86, I don't know what the error means.

|POW|Da_ghost 12-31-2006 10:11

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
Well the error is because you had 2 extra "{" so here is the new one.
Code:
#include <amxmodx> #include <fakemeta> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] public plugin_init() {  register_plugin(PLUGIN, VERSION, AUTHOR)  register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function")  register_event("DeathMsg", "Event_Death", "a")  register_forward(FM_PlayerPreThink, "PlayerPreThink")  register_clcmd("say /brassknuckles", "cmdBrassKnuckles")  register_forward(FM_EmitSound, "EmitSound") } public plugin_precache() {  precache_sound("bknuckles/hit_01.wav")  precache_sound("bknuckles/swing_01.wav") } public client_connect(id) {  g_brassknuckles[id] = false  g_is_in_kungfu[id] = true } public Event_Death() {  new id = read_data(2)  g_brassknuckles[id] = false  g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) {  if(!get_msg_arg_int(1))  {   g_is_in_kungfu[msg_dest] = true  }  else  {   g_is_in_kungfu[msg_dest] = false  } } public cmdBrassKnuckles(id) {  if(!is_user_alive(id))   client_print(id, print_chat, "The dead cannot buy items!")  else if(g_brassknuckles[id])   client_print(id, print_chat, "What good would that do?")  else  {   g_brassknuckles[id] = true   client_print(id, print_chat, "You bought a pair of brass knuckles!")  }  return PLUGIN_HANDLED } public PlayerPreThink(id) {  if(!is_user_alive(id))   return FMRES_IGNORED  else if(!g_brassknuckles[id])   return FMRES_IGNORED    if(pev(id,pev_button) & IN_ATTACK && g_is_in_kungfu[id])  {   client_print(id, print_chat, "You attack like viper! Rrrrr")  }    return FMRES_HANDLED } public EmitSound(id, channel, sample[]) {  if(!is_user_alive(id))   return FMRES_IGNORED    if(g_brassknuckles[id])  {   if(equal(sample,"player/kungfuhit.wav"))   {    emit_sound(id, CHAN_WEAPON, "bknuckles/hit_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)    return FMRES_SUPERCEDE   }   else if(equal(sample,"player/closecombat.wav"))   {    emit_sound(id, CHAN_WEAPON, "bknuckles/swing_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)    return FMRES_SUPERCEDE   }  }  return FMRES_IGNORED }

Calimaw 12-31-2006 14:05

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
Code:
#include <amxmodx> #include <fakemeta> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] public plugin_init() {  register_plugin(PLUGIN, VERSION, AUTHOR)  register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function")  register_event("DeathMsg", "Event_Death", "a")  register_forward(FM_PlayerPreThink, "PlayerPreThink")  register_clcmd("say /brassknuckles", "cmdBrassKnuckles")  register_forward(FM_EmitSound, "EmitSound") } public plugin_precache() {  precache_sound("bknuckles/hit_01.wav")  precache_sound("bknuckles/swing_01.wav") } public client_connect(id) {  g_brassknuckles[id] = false  g_is_in_kungfu[id] = true } public Event_Death() {  new id = read_data(2)  g_brassknuckles[id] = false  g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) {  if(!get_msg_arg_int(1))  {   g_is_in_kungfu[msg_dest] = true  }  else  {   g_is_in_kungfu[msg_dest] = false  } } public cmdBrassKnuckles(id) {  if(!is_user_alive(id))   client_print(id, print_chat, "The dead cannot buy items!")  else if(g_brassknuckles[id])   client_print(id, print_chat, "What good would that do?")  else  {   g_brassknuckles[id] = true   client_print(id, print_chat, "You bought a pair of brass knuckles!")  }  return PLUGIN_HANDLED } public PlayerPreThink(id) {  if(!is_user_alive(id))   return FMRES_IGNORED  else if(!g_brassknuckles[id])   return FMRES_IGNORED    if(pev(id,pev_button) & IN_ATTACK && g_is_in_kungfu[id])  {   client_print(id, print_chat, "You attack like viper! Rrrrr")  }    return FMRES_HANDLED } public EmitSound(id, channel, sample[]) {  if(!is_user_alive(id))   return FMRES_IGNORED    if(g_brassknuckles[id])  {   if(equal(sample,"player/kungfuhit.wav"))   {    emit_sound(id, CHAN_WEAPON, "bknuckles/hit_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)    client_print(id, print_chat, "Hit Sound!")    return FMRES_SUPERCEDE   }   else if(equal(sample,"player/closecombat.wav"))   {    emit_sound(id, CHAN_WEAPON, "bknuckles/swing_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)    client_print(id, print_chat, "Swing Sound!")    return FMRES_SUPERCEDE   }  }  return FMRES_IGNORED }

Okay, thanks to Da_Ghost the sounds play, but heres the kicker.

When you get hit by kung_fu or have hit some one, the sound emits from that player, so, whats going on is when I type /brassknuckles and get hit I will emit the sound. The sound that does not play at all currently is the swing sound.

I need to change it so that If the victim is hit by a player with the brass knuckles both players hear the new sound, as well as if the player has brass knuckles they need to emit the swing sound regardless of hitting or not.

stupok 12-31-2006 18:21

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
"player/kungfuhit.wav" passes through the EmitSound() function, but "player/closecombat.wav" does not. So you won't be able to change it, unfortunately. At least not with the fakemeta method; there may be some other method I'm not aware of. I'd wager it's client-side, and therefore untouchable.

You might be able to catch in prethink if a client has pushed the attack button and then check if an entity lost health, but that may not work and might be a bit hard to figure out...

Anyways, I played around with the code and changed a few things. I used the method from one of my other plugins to make the victim of the punch be knocked back when you hit him with brass knuckles, and the knuckles will do damage twice, meaning you do twice the amount of damage of a normal punch. I didn't bother replacing sounds, because I don't have your brass knuckles sound effects and you could only replace kungfuhit anyways.

I left code in there so you could see for yourself exactly what sound effects are passing through the function. Compiles fine, no errors.

I think the knock-back is entertaining enough. :wink:

Code:
#include <amxmodx> #include <fakemeta> #include <fun> #include <tsfun> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] new g_damage public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function")     register_event("PTakeDam", "PTakeDam_function", "a")     register_message(50, "killer_victim_function")         register_forward(FM_EmitSound, "EmitSound")         register_clcmd("say /brassknuckles", "cmdBrassKnuckles") } public client_connect(id) {     g_brassknuckles[id] = false     g_is_in_kungfu[id] = true } public Event_Death() {     new id = read_data(2)     g_brassknuckles[id] = false     g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) {     if(!get_msg_arg_int(1))     {         g_is_in_kungfu[msg_dest] = true     }     else     {         g_is_in_kungfu[msg_dest] = false     } } public PTakeDam_function() {     g_damage = read_data(7) } public killer_victim_function(msg_id, msg_dest, msg_entity) {     new victim = get_msg_arg_int(2)     new killer = get_msg_arg_int(3)         if(!is_user_alive(killer)) return PLUGIN_HANDLED         new Float:aimvelocity[3]         if(g_brassknuckles[killer])     {         velocity_by_aim(killer, g_damage * 100, aimvelocity)         set_pev(victim, pev_velocity, aimvelocity)                 new health = get_user_health(victim)         if(health - g_damage >= 0)         {             set_user_health(victim, health-g_damage)         }     }     return PLUGIN_HANDLED } public cmdBrassKnuckles(id) {     if(!is_user_alive(id))         client_print(id, print_chat, "The dead cannot buy items!")     else if(g_brassknuckles[id])         client_print(id, print_chat, "What good would that do?")     else     {         g_brassknuckles[id] = true         client_print(id, print_chat, "You bought a pair of brass knuckles!")     }     return PLUGIN_HANDLED } public EmitSound(id, channel, sample[]) {     /*     if(!is_user_alive(id))         return FMRES_IGNORED     */     new name[32]     get_user_name(id, name, 31)     if(contain(sample, "spark") == -1)     {         client_print(0, print_chat, "%s %s", name, sample)     }     /*     if(g_brassknuckles[id])     {         if(equal(sample,"player/kungfuhit.wav"))         {             emit_sound(id, CHAN_WEAPON, "bknuckles/hit_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)             client_print(id, print_chat, "Hit Sound!")             return FMRES_SUPERCEDE         }         else if(equal(sample,"player/closecombat.wav"))         {             emit_sound(id, CHAN_WEAPON, "bknuckles/swing_01.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)             client_print(id, print_chat, "Swing Sound!")             return FMRES_SUPERCEDE         }     }     */     return FMRES_IGNORED }

Calimaw 12-31-2006 19:46

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
Code:
#include <amxmodx> #include <fakemeta> #include <tsfun> #include <tsx> #include <engine> #define PLUGIN "Brass Knuckles" #define VERSION "1.0" #define AUTHOR "Calimaw/stupok69/Da_Ghost/XxAvalanchexX" new bool:g_brassknuckles[33] new bool:g_is_in_kungfu[33] public plugin_init() {  register_plugin(PLUGIN, VERSION, AUTHOR)  register_message(get_user_msgid("WeaponInfo"), "WeaponInfo_function")  register_event("DeathMsg", "Event_Death", "a")  register_clcmd("say /brassknuckles", "cmdBrassKnuckles")  register_forward(FM_EmitSound, "EmitSound") } public plugin_precache() {  precache_sound("bknuckles/hit_01.wav") } public client_connect(id) {  g_brassknuckles[id] = false  g_is_in_kungfu[id] = true } public Event_Death() {  new id = read_data(2)  g_brassknuckles[id] = false  g_is_in_kungfu[id] = true } public WeaponInfo_function(msg_id, msg_dest, msg_entity) {  if(!get_msg_arg_int(1))  {   g_is_in_kungfu[msg_dest] = true  }  else  {   g_is_in_kungfu[msg_dest] = false  } } public cmdBrassKnuckles(id) {  if(!is_user_alive(id))   client_print(id, print_chat, "The dead cannot buy items!")  else if(g_brassknuckles[id])   client_print(id, print_chat, "What good would that do?")  else  {   g_brassknuckles[id] = true   client_print(id, print_chat, "You bought a pair of brass knuckles!")  }  return PLUGIN_HANDLED } public EmitSound(id, channel, sample[], Float:volume, Float:att, flags, pitch) {         if(!is_user_alive(id))                 return FMRES_IGNORED           if(equal(sample,"player/kungfuhit.wav"))         {                 new attacker = get_user_attacker(id);                   if(is_user_connected(attacker) && attacker != id                 && g_brassknuckles[attacker] && g_is_in_kungfu[attacker])                 {                         emit_sound(id,channel,"bknuckles/hit_01.wav",volume,att,flags,pitch+random_num(-30,60));                         return FMRES_SUPERCEDE;                 }         }           return FMRES_IGNORED }   public client_damage(attacker,victim,damage,wpnindex,hitplace,TA) {         if(!g_brassknuckles[attacker] || (wpnindex != 0 && wpnindex != TSW_KUNG_FU))                 return PLUGIN_CONTINUE;           extra_damage(attacker,victim,random_float(18.0,36.0),"Brass Knuckles");           new Float:punch[3];         punch[0] = random_float(-30.0,30.0);         punch[1] = random_float(-15.0,15.0);         punch[2] = random_float(-20.0,20.0);           set_pev(victim,pev_punchangle,punch);         set_pev(victim,pev_fixangle,1);           return PLUGIN_CONTINUE; }   public extra_damage(attacker,victim,Float:damage,weapon[]) {         if(pev(victim,pev_health) - damage <= 0.0)         {                 new Float:frags;                 pev(attacker,pev_frags,frags);                   user_silentkill(victim);                 set_pev(attacker,pev_frags,frags+1.0);                   message_begin(MSG_ALL,get_user_msgid("DeathMsg"));                 write_byte(attacker);                 write_byte(victim);                 write_string(weapon);                 message_end();                   pev(attacker,pev_frags,frags);                 message_begin(MSG_ALL,get_user_msgid("ScoreInfo"));                 write_byte(attacker);                 write_short(floatround(frags));                 write_short(get_user_deaths(attacker));                 write_short(0);                 write_short(0);                 message_end();                   pev(victim,pev_frags,frags);                 message_begin(MSG_ALL,get_user_msgid("ScoreInfo"));                 write_byte(victim);                 write_short(floatround(frags));                 write_short(get_user_deaths(victim));                 write_short(0);                 write_short(0);                 message_end();         }         else fakedamage(victim,weapon,damage,0); }

This is what I've got so far, alot of help and many thanks to XxAvalanchexX.

This is working fairly well for the most part, except that the damage, and sound will play on the 2nd hit, never the first. The hit_01.wav seems to be working normally, altho it takes a while to kick in or something, Im not sure. It's a bit strange.

The next step is to make it so that brass knuckles do not effect kicks (+attack2?) and stunts moves. Im still disecting the code to learn from the bits Avalanche added.

stupok 01-01-2007 04:38

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
I have an idea for making brass knuckles work only for +attack and not +attack2. I can't say how effective the method may be without actually testing it, but you can have a boolean for each player, and in a prethink function set the boolean to true when +attack button is pushed and false when +attack2 button is pushed. Then in the damage function check if the boolean is true before dealing the extra damage. :wink:

Calimaw 01-02-2007 04:05

Re: The Specialists - Brass Knuckles (Melee_Attack Usage)
 
How do I stop the Fu death message when the player dies to Kung Fu, and has brass knuckles. Currently if you kill them with KungFu (as if to say, you do NOT have knuckles, but do) it will show that message, as well as the knuckles message.


All times are GMT -4. The time now is 22:22.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.