AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Proper way to attach a value to a native (https://forums.alliedmods.net/showthread.php?t=133398)

Tirant 07-24-2010 19:20

Proper way to attach a value to a native
 
I'm playing around with a plugin that works sorta like a zombie infection mod where when players die they turn into zombies. Anyways, the teams switch at the end of the round and go to the other team (that they started on the round before). I created an array called g_pTeam[33], and I grab the value when they first join a team. After that, the mod changes their teams during the rounds, but at the end of the round, it gets their g_pTeam[id] value and changes it to the opposite team. Right now I get a couple players every round who do not swap right, I thought it was an issue with autobalance or limitteams, but they are both set to 0. I was just wondering if there was a more efficient way to do this.

Here is an example of the team swap.
Quote:

cs_set_user_team(player, g_pTeam[player] == CS_TEAM_T ? CS_TEAM_CT:CS_TEAM_T)
g_pTeam[player] = cs_get_user_team(player)
I also get an error when grabbing and setting the g_pTeam[id] value
Quote:

Warning: Tag mismatch on line 601
I was wondering how to set it to not get an error. I was thinking making it static or constant would, but that doesn't make sense to me. Thank you for any help.

wrecked_ 07-24-2010 19:27

Re: Proper way to attach a value to a native
 
To get rid of that tag mismatch you need to declare g_pTeam as CsTeams.

PHP Code:

new CsTeams:g_pTeam[33


ConnorMcLeod 07-24-2010 19:28

Re: Proper way to attach a value to a native
 
Show more code.

Tirant 07-24-2010 22:10

Re: Proper way to attach a value to a native
 
This is all the code that changes teams. It looks solid enough to me, but I know that I can't code for !%#^. Thank you very much for you help so far. I should've known the CsTeams: :P.

PHP Code:

public task_force_team_join(menu_msgid[], id
{
    if (
get_user_team(id))
        return

    static 
msg_block
    msg_block 
get_msg_block(menu_msgid[0])
    
set_msg_block(menu_msgid[0], BLOCK_SET)
    
engclient_cmd(id"jointeam""5")
    
engclient_cmd(id"joinclass""5")
    
set_msg_block(menu_msgid[0], msg_block)
    
    
g_pTeam[id] = cs_get_user_team(id)


PHP Code:

public logevent_round_end()
{
    new 
players[32], num
    get_players
(playersnum)
        
    new 
player
    
for (new 0numi++)
    {
        
player players[i]
        
cs_set_user_team(playerg_pTeam[player] == CS_TEAM_T CS_TEAM_CT:CS_TEAM_T)
        
g_pTeam[player] = cs_get_user_team(player)
    }
    
print_color(0"^x04%L"LANG_SERVER"TEAMS_SWAPPED")

    
    if (
task_exists(TASK_ROUND))
        
remove_task(TASK_ROUND)
    if (
task_exists(BUILD_TASK))
        
remove_task(BUILD_TASK)
        
    return 
PLUGIN_HANDLED


CT Death Event
PHP Code:

cs_set_user_team(g_victimcs_get_user_team(g_victim) == CS_TEAM_T CS_TEAM_CT:CS_TEAM_T


SnoW 07-25-2010 05:48

Re: Proper way to attach a value to a native
 
PHP Code:

for( new 0numi++ )
        
cs_set_user_team( ( player players] ), ( g_pTeamplayer ] = ( g_pTeamplayer ] == CS_TEAM_T CS_TEAM_CT CS_TEAM_T ) ) ) 


ConnorMcLeod 07-25-2010 08:21

Re: Proper way to attach a value to a native
 
As a side note, you can replace :

PHP Code:

    if (task_exists(TASK_ROUND))
        
remove_task(TASK_ROUND)
    if (
task_exists(BUILD_TASK))
        
remove_task(BUILD_TASK

with

PHP Code:

        remove_task(TASK_ROUND)
        
remove_task(BUILD_TASK

because remove_task checks if the task exists.


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

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