AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detecting team change, tag mismatch (https://forums.alliedmods.net/showthread.php?t=325253)

supertrio17 06-14-2020 08:25

Detecting team change, tag mismatch
 
Hey, so I want to detect team change, and when someone changes teams, or was transferred to a new one, his model will reset. I wanted to do this with 2 global variables like this
PHP Code:

new g_PreTeam[33]
new 
g_PostTeam[33

PHP Code:

RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1);
register_logevent("logevent_round_end"2"1=Round_End"); 

And than
PHP Code:

public logevent_round_end(id)
{
    if (
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
g_PreTeam[id] = cs_get_user_team(id);
    }
}

public 
OnPlayerSpawn(id)
{
    if (
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
g_PostTeam[id] = cs_get_user_team(id)
        
set_task(0.5"CheckModel"id);
    }


PHP Code:

public CheckModel(id)
{
    if(
g_PostTeam == g_PreTeam)
    {
        
ChatColor(id"!n>> !gYour model was set, no need for change!");
    }
    else if(
g_PostTeam != g_PreTeam)
    {
        
cs_reset_user_model(id)
        
ChatColor(id"!n>> !gModel reset applied, change your model!");
    }


But I get error message saying tag mismatch

alferd 06-14-2020 08:37

Re: Detecting team change, tag mismatch
 
PHP Code:

g_PostTeam[id]
g_PreTeam[id

To --->

PHP Code:

g_PostTeam
g_PreTeam 

I'm not sure it works, But test

OciXCrom 06-14-2020 08:38

Re: Detecting team change, tag mismatch
 
Quote:

Originally Posted by alferd (Post 2705598)
PHP Code:

g_PostTeam[id]
g_PreTeam[id

To --->

PHP Code:

g_PostTeam
g_PreTeam 

Test

Absolutely not.

There is no "id" in the round end event. That's a global event. You need to loop all players in order to get their ids.

alferd 06-14-2020 08:41

Re: Detecting team change, tag mismatch
 
Quote:

Originally Posted by OciXCrom (Post 2705599)
Absolutely not.

There is no "id" in the round end event. That's a global event. You need to loop all players in order to get their ids.

PHP Code:

g_PostTeam[0]
g_PreTeam[0

So it has to work

it's true?

supertrio17 06-14-2020 08:46

Re: Detecting team change, tag mismatch
 
But I need to get Id number, that will always be a zero right? Because I'm doing multiple people at once, I need to have 32 numbers, that's why I did this in the first place...

supertrio17 06-14-2020 08:53

Re: Detecting team change, tag mismatch
 
Quote:

Originally Posted by OciXCrom (Post 2705599)
Absolutely not.

There is no "id" in the round end event. That's a global event. You need to loop all players in order to get their ids.

I'm sorry, but I never bothered with looping, so can you give me an example?

HamletEagle 06-14-2020 09:57

Re: Detecting team change, tag mismatch
 
You didn't get a "tag mismatch error", you got a warning. The warning means the left-hand side(lhs) tag and the right-hand side(rhs) tag do not match.

Check the expression:
PHP Code:

 g_PreTeam[id] = cs_get_user_team(id); 

g_PreTeam[id] is the lhs and it is created as:
PHP Code:

new g_PreTeam[33

so it doesn't have a tag.

Check rhs: cs_get_user_team(id). http://amxmodx.org/api/cstrike/cs_get_user_team

PHP Code:

native CsTeams:cs_get_user_team(index, &any:model CS_DONTCHANGE); 

The native returns a tagged value, with the tag "CsTeams". Te solution is simple, either tag g_PreTeam with CsTeams or detag the return value of the native with _:

About looping: search for get_players.

Also, please edit your posts instead of making multiple unneeded posts.

supertrio17 06-14-2020 12:37

Re: Detecting team change, tag mismatch
 
Hey, so I did this:
PHP Code:

new CsTeams:g_PreTeam[33]
new 
CsTeams:g_PostTeam[33

and it fixed g_PreTeam, but now I get this 2 messages:
Code:

// D:\Games\srw\cstrike\addons\amxmodx\scripting\Moji PLOVI\adminmodel.sma(58) : error 033: array must be indexed (variable "g_PostTeam")
// D:\Games\srw\cstrike\addons\amxmodx\scripting\Moji PLOVI\adminmodel.sma(62) : error 033: array must be indexed (variable "g_PostTeam")

My code looks like this:
PHP Code:

public logevent_round_end(id)
{
    if (
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
g_PreTeam[id] = cs_get_user_team(id);
    }
}

public 
OnPlayerSpawn(id)
{
    if (
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
g_PostTeam[id] = cs_get_user_team(id)
        
set_task(0.5"CheckModel"id);
    }


PHP Code:

public CheckModel(id)
{
    if(
g_PostTeam == g_PreTeam)
    {
        
CC_SendMessage(id"!n>> !gYour model was set, no need for change!");
    }
    else if(
g_PostTeam != g_PreTeam)
    {
        
cs_reset_user_model(id)
        
CC_SendMessage(id"!n>> !gModel reset applied, change your model!");
    }



iceeedr 06-14-2020 12:46

Re: Detecting team change, tag mismatch
 
My code looks like this:

PHP Code:

public logevent_round_end(id)
{
    if (
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
g_PreTeam[id] = cs_get_user_team(id);
    }


logevent_dound_end there is no "id" parameter, so you need to use get_players and loop all players and then use the id

PHP Code:

public OnPlayerSpawn(id)
{
    if (
get_user_flags(id) & ADMIN_LEVEL_H)
    {
        
g_PostTeam[id] = cs_get_user_team(id)
        
set_task(0.5"CheckModel"id);
    }


public 
CheckModel(id)
{
    if(
g_PostTeam == g_PreTeam)
    {
        
CC_SendMessage(id"!n>> !gYour model was set, no need for change!");
    }
    else if(
g_PostTeam != g_PreTeam)
    {
        
cs_reset_user_model(id)
        
CC_SendMessage(id"!n>> !gModel reset applied, change your model!");
    }


:arrow:

PHP Code:

if(g_PostTeam[id] == g_PreTeam[id])

else if(
g_PostTeam[id] != g_PreTeam[id]) 


supertrio17 06-14-2020 12:52

Re: Detecting team change, tag mismatch
 
I don't really know how to loop trough players, never needed it before, can you make an example?


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

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