Raised This Month: $ Target: $400
 0% 

Hamsandwich Forward, Return values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
t3hNox
Senior Member
Join Date: Oct 2009
Old 06-14-2010 , 11:31   Hamsandwich Forward, Return values
Reply With Quote #1

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.
t3hNox is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 06-14-2010 , 12:42   Re: Hamsandwich Forward, Return values
Reply With Quote #2

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...
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
t3hNox
Senior Member
Join Date: Oct 2009
Old 06-14-2010 , 13:32   Re: Hamsandwich Forward, Return values
Reply With Quote #3

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 ?
t3hNox is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 06-14-2010 , 13:38   Re: Hamsandwich Forward, Return values
Reply With Quote #4

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.
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...

Last edited by Alucard^; 06-14-2010 at 13:41.
Alucard^ is offline
Send a message via Skype™ to Alucard^
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 06-14-2010 , 13:47   Re: Hamsandwich Forward, Return values
Reply With Quote #5

check if the caller is a player.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 06-14-2010 , 14:00   Re: Hamsandwich Forward, Return values
Reply With Quote #6

Quote:
Originally Posted by drekes View Post
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...
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...

Last edited by Alucard^; 06-14-2010 at 14:03.
Alucard^ is offline
Send a message via Skype™ to Alucard^
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-15-2010 , 04:58   Re: Hamsandwich Forward, Return values
Reply With Quote #7

Quote:
Originally Posted by Alucard^ View Post
Oh, maybe here is the problem, yes...

Code:
#define IsPlayer(%1) (0 < %1 < 33)
This define is false, don't use it.


Correct one :

PHP Code:
new g_iMaxPlayers
#define FIRST_PLAYER_ID    1
#define IsPlayer(%1)    ( FIRST_PLAYER_ID <= %1 <= g_iMaxPlayers )

public plugin_init()
{
    
g_iMaxPlayers get_maxplayers()

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 06-14-2010 , 13:55   Re: Hamsandwich Forward, Return values
Reply With Quote #8

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.

Last edited by t3hNox; 06-15-2010 at 04:38.
t3hNox is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 06-14-2010 , 14:16   Re: Hamsandwich Forward, Return values
Reply With Quote #9

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.
t3hNox is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 06-14-2010 , 14:35   Re: Hamsandwich Forward, Return values
Reply With Quote #10

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
}

__________________


Last edited by NiHiLaNTh; 06-14-2010 at 14:56. Reason: O.o I didn't read carefully Alucard's post!
NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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