AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hamsandwich Forward, Return values (https://forums.alliedmods.net/showthread.php?t=129587)

t3hNox 06-14-2010 11:31

Hamsandwich Forward, Return values
 
Hi.
I've never worked with hamsandwich module before. Basically I'm making a plugin that would block Ts from clicking any button if IsFreeRun is "true", however, CTs would be still able to use them (no matter the IsFreeRun value).
The code is mainly taken from another plugin - Use Button Once.

PHP Code:

public plugin_init() {
//     ...code...
    
if( engfunc(EngFunc_FindEntityByString,-,"classname""func_button"))
        
RegisterHam(Ham_Use"func_button""fwButtonUsed");

    if(
engfunc(EngFunc_FindEntityByString,-,"classname","func_rot_button"))
        
RegisterHam(Ham_Use"func_rot_button""fwButtonUsed");
        
    if(
engfunc(EngFunc_FindEntityByString,-,"classname""button_target"))
        
RegisterHam(Ham_Use"button_target""fwButtonUsed");
}

//The function.. I know it's not the best way to use IFs
public fwButtonUsed(idcaller) {
    if(
IsFreeRun == true && get_user_team(idcaller) == 1) {
        return 
HAM_SUPERCEDE;
    }
    if(
IsFreeRun == true && get_user_team(idcaller) == 2) {
        return 
FMRES_IGNORED;
    }
    return 
PLUGIN_HANDLED;


Not the full code (obviously), only the part that is not working, plugin completes fine - no errors. However, that button clicking thing is not working. Either no one can click them or buttons are usable no matter the IsFreeRun value.
Currently I'm not really interested in any optimizations (if any is possible), I just need to get the code to work.

Alucard^ 06-14-2010 12:42

Re: Hamsandwich Forward, Return values
 
This is useless, i think:

PHP Code:

    if(IsFreeRun == true && get_user_team(idcaller) == 2) { 
        return 
FMRES_IGNORED

Also..

PHP Code:

return PLUGIN_HANDLED

-->

PHP Code:

return HAM_IGNORED

And..

PHP Code:

return FMRES_SUPERCEDE

-->

PHP Code:

return HAM_SUPERCEDE

And... try using fm_get_user_team( ) or cs_get_user_team( ), cuz get_user_team( ) has some bugs if am not wrong...

t3hNox 06-14-2010 13:32

Re: Hamsandwich Forward, Return values
 
Unfortunately, no success.
The function now looks like this:
PHP Code:

public fwButtonUsed(idcaller) {
    if(
IsFreeRun == true && cs_get_user_team(idcaller) == CS_TEAM_T) {
        return 
HAM_SUPERCEDE;
    }
    if(
IsFreeRun == true && cs_get_user_team(idcaller) == CS_TEAM_CT) {
        return 
HAM_IGNORED
    }
    return 
HAM_IGNORED


(Yes, the second IF is probably not needed)
Server's console returns this error (although, the plugin completes fine) :
Code:

L 06/14/2010 - 20:22:17: [AMXX]    [0] sample.sma::fwButtonUsed (line 79)
L 06/14/2010 - 20:22:17: [CSTRIKE] Player out of range (97)
L 06/14/2010 - 20:22:17: [AMXX] Displaying debug trace (plugin "sample.amxx")
L 06/14/2010 - 20:22:17: [AMXX] Run time error 10: native error (native "cs_get_
user_team")

The 79th line is:
PHP Code:

    if(IsFreeRun == true && cs_get_user_team(idcaller) == CS_TEAM_T) { 

I guess I don't use cs_get_user_team properly ?

Alucard^ 06-14-2010 13:38

Re: Hamsandwich Forward, Return values
 
mMM, strange =S... no, you are using cs_get_user_team( ) correctly.

I think is not a problem of that part of code, is another thing, don't know.

EDIT: I never tried with IamBool == true in a condition... i think is ok but don't sure... i usually use if(IamBool) or if(!IamBool), just try... who know.

EDIT2: what version of AMXX you are using? maybe cstrike module is outdate.

drekes 06-14-2010 13:47

Re: Hamsandwich Forward, Return values
 
check if the caller is a player.

t3hNox 06-14-2010 13:55

Re: Hamsandwich Forward, Return values
 
Here's how it looks. I know, probably poorly coded.
*No more available. Optimizing and upgrading it.*
The AMXX version I'm using is 1.8.1.

Alucard^ 06-14-2010 14:00

Re: Hamsandwich Forward, Return values
 
Quote:

Originally Posted by drekes (Post 1208605)
check if the caller is a player.

Oh, maybe here is the problem, yes...

Code:
#define IsPlayer(%1) (0 < %1 < 33)

Also... rememebr that:

Code:
        if(cs_get_user_team(idcaller) == CS_TEAM_CT)             return HAM_IGNORED;

Is useless...

t3hNox 06-14-2010 14:16

Re: Hamsandwich Forward, Return values
 
Huh, I'm not sure how to check if a caller is a player ( if(idcalled) ?). And I'm also not sure how to use that define. I tried this:
Code:

if(IsFreeRun == true && IsPlayer(idcaller))
With no success.
Another interesting this is that the "check" function (see the full code) cannot properly detect the player's team at the beginning of a round.

NiHiLaNTh 06-14-2010 14:35

Re: Hamsandwich Forward, Return values
 
Anyway, to filter valid player you can also use
Code:

    is_user_alive(id)


Code:

public fwButtonUsed(idcaller)
{   
    if ( !is_user_alive ( idcaller ) )         
        return HAM_IGNORED
   
    static CsTeams:iTeam
    iTeam = cs_get_user_team ( idcaller ) 
   
    if ( IsFreeRun && iTeam == CS_TEAM_T )         
        return HAM_SUPERCEDE
   
    return HAM_IGNORED
}



t3hNox 06-14-2010 14:49

Re: Hamsandwich Forward, Return values
 
Unfortunately, no success. With this version everyone can click buttons.
PHP Code:

public fwButtonUsed(idcaller
{    
    if ( !
is_user_alive idcaller ) )           
        return 
HAM_IGNORED
    
    
static CsTeams:iTeam
    iTeam 
cs_get_user_team idcaller )   
    
    if ( 
IsFreeRun == true && iTeam == CS_TEAM_T )           
        return 
HAM_SUPERCEDE
    
    
return HAM_IGNORED




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

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