AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ham_takedamage and global var (https://forums.alliedmods.net/showthread.php?t=187244)

EpicMonkey 06-10-2012 16:11

Ham_takedamage and global var
 
So ... Here's what am trying to do :

PHP Code:

#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Test"
#define VERSION "1.0"
#define AUTHOR "Epic"

new TestPlayer;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_TakeDamage"player""Fw_TakeDamage")
    
    
register_clcmd("say /test""Test")
}

public 
Test(id)
{
    
TestPlayer id
}

public 
Fw_TakeDamage(victiminflictorattackerFloat:damagedamagetype)
{
    if(
attacker == TestPlayer)
    {
        
client_print(0print_chat"Attacker is a test player")
    }
    else if(
attacker != TestPlayer)
    {
        
client_print(0print_chat"Attacker is not test player")
    }


here's the problem , when i attack a player , it doesnt print a message , but when another play attack me , it shows that Attacker is not a test player.

Any help would be appreciated , even a hint would be appreciated ...

ConnorMcLeod 06-10-2012 17:02

Re: Ham_takedamage and global var
 
Are you testing on condition zero bots ?

EpicMonkey 06-10-2012 17:26

Re: Ham_takedamage and global var
 
Quote:

Originally Posted by ConnorMcLeod (Post 1726366)
Are you testing on condition zero bots ?

:3 ... dont tell me thats the problem ....

Exolent[jNr] 06-10-2012 17:33

Re: Ham_takedamage and global var
 
Bots need to be registered differently than players for Ham hooks.

ConnorMcLeod 06-10-2012 19:16

Re: Ham_takedamage and global var
 
Install : http://forums.alliedmods.net/showpos...3&postcount=15

And in your plugin add :

PHP Code:

public cz_bot_ham_registerablebotIndex )
{
    
RegisterHamFromEntity(Ham_TakeDamagebotIndex"Fw_TakeDamage")



EpicMonkey 06-11-2012 01:40

Re: Ham_takedamage and global var
 
Quote:

Originally Posted by Exolent[jNr] (Post 1726383)
Bots need to be registered differently than players for Ham hooks.

once again , thank you for enlightening me.


Quote:

Originally Posted by ConnorMcLeod (Post 1726430)
Install : http://forums.alliedmods.net/showpos...3&postcount=15

And in your plugin add :

PHP Code:

public cz_bot_ham_registerablebotIndex )
{
    
RegisterHamFromEntity(Ham_TakeDamagebotIndex"Fw_TakeDamage")



thanks conner , ur the man :3

EpicMonkey 06-12-2012 16:29

Re: Ham_takedamage and global var
 
So , I tried this with a real player ... and its still bugg'ish ...
PHP Code:

#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Test"
#define VERSION "1.0"
#define AUTHOR "Epic"

new g_test1g_test2g_maxplayers;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /Test""TestMenu")
    
RegisterHam(Ham_TakeDamage"player""Fw_TakeDamage")
    
    
g_maxplayers get_maxplayers()
}

public 
TestMenu(id)
{
    new 
menu menu_create("Select a test player:""TestMenu_handler");
        
    new 
players[32], pnumtempid;
    new 
szName[32], szTempid[10];
        
    
get_players(playerspnum);
        
    for( new 
ii<pnumi++ )
    {
        
tempid players[i];
            
        
get_user_name(tempidszName31);
        
num_to_str(tempidszTempid9);
        
        
menu_additem(menuszNameszTempid0);
    }
    
menu_display(idmenu0);
}

public 
TestMenu_Handler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
tempid str_to_num(data)
    
    
g_test1 id
    g_test2 
tempid
    
    menu_destroy
(menu);
    return 
PLUGIN_HANDLED;
}

public 
Fw_TakeDamage(victiminflictorattackerFloat:damagedamagetype)
{
    if(
attacker == g_test1||g_test2 && victim != g_test1||g_test2)
    {
        
client_print(0print_chat"[AMXX] Attacker is a test player")
        return 
HAM_SUPERCEDE
    
}
    if(
attacker != g_test1||g_test2 && victim == g_test1||g_test2)
    {
        
client_print(0print_chat"[AMXX] Attacker is not a test player")
        return 
HAM_SUPERCEDE
    
}
    return 
HAM_HANDLED


test players arent supposed to hit other players , and other players arent supposed to hit test players ... but its giving me wierd results , even when i test it with real players

Exolent[jNr] 06-12-2012 16:36

Re: Ham_takedamage and global var
 
PHP Code:

attacker == g_test1||g_test2 

That's not how conditionals work.
What you would want to do is this:
PHP Code:

(attacker == g_test1 || attacker == g_test2

You do that several times, so be sure to correct them all.

EpicMonkey 06-13-2012 01:36

Re: Ham_takedamage and global var
 
Quote:

Originally Posted by Exolent[jNr] (Post 1727500)
PHP Code:

attacker == g_test1||g_test2 

That's not how conditionals work.
What you would want to do is this:
PHP Code:

(attacker == g_test1 || attacker == g_test2

You do that several times, so be sure to correct them all.

the basics of scripting ... and i got it all wrong :3 , time to read the wiki again ....
and thanks alot for pointing that out

EpicMonkey 06-13-2012 16:35

Re: Ham_takedamage and global var
 
so what your saying is as simple as:
PHP Code:

if(attacker == g_test1 || attacker == g_test2 && victim != g_test1 || victim != g_test2)
{
return 
HAM_SUPERCEDE;
}
else if(
attacker != g_test1 || attacker != g_test2 && victim == g_test1 || victim == g_test2
{
return 
HAM_SUPERCEDE;




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

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