AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] PrimaryAttack/SecondaryAttack (https://forums.alliedmods.net/showthread.php?t=237732)

~Ice*shOt 03-28-2014 19:00

[Solved] PrimaryAttack/SecondaryAttack
 
Hello, I need some help. When I write 'pri' I must use 'attack2' once and then PrimaryAttack for knife is blocked, and it's the same with SecondaryAttack. Question, what I need to do, that when I write 'pri' PrimaryAttack should be [un]blocked at the time, and when I write 'sec' SecondaryAttack should be [un]blocked at the time too?


PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
 
new boolblocked[33]
 
public 
plugin_init()
{
    
register_clcmd("say toggle""toggle")
 
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""Fwd_PrimaryAttack"1)
    
RegisterHam(Ham_Item_Deploy"weapon_knife""Fwd_PrimaryAttack"1)
 
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_knife""Fwd_SecondaryAttack"1)
    
RegisterHam(Ham_Item_Deploy"weapon_knife""Fwd_SecondaryAttack"1)
}
 
public 
toggle(id)
        
blocked[id] = !blocked[id]
 
public 
Fwd_PrimaryAttack(Ent)
{
    new 
id get_pdata_cbase(Ent414)
 
    if (
blocked[id])
        
set_pdata_float(Ent479999.04)
 
    return 
HAM_IGNORED
}
 
public 
Fwd_SecondaryAttack(Ent)
{
    new 
id get_pdata_cbase(Ent414)
 
    if (!
blocked[id])
        
set_pdata_float(Ent469999.04)
 
    return 
HAM_IGNORED



Black Rose 03-28-2014 19:11

Re: PrimaryAttack/SecondaryAttack
 
You basically want to switch between only allowing primary or secondary?
If so, you only need one variable, making two when they always have the opposite function is useless.

Code:
public pri(id)         pblocked[id] = ! pblocked[id];

Code:
public Fwd_PrimaryAttack(Ent) {     new id = get_pdata_cbase(Ent, 41, 4)     if (pblocked[id])         set_pdata_float(Ent, 47, 9999.0, 4)     return HAM_IGNORED } public Fwd_SecondaryAttack(Ent) {     new id = get_pdata_cbase(Ent, 41, 4)     if (!pblocked[id])         set_pdata_float(Ent, 46, 9999.0, 4)     return HAM_IGNORED }

~Ice*shOt 03-28-2014 19:18

Re: PrimaryAttack/SecondaryAttack
 
Thanks for explaining :), now waiting for my real problem solution, because it still works bad.

Black Rose 03-28-2014 19:19

Re: PrimaryAttack/SecondaryAttack
 
Quote:

Originally Posted by ~Ice*shOt (Post 2117190)
Thanks for explaining :), now waiting for my real problem solution, because it still works bad.

What's your real problem?

~Ice*shOt 03-28-2014 19:24

Re: PrimaryAttack/SecondaryAttack
 
I tried to explain it in first post, anyway.. Look when I write toggle now, it should toggle one of attacks, but when I write toggle it's still blocked, untill I used opposite button. Idk how to explain that really, it should be tested and you could see it..

Black Rose 03-28-2014 20:23

Re: PrimaryAttack/SecondaryAttack
 
I have no idea what I did, but it seems to be working.

Code:
#include <amxmodx> #include <fakemeta> #include <hamsandwich> new bool: blocked[33] new gWeaponEntIndex[33]; public plugin_init() {     register_clcmd("say toggle", "toggle")     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "Fwd_PrimaryAttack", 1)     RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "Fwd_SecondaryAttack", 1)         RegisterHam(Ham_Item_Deploy, "weapon_knife", "Fwd_Item_Deploy") } public Fwd_Item_Deploy(Ent) {     new id = get_pdata_cbase(Ent, 41, 4);     ResetAttack(id, Ent)     gWeaponEntIndex[id] = Ent; } public toggle(id) {     blocked[id] = ! blocked[id];     ResetAttack(id, gWeaponEntIndex[id]) } public Fwd_PrimaryAttack(Ent)     set_pdata_float(Ent, 47, 9999.0, 4); public Fwd_SecondaryAttack(Ent)     set_pdata_float(Ent, 46, 9999.0, 4) ResetAttack(id, Ent) {     if ( blocked[id] ) {         set_pdata_float(Ent, 46, 0.0, 4);         set_pdata_float(Ent, 47, 9999.0, 4)     }     else {         set_pdata_float(Ent, 47, 0.0, 4);         set_pdata_float(Ent, 46, 9999.0, 4)     } }

~Ice*shOt 03-29-2014 02:39

Re: PrimaryAttack/SecondaryAttack
 
Black Rose, thank you a lot!


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

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