AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Plugin doesnt register event. (https://forums.alliedmods.net/showthread.php?t=147267)

Pantheon 01-07-2011 11:45

Plugin doesnt register event.
 
PHP Code:

#include <amxmodx>
#include <cstrike>

new bool:bTransfer false

public plugin_init() {
    
register_plugin("Mod","0.0.1","Pantheon")
    
register_clcmd("say !team","Event_TeamCheck",0," prints how many players in each team.")
    
register_logevent("RoundStart",2,"1=Round_Start")
    
register_event("CTransfer""Transfer""a")
}

public 
GetTeamCounts( &TCount , &CTCount )    {
    new 
iMaxPlayers get_maxplayers()
    
TCount 0
    CTCount 
0

    
for ( new <= iMaxPlayers i++ )    {
        if ( !
is_user_connected) )
            continue

        switch ( 
cs_get_user_team) )    {
            case 
CS_TEAM_TTCount++
            case 
CS_TEAM_CTCTCount++
        }
    }
}

public 
RoundStart() {
    new 
iTs iCTs
    GetTeamCounts
iTs iCTs )
    
client_printprint_center "Teams are being arranged. Stay Patient.")
    if (
iTs 1) {
        
bTransfer true
    
}else{
        
set_task(3.0,"Transfer_NoAction"0)
    }
}

public 
Transfer() {
    
client_print(0print_chat"LoL!!!")
    while (
bTransfer) {
        new 
zUser[32], i
        
if (cs_get_user_team(zUser[i])==CS_TEAM_T)
            
cs_set_user_team(zUser[i], CS_TEAM_CTCS_DONTCHANGE)
        else
            
set_task(3.0,"Transfer_NoAction"0)
    }
}

public 
Transfer_NoAction() {
    
client_print(0print_center"No Action was taken!")
}

public 
Event_TeamCheck() {
    new 
iTs iCTs
    GetTeamCounts
iTs iCTs )
    
client_printprint_chat "Terrorist=%d Counter Terrorist=%d" iTs iCTs )


Quote:

Teams are being arranged. Stay Patient.
is being printed. As well as:
Quote:

No Action was taken!
What am i doing wrong?

Arkshine 01-07-2011 11:57

Re: Plugin doesnt register event.
 
"CTransfer" event doesn't exist.

You have put that randomly or what?

Pantheon 01-07-2011 12:01

Re: Plugin doesnt register event.
 
Quote:

Originally Posted by Arkshine (Post 1388142)
"CTransfer" event doesn't exist.

You have put that randomly or what?

No, i thought the second parameter was the event name.

drekes 01-07-2011 12:22

Re: Plugin doesnt register event.
 
http://amxmodx.org/funcwiki.php?sear...vent&go=search
The first param is the name of the event, you can find the events here
the second parameter is the name of the function that's being called when the event is fired.

example:
PHP Code:

register_event("TeamInfo""Event_TeamInfo""a");

public 
Event_TeamInfo()
    
client_print(0print_chat"event TeamInfo is called"); 


Pantheon 01-07-2011 14:16

Re: Plugin doesnt register event.
 
I get these errors:
PHP Code:

L 01/07/2011 20:14:13: [CSTRIKEPlayer out of range (0)
L 01/07/2011 20:14:13: [AMXXDisplaying debug trace (plugin "mod.amxx")
L 01/07/2011 20:14:13: [AMXXRun time error 10native error (native "cs_get_user_team")
L 01/07/2011 20:14:13: [AMXX]    [0assassinsmod.sma::Event_TeamInfo (line 38

PHP Code:

#include <amxmodx>
#include <cstrike>

public plugin_init() {
    
register_plugin("Mod","0.0.1","Pantheon")
    
register_clcmd("say !team","Event_TeamCheck",0," prints how many players in each team.")
    
register_logevent("RoundStart",2,"1=Round_Start")
    
register_event("TeamInfo""Event_TeamInfo""a")
}

public 
GetTeamCounts( &TCount , &CTCount )    {
    new 
iMaxPlayers get_maxplayers()
    
TCount 0
    CTCount 
0

    
for ( new <= iMaxPlayers i++ )    {
        if ( !
is_user_connected) )
            continue

        switch ( 
cs_get_user_team) )    {
            case 
CS_TEAM_TTCount++
            case 
CS_TEAM_CTCTCount++
        }
    }
}

public 
RoundStart() {
    new 
iTs iCTs
    GetTeamCounts
iTs iCTs )
    
client_printprint_center "Teams are being arranged. Stay Patient.")
    if (
iTs 2)
        
set_task(3.0,"Transfer_NoAction"0)
}

public 
Event_TeamInfo() {
    
client_print(0print_chat"Success!")
    new 
zUser[32], i
    
if (cs_get_user_team(zUser[i])==CS_TEAM_T)
        
cs_set_user_team(zUser[i], CS_TEAM_CTCS_DONTCHANGE)
    else
        
set_task(3.0,"Transfer_NoAction"0)
}

public 
Transfer_NoAction() {
    
client_print(0print_center"No Action was taken!")
}

public 
Event_TeamCheck() {
    new 
iTs iCTs
    GetTeamCounts
iTs iCTs )
    
client_printprint_chat "Terrorist=%d Counter Terrorist=%d" iTs iCTs )



drekes 01-07-2011 14:25

Re: Plugin doesnt register event.
 
PHP Code:

public Event_TeamInfo() {
    
client_print(0print_chat"Success!")

    new 
id read_data(1);
    if (
cs_get_user_team(id)==CS_TEAM_T)
        
cs_set_user_team(idCS_TEAM_CTCS_DONTCHANGE)
    else
        
set_task(3.0,"Transfer_NoAction"0)



Pantheon 01-07-2011 15:15

Re: Plugin doesnt register event.
 
Quote:

Originally Posted by drekes (Post 1388240)
PHP Code:

public Event_TeamInfo() {
    
client_print(0print_chat"Success!")

    new 
id read_data(1);
    if (
cs_get_user_team(id)==CS_TEAM_T)
        
cs_set_user_team(idCS_TEAM_CTCS_DONTCHANGE)
    else
        
set_task(3.0,"Transfer_NoAction"0)



Thanks, i did some minor changes myself.

And it still doesnt work.

PHP Code:

#include <amxmodx>
#include <cstrike>

new bool:bTransfer false

public plugin_init() {
    
register_plugin("Assassins Creed Mod","0.0.1","Pantheon")
    
register_clcmd("say !team","Event_TeamCheck",0," prints how many players in each team.")
    
register_logevent("RoundStart",2,"1=Round_Start")
    
register_event("TeamInfo""Event_TeamInfo""a")
}

public 
GetTeamCounts( &TCount , &CTCount )    {
    new 
iMaxPlayers get_maxplayers()
    
TCount 0
    CTCount 
0

    
for ( new <= iMaxPlayers i++ )    {
        if ( !
is_user_connected) )
            continue

        switch ( 
cs_get_user_team) )    {
            case 
CS_TEAM_TTCount++
            case 
CS_TEAM_CTCTCount++
        }
    }
}

public 
RoundStart() {
    new 
iTs iCTs
    GetTeamCounts
iTs iCTs )
    
client_printprint_center "Teams are being arranged. Stay Patient.")
    if (
iTs 1) {
        
bTransfer true
    
}else{
        
bTransfer false
        set_task
(3.0,"Transfer_NoAction"0)
    }
}

public 
Event_TeamInfo() {
    
client_print(0print_chat"Success!")
    while (
bTransfer) {
        new 
id read_data(1);
        if (
cs_get_user_team(id)==CS_TEAM_T)
            
cs_set_user_team(idCS_TEAM_CTCS_DONTCHANGE)
        else
            
set_task(3.0,"Transfer_NoAction"0)
    }
}

public 
Transfer_NoAction() {
    
client_print(0print_center"No Action was taken!")
}

public 
Event_TeamCheck() {
    new 
iTs iCTs
    GetTeamCounts
iTs iCTs )
    
client_printprint_chat "Terrorist=%d Counter Terrorist=%d" iTs iCTs )



drekes 01-07-2011 16:10

Re: Plugin doesnt register event.
 
That's because at roundstart you set the bool true, but you don't use it until a player changes team.
The code only sets the player to CS_TEAM_T if there is more then 1 terrorist at the moment a player switches team.

What you need to do is make a new function that holds the code to change a player's team.
And at roundstart and the TeamInfo event check if there is more then 1 T, if so call the function.

Pantheon 01-07-2011 16:17

Re: Plugin doesnt register event.
 
Quote:

Originally Posted by drekes (Post 1388315)
That's because at roundstart you set the bool true, but you don't use it until a player changes team.
The code only sets the player to CS_TEAM_T if there is more then 1 terrorist at the moment a player switches team.

What you need to do is make a new function that holds the code to change a player's team.
And at roundstart and the TeamInfo event check if there is more then 1 T, if so call the function.

Im sorry to seem a little slow, but i have a easier time learning with examples.

So if you please..

Pantheon 01-07-2011 18:39

Re: Plugin doesnt register event.
 
Nevermind, fixed it.

Thanks for all your support!


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

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