Raised This Month: $ Target: $400
 0% 

Solved [HELP]what am i doing wrong ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yas17sin
Veteran Member
Join Date: Oct 2016
Location: Morocco/Sale
Old 04-11-2017 , 13:02   [HELP]what am i doing wrong ?
Reply With Quote #1

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.
__________________
FINISHED WORKING ON : Attack On Titan Mod (100% Done).

FB Acc : FaceBook Account.

pic: http://prntscr.com/fszkke not good quality

Last edited by yas17sin; 04-12-2017 at 14:40.
yas17sin is offline
Send a message via ICQ to yas17sin
Adomaz1
Senior Member
Join Date: Feb 2014
Old 04-11-2017 , 15:11   Re: [HELP]what am i doing wrong ?
Reply With Quote #2

try to check iCount on round end
Adomaz1 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-11-2017 , 15:52   Re: [HELP]what am i doing wrong ?
Reply With Quote #3

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; }
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-11-2017 at 15:53.
EFFx is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-11-2017 , 15:55   Re: [HELP]what am i doing wrong ?
Reply With Quote #4

Because there's no "id" in the Swap function. It's a global function, so you need to loop through all players.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
yas17sin
Veteran Member
Join Date: Oct 2016
Location: Morocco/Sale
Old 04-11-2017 , 16:38   Re: [HELP]what am i doing wrong ?
Reply With Quote #5

@EFFx, thanks for your help it worked.

@OciXCrom, yeah i didn't know that also can it be done by read_data ?.
__________________
FINISHED WORKING ON : Attack On Titan Mod (100% Done).

FB Acc : FaceBook Account.

pic: http://prntscr.com/fszkke not good quality
yas17sin is offline
Send a message via ICQ to yas17sin
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-11-2017 , 16:40   Re: [HELP]what am i doing wrong ?
Reply With Quote #6

READ About set task

>>
https://wiki.alliedmods.net/Advanced...X_Mod_X)#Tasks
>>
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
yas17sin
Veteran Member
Join Date: Oct 2016
Location: Morocco/Sale
Old 04-11-2017 , 16:59   Re: [HELP]what am i doing wrong ?
Reply With Quote #7

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.
__________________
FINISHED WORKING ON : Attack On Titan Mod (100% Done).

FB Acc : FaceBook Account.

pic: http://prntscr.com/fszkke not good quality

Last edited by yas17sin; 04-11-2017 at 17:06.
yas17sin is offline
Send a message via ICQ to yas17sin
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-11-2017 , 18:22   Re: [HELP]what am i doing wrong ?
Reply With Quote #8

set_task(length parameter, function, taskid) PS taskid is not the player id as you think!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-11-2017 , 18:53   Re: [HELP]what am i doing wrong ?
Reply With Quote #9

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 }
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-11-2017 at 19:07.
EFFx is offline
yas17sin
Veteran Member
Join Date: Oct 2016
Location: Morocco/Sale
Old 04-12-2017 , 14:39   Re: [HELP]what am i doing wrong ?
Reply With Quote #10

thanks EFFx for you usefull explaintion, i appreciate it.
__________________
FINISHED WORKING ON : Attack On Titan Mod (100% Done).

FB Acc : FaceBook Account.

pic: http://prntscr.com/fszkke not good quality
yas17sin is offline
Send a message via ICQ to yas17sin
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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