AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved [HELP]what am i doing wrong ? (https://forums.alliedmods.net/showthread.php?t=296069)

yas17sin 04-11-2017 13:02

[HELP]what am i doing wrong ?
 
Hi all.

i've made this team swap and all seems good but when the round that cnrtolled by cvar comes the team does not swap, any idea why it doesn't work.

Here the fixed Code :

PHP Code:

#include <amxmodx>
#include <fun>
#include <cstrike>
#include <hamsandwich>

#define PLUGIN "Team Swap"
#define VERSION "0.2"
#define AUTHOR "yas17sin"

#define TAG "TAG"

#define TASK_SHOW_LEVEL 10113

#define isTeam(%0)    (CS_TEAM_T <= cs_get_user_team(%0) <= CS_TEAM_CT)

#define MAX_PLAYERS 32

new g_msgsync;

new 
iCount;

new 
cvar_enablecvar_round_neededcvar_round_hud;

public 
plugin_init()
{
    
register_plugin(AUTHORVERSIONPLUGIN)
    
    
register_event"HLTV""Event_NewRound""a""1=0""2=0" );
    
register_logevent("EventRoundEnd"2"1=Round_End" );
    
    
RegisterHamHam_Spawn"player""FwdPlayerSpawnPost");
    
    
g_msgsync CreateHudSyncObj();
    
    
cvar_enable register_cvar("amx_plugin_on""1");
    
cvar_round_needed register_cvar("amx_round_needed""4");
    
cvar_round_hud register_cvar("amx_hud_on""1");
    
    
register_clcmd("say /round""round_now")
    
register_clcmd("say_team /round""round_now")
    
register_clcmd("say /rnd""round_now")
    
register_clcmd("say_team /rnd""round_now")
}
public 
client_disconnect(id)
{
    
remove_taskTASK_SHOW_LEVEL id );
}
public 
Event_NewRound()
{
    if(!
get_pcvar_num(cvar_enable))
        return;
        
    
iCount++
    
    if( 
iCount get_pcvar_num(cvar_round_needed) )
    {
        
set_task(1.0"Swap")
    }
}
public 
FwdPlayerSpawnPost(id)
{
    if(!
get_pcvar_num(cvar_round_hud))
        return 
HAM_HANDLED;
        
    
set_task(0.1"task_show_level"TASK_SHOW_LEVEL id)
    
    return 
PLUGIN_CONTINUE;
}
public 
task_show_level(task)
{
    new 
id task TASK_SHOW_LEVEL
    
    set_hudmessage
(025500.440.0106.0300.0)
    
ShowSyncHudMsg(idg_msgsync"[%s] Round Remain For Swap : %d/%d"TAGiCountget_pcvar_num(cvar_round_needed));
    
    
set_task(0.1"task_show_level"TASK_SHOW_LEVEL id)        
}
public 
Swap(id)
{
    if(!
get_pcvar_num(cvar_enable))
        return;

    new 
iPlayers[MAX_PLAYERS], iNumid
    get_players
(iPlayersiNum)
    for(new 
i;iNum;i++)
    {
        
id iPlayers[i]

        if(
isTeam(id))
        {
            
cs_set_user_team(idcs_get_user_team(id) == CS_TEAM_CT CS_TEAM_T CS_TEAM_CT)
        }
    }
    
iCount 0;
}
public 
round_now(id)
{
    
client_print(idprint_center"[%s] the round now is %d/%d"TAGiCountget_pcvar_num(cvar_round_needed))
}
public 
EventRoundEnd()
{
    if(
get_pcvar_num(cvar_round_hud))
        return
        
    
client_print(0print_center"[%s] the round now is %d/%d"TAGiCountget_pcvar_num(cvar_round_needed))


P.S : thanks for advance.

Adomaz1 04-11-2017 15:11

Re: [HELP]what am i doing wrong ?
 
try to check iCount on round end

EFFx 04-11-2017 15:52

Re: [HELP]what am i doing wrong ?
 
Code:
#define isTeam(%0)          (CS_TEAM_T <= cs_get_user_team(%0) <= CS_TEAM_CT)

Code:
public Swap(id) {     if(!get_pcvar_num(cvar_enable))         return;     new iPlayers[MAX_PLAYERS], iNum, id     get_players(iPlayers, iNum)     for(new i;i < iNum;i++)     {         id = iPlayers[i]         if(isTeam(id))         {             cs_set_user_team(id, cs_get_user_team(id) == CS_TEAM_CT ? CS_TEAM_T : CS_TEAM_CT)         }     }     iCount = 0; }

OciXCrom 04-11-2017 15:55

Re: [HELP]what am i doing wrong ?
 
Because there's no "id" in the Swap function. It's a global function, so you need to loop through all players.

yas17sin 04-11-2017 16:38

Re: [HELP]what am i doing wrong ?
 
@EFFx, thanks for your help it worked.

@OciXCrom, yeah i didn't know that also can it be done by read_data ?.

Natsheh 04-11-2017 16:40

Re: [HELP]what am i doing wrong ?
 
READ About set task

>>
https://wiki.alliedmods.net/Advanced...X_Mod_X)#Tasks
>>

yas17sin 04-11-2017 16:59

Re: [HELP]what am i doing wrong ?
 
so you mean that i can set the task for all player 0 no need for the id of the player :

like that :
PHP Code:

set_task(1.0"function"0

if it is that way i have already try it but didn't work.

i think like EFFx did is better and work fine.

Natsheh 04-11-2017 18:22

Re: [HELP]what am i doing wrong ?
 
set_task(length parameter, function, taskid) PS taskid is not the player id as you think!

EFFx 04-11-2017 18:53

Re: [HELP]what am i doing wrong ?
 
Just a little fix:

Code:
public Swap(id)

Code:
public Swap()

When you're gonna add a task for a player, add id+SOMENUMBERS and at your function, id -= SAMENUMBERS.

Your code didn't work because you hadn't an id in your task while you added (id) at your function. The compiler readed
Code:
switch(cs_get_user_team(0))

Code:
set_task(Float:time, "function")

Code:
public function() { }

This is the right way without an id.

Code:
set_task(Float:time, "function", id+20310)

ID example: 12

12+20310 = 20322

Code:
public function(id) {    id -= 20310 }

23022 - 20310 = 12

This is the right way with an id.

I recommend you always use a constant or define for set a task, it will be good if you want remove that task whenever you want even without an id. I mean:

Code:
const TASK_1 = 20310

or

Code:
#define TASK_1 20310

Code:
set_task(Float:time, "function", id+TASK_1)

Code:
public function(id) {    id -= TASK_1 }

yas17sin 04-12-2017 14:39

Re: [HELP]what am i doing wrong ?
 
thanks EFFx for you usefull explaintion, i appreciate it.


All times are GMT -4. The time now is 18:01.

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