AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Only when being terrorist or CT (https://forums.alliedmods.net/showthread.php?t=120763)

amxxlover 03-07-2010 17:32

Only when being terrorist or CT
 
I try to make make clients who are in the terrorists or CT team say "I'm a terrorist or CT" when the doAction in the plugin is triggered or as soon they are terrorist or CT. When i use the below script clients who are not terrorist or CT say each 2 secconds "I'm a terrorist or CT". However these clients aren't terrorist or CT the "client_cmd(id,"say I'm a terrorists or CT")" line in the script is executed what shouldn't be happened if im right. Anyone can tell me what i did wrong or make a working script?

PHP Code:

public doAction(id)
{
    if ( 
get_user_team(id) != && get_user_team(id) != )
    {
        
set_task(2.0"doAction",id)
    }
    
client_cmd(id,"say I'm a terrorist or CT")



Doc-Holiday 03-07-2010 22:06

Re: Only when being terrorist or CT
 
PHP Code:

public doAction(id)
{
    if ( 
get_user_team(id) != && get_user_team(id) != )
    {
        
set_task(2.0"doAction",id)
    }
    
client_cmd(id,"say I'm a terrorist or CT")


:arrow:

PHP Code:

public doAction(id)
{
    if(
get_user_team(id) == 1)
    {
        
client_cmd(id,"say I'm a terrorist");
    }
    if(
get_user_team(id == 2)
    {
        
client_cmd(id"say I'm a CT");
    }




then call it where you want.
if you want it to loop every x amounts of seconds
PHP Code:

set_task(Time"Function"id_,_,_,b); //The b flag is the loop tag.

If No loop

set_task
(Time"Function"id); 


wrecked_ 03-07-2010 22:32

Re: Only when being terrorist or CT
 
Tsk tsk NcB... all that C++ reading has caused you to get sloppy.

Don't use get_user_team, it returns false results sometimes. Also, the code NcB posted had a couple of bracket-eering errors in it.

Code:
#include <amxmodx> #include <cstrike> // ... public doAction( id ) {     new CsTeams:iTeam = cs_get_user_team( id )         switch( iTeam )     {         case CS_TEAM_T:         {             client_cmd( id, "say terrorist" )         }                 case CS_TEAM_CT:         {             client_cmd( id, "say counter-terr" )         }                 default: // spec or unassigned         {             client_cmd( id, "say spec" )         }     } }

EDIT: *giggle* at the coincidental timing.

Bugsy 03-07-2010 23:12

Re: Only when being terrorist or CT
 
If you're only using a value once, no need to create a variable.
PHP Code:

switch( cs_get_user_teamid ) ) 

You can also do something like this.
PHP Code:

new CsTeams:iTeam cs_get_user_teamid );

if ( 
CS_TEAM_T <= iTeam <= CS_TEAM_CT )
    
client_printid print_chat "I am a %s" iTeam == CS_TEAM_T "Terrorist" "CT" ); 

I don't understand completely what you are trying to do. If you can explain better we can help better.

amxxlover 03-08-2010 00:53

Re: Only when being terrorist or CT
 
All 3 thank you very much :up::up::up:
Ive choicen for wrecked_ his script because spectators and unassigned team players could easely say something to so an extra thumb up for you :up:

edit: Reason for the script is to make players who join the T or CT team automaticly execute a command.

Bugsy 03-08-2010 08:40

Re: Only when being terrorist or CT
 
The thing you want to try to avoid is writing the same code twice. If you use the same function on T\CT (aside from a chat msg) you can do this (same for unassigned\spec).
PHP Code:

new CsTeams:iTeam cs_get_user_teamid );

switch ( 
iTeam )
{
     case 
CS_TEAM_T CS_TEAM_CT:
     {
          
client_printid print_chat "* You are a %s" iTeam == CS_TEAM_T "Terrorist" "CT" );
          
//call your other function(s)
     
}
     case 
CS_TEAM_UNASSIGNED CS_TEAM_SPECTATOR//default works too
     
{
          
client_printid print_chat "* %s" iTeam == CS_TEAM_UNASSIGNED "Choose a team!" "Why don't you play instead of spectate?" );
          
//call your other function(s)
     
}


If using wrecked's code and you do not use the iTeam variable again in your function, switch it directly.
PHP Code:

switch ( cs_get_user_teamid ) ) 


Doc-Holiday 03-09-2010 00:33

Re: Only when being terrorist or CT
 
I have always used get_user_team and have never had an error...

when it returns 0 i believe it just gets handled no actual run time error.. i could be wrong though...

wrecked_ 03-09-2010 07:03

Re: Only when being terrorist or CT
 
Quote:

Originally Posted by NcB_Sav (Post 1112446)
I have always used get_user_team and have never had an error...

when it returns 0 i believe it just gets handled no actual run time error.. i could be wrong though...

It's not that it errors, it returns false results on occasion.

Doc-Holiday 03-10-2010 18:44

Re: Only when being terrorist or CT
 
Quote:

Originally Posted by wrecked_ (Post 1112590)
It's not that it errors, it returns false results on occasion.

Good ta know.


All times are GMT -4. The time now is 08:40.

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