AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] if player change team..... (https://forums.alliedmods.net/showthread.php?t=294436)

yas17sin 02-26-2017 16:47

[HELP] if player change team.....
 
Hi i need help about this :
I have a plugin and i want it to work only with CT.
Because i have every 3 rounds the team switch and if the player have the item he just keep it.
I want it to get remove from the player when the his team switch to T and then give him back when he is CT and keep happing that way.

I did try this but didn't work :
PHP Code:

public FwdPlayerSpawnPost(id)
{
    if(
cs_get_user_team(id) == CS_TEAM_T )
    {
        
g_KNIFE[id] = false
        g_hasSpeed
[id] = false
    
}



EFFx 02-26-2017 16:55

Re: [HELP] if player change team.....
 
Add a check for see if the player is on team T.

Bugsy 02-26-2017 17:07

Re: [HELP] if player change team.....
 
Hook TeamInfo. Take a look at this: https://forums.alliedmods.net/showpo...5&postcount=19

yas17sin 02-26-2017 17:07

Re: [HELP] if player change team.....
 
EDIT: so i can done it this way ?
PHP Code:

#include <amxmodx>

public plugin_init()
{
    
register_event("TeamInfo""TeamInfo""a")
}
public 
TeamInfo()
{
    new 
id szTeam];
    
    
id read_data);
    
read_dataszTeam charsmaxszTeam ) );
    
    if ( 
g_iCurTeamid ] != szTeam] )
    {
        
g_iCurTeamid ] = szTeam];
        
        switch( 
szTeam] )
        {
            case 
'T'
            {
                if ( !
g_AdminsTeam_T ] )
                    {
                        
g_KNIFE[id] = false
                        g_hasSpeed
[id] = false
                    
}
            }
            case 
'C'
            {
                if ( !
g_AdminsTeam_CT ] )
                    {
                        
g_KNIFE[id] = false
                        g_hasSpeed
[id] = false
                    
}
            }
        }
    }



Bugsy 02-26-2017 17:17

Re: [HELP] if player change team.....
 
You do not need the g_Admins check.

Your switch should look like this. Why are you setting to false in both instances? If that's the case you're better off with an if statement for T or CT. Explain when g_KNIFE and g_hasSpeed get their values.
PHP Code:

        switch( szTeam] )
        {
            case 
'T'
            {
                   
g_KNIFE[id] = false
                   g_hasSpeed
[id] = false
            
}
            case 
'C'
            {
                   
g_KNIFE[id] = false
                   g_hasSpeed
[id] = false
            
}
        } 


yas17sin 02-26-2017 17:19

Re: [HELP] if player change team.....
 
no that was just an example. so i will test it that way and se if it work.

yas17sin 02-26-2017 17:34

Re: [HELP] if player change team.....
 
so i did it that way but it still give the knife on respawn for all CT and it give them also after switch team to CT again not for the one who buy it only ( sorry if i type wrong )
Full Code :
PHP Code:

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

#define PLUGIN    "Unlock Candy Knife"
#define VERSION    "0.2"
#define AUTHOR    "yas17sin"

#define ADMIN_ACCESS ADMIN_LEVEL_H

#define MAX_PLAYERS 32

enum Teams
{
    
Team_T 1,
    
Team_CT
}

new 
g_iCurTeamMAX_PLAYERS ] = { 'U' , ... };

new 
KNIFE_V_MODEL[] = "models/v_Candy-knife.mdl"

new bool:g_KNIFE[33]
new 
bool:g_hasSpeed[33]

new 
cvar_knife_gore
new cvar_jumpcvar_dmgmultcvar_knife_spdcvar_knock

new const g_sound_knife[] = { "items/gunpickup2.wav" }


new const 
d_sounds[][] =
{
        
"Candy-Knife/knife_deploy1.wav",
        
"Candy-Knife/knife_hit1.wav",
        
"Candy-Knife/knife_hit2.wav",
        
"Candy-Knife/knife_hitwall.wav",
        
"Candy-Knife/knife_slash1.wav",
        
"Candy-Knife/knife_stab.wav"
}

new const 
oldknife_sounds[][] =
{
        
"weapons/knife_deploy1.wav",
        
"weapons/knife_hit1.wav",
        
"weapons/knife_hit2.wav",
        
"weapons/knife_hitwall1.wav",
        
"weapons/knife_slash1.wav",
        
"weapons/knife_stab.wav"
}

public 
plugin_init()
{
        
register_plugin(PLUGIN VERSION AUTHOR);
        
register_gxm_item("\wCandy Knife\r[ADMIN ACCESS]"" +speed +power +Knockback (Knife)"250)
        
        
register_event"TeamInfo" "TeamInfo" "a" );
        
register_event("CurWeapon","checkWeapon","be","1=1");
        
register_forward(FM_EmitSound"fw_EmitSound");
        
register_forward(FM_PlayerPreThink"fw_PlayerPreThink");
        
RegisterHam(Ham_TakeDamage"player""fw_TakeDamage");

        
register_message(get_user_msgid("DeathMsg"), "message_DeathMsg");

        
cvar_knife_gore         register_cvar("knife_effect"               "1");
        
cvar_jump           register_cvar("knife_jump"             "380.0");
        
cvar_dmgmult        register_cvar("knife_dmg"              "5");
        
cvar_knife_spd      register_cvar("knife_spd"              "350.0");
        
cvar_knock          register_cvar("knife_power"            "17");
}
public 
gxm_item_enabled(id
{
    
g_KNIFE[id] = true
    g_hasSpeed
[id] = true
}
public 
client_connect(id)
{
        
g_KNIFE[id] = false
        g_hasSpeed
[id] = false
}

public 
client_disconnect(id)
{
        
g_KNIFE[id] = false
        g_hasSpeed
[id] = false
}
public 
TeamInfo()
{
    new 
id szTeam];
    
    
id read_data);
    
read_dataszTeam charsmaxszTeam ) );
    
    if ( 
g_iCurTeamid ] != szTeam] )
    {
        
g_iCurTeamid ] = szTeam];
        
        switch( 
szTeam] )
        {
            case 
'T'
            {
                
g_KNIFE[id] = false
                g_hasSpeed
[id] = false
            
}
            case 
'C'
            {
                
g_KNIFE[id] = true
                g_hasSpeed
[id] = true
            
}
        }
    }
}
public 
plugin_precache()
{
        
precache_model(KNIFE_V_MODEL)

        
precache_sound(g_sound_knife)

        for(new 
0sizeof d_soundsi++)
                
precache_sound(d_sounds[i])
}


/*public buy_knife(id)
{
    new flags = get_user_flags(id);
    if( flags & ADMIN_ACCESS)
    {
    g_KNIFE[id] = true
    g_hasSpeed[id] = true

    engfunc(EngFunc_EmitSound, id, CHAN_BODY, g_sound_knife, 1.0, ATTN_NORM, 0, PITCH_NORM)
    }
}*/

public checkWeapon(id)
{
        new 
plrWeapId
    
        plrWeapId 
get_user_weapon(id)
    
        if (
plrWeapId == CSW_KNIFE && (g_KNIFE[id]))
        {
                
checkModel(id)
        }
}

public 
checkModel(id)
{
        if (
g_KNIFE[id])
        {
                
set_pev(idpev_viewmodel2KNIFE_V_MODEL)
        }
        return 
PLUGIN_HANDLED
}

public 
fw_EmitSound(idchannel, const sound[])
{
        if(!
is_user_alive(id))
                return 
FMRES_IGNORED
        
        
for(new 0sizeof d_soundsi++)
        {
                if(
equal(soundoldknife_sounds[i]))
                {
                        if (
g_KNIFE[id])
                        {
                                
emit_sound(idchanneld_sounds[i], 1.0ATTN_NORM0PITCH_NORM)
                                return 
FMRES_SUPERCEDE
                        
}
                        if (!
g_KNIFE[id])
                        {
                                
emit_sound(idchanneloldknife_sounds[i], 1.0ATTN_NORM0PITCH_NORM)
                                return 
FMRES_SUPERCEDE
                        
}
                }
        }
        return 
FMRES_IGNORED
}

public 
fw_PlayerPreThink(id)
{
        if(!
is_user_alive(id))
                return 
FMRES_IGNORED

        
new temp[2], weapon get_user_weapon(idtemp[0], temp[1])

        if (
weapon == CSW_KNIFE && g_KNIFE[id])
        {
                
g_hasSpeed[id] = true
                set_user_maxspeed
(idget_pcvar_float(cvar_knife_spd))

                if ((
pev(idpev_button) & IN_JUMP) && !(pev(idpev_oldbuttons) & IN_JUMP))
                {
                        new 
flags pev(idpev_flags)
                        new 
waterlvl pev(idpev_waterlevel)
                        
                        if (!(
flags FL_ONGROUND))
                                return 
FMRES_IGNORED

                        
if (flags FL_WATERJUMP)
                                return 
FMRES_IGNORED

                        
if (waterlvl 1)
                                return 
FMRES_IGNORED
                        
                        
new Float:fVelocity[3]
                        
pev(idpev_velocityfVelocity)
                        
                        
fVelocity[2] += get_pcvar_num(cvar_jump)
                        
                        
set_pev(idpev_velocityfVelocity)
                        
set_pev(idpev_gaitsequence6)
                }
        }
        return 
FMRES_IGNORED
}  

public 
fw_TakeDamage(victiminflictorattackerFloat:damagedamage_type)
{
        if(!
is_user_connected(attacker))
                return 
HAM_IGNORED

        
new weapon get_user_weapon(attacker)
        if (
weapon == CSW_KNIFE && g_KNIFE[attacker])
        {       
                
SetHamParamFloat(4damage get_pcvar_float(cvar_dmgmult)) 

                new 
Float:vec[3];
                new 
Float:oldvelo[3];
                
pev(victimpev_velocityoldvelo);
                
create_velocity_vector(victim attacker vec);
                
vec[0] += oldvelo[0];
                
vec[1] += oldvelo[1];
                
set_pev(victimpev_velocityvec);
        }

        if(
get_pcvar_num(cvar_knife_gore))
                
more_blood(victim)

        return 
HAM_IGNORED
}

public 
message_DeathMsg(msg_idmsg_destid)
{
        static 
szTruncatedWeapon[33], iattackerivictim
        
        get_msg_arg_string
(4szTruncatedWeaponcharsmax(szTruncatedWeapon))
        
        
iattacker get_msg_arg_int(1)
        
ivictim get_msg_arg_int(2)
        
        if(!
is_user_connected(iattacker) || iattacker == ivictim)
                return 
PLUGIN_CONTINUE

        
        
if(equal(szTruncatedWeapon"knife") && get_user_weapon(iattacker) == CSW_KNIFE)
        {
                if(
g_KNIFE[iattacker])
                    
set_msg_arg_string(4"Candy Knife")
        }
        
        if(
equal(szTruncatedWeapon"knife") && get_user_weapon(iattacker) == CSW_KNIFE)
        {
            if(!
g_KNIFE[iattacker])
                
set_msg_arg_string(4"knife")
        }
        return 
PLUGIN_CONTINUE
}

stock create_velocity_vector(victim,attacker,Float:velocity[3])
{
        if(!
is_user_alive(attacker))
                return 
0;

        new 
Float:vicorigin[3];
        new 
Float:attorigin[3];
        
pev(victimpev_origin vicorigin);
        
pev(attackerpev_origin attorigin);

        new 
Float:origin2[3]
        
origin2[0] = vicorigin[0] - attorigin[0];
        
origin2[1] = vicorigin[1] - attorigin[1];

        new 
Float:largestnum 0.0;

        if(
floatabs(origin2[0])>largestnumlargestnum floatabs(origin2[0]);
        if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]);

        
origin2[0] /= largestnum;
        
origin2[1] /= largestnum;

        if (
g_KNIFE[attacker])
        {
                
velocity[0] = ( origin2[0] * (get_pcvar_float(cvar_knock) * 3000) ) / floatround(get_distance_f(vicoriginattorigin));
                
velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_knock) * 3000) ) / floatround(get_distance_f(vicoriginattorigin));
        }

        if(
velocity[0] <= 20.0 || velocity[1] <= 20.0)
        
velocity[2] = random_float(200.0 275.0);

        return 
1;
}

stock fm_set_user_maxspeed(indexFloat:speed = -1.0
{
        
engfunc(EngFunc_SetClientMaxspeedindexspeed);
        
set_pev(indexpev_maxspeedspeed);

        return 
1;
}       

more_blood(id)
{
        static 
iOrigin[3]
        
get_user_origin(idiOrigin)
        
        
// Blood spray
        
message_begin(MSG_PVSSVC_TEMPENTITYiOrigin)
        
write_byte(TE_BLOODSTREAM)
        
write_coord(iOrigin[0])
        
write_coord(iOrigin[1])
        
write_coord(iOrigin[2]+10)
        
write_coord(random_num(-360360)) // x
        
write_coord(random_num(-360360)) // y
        
write_coord(-10// z
        
write_byte(70// color
        
write_byte(random_num(50100)) // speed
        
message_end()

        for (new 
04j++) 
        {
                
message_begin(MSG_PVSSVC_TEMPENTITYiOrigin)
                
write_byte(TE_WORLDDECAL)
                
write_coord(iOrigin[0]+random_num(-100100))
                
write_coord(iOrigin[1]+random_num(-100100))
                
write_coord(iOrigin[2]-36)
                
write_byte(random_num(190197)) // index
                
message_end()
        }




All times are GMT -4. The time now is 20:54.

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