Raised This Month: $32 Target: $400
 8% 

Give shield (problem)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CHyCMyMpNk
Senior Member
Join Date: Jun 2008
Location: PTZ
Old 10-19-2011 , 13:47   Give shield (problem)
Reply With Quote #1

Maybe someone knows, why not give shield properly. When I give him that it is not visible from the outside and the first person.


PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta_util>
#include <hamsandwich>

new bool:g_hasShield[33]

new 
SHIELD_V_MODEL[] = "models/shield/v_shield_knife.mdl"
new SHIELD_P_MODEL[] = "models/shield/p_shield_knife.mdl"


// CS Player CBase Offsets (win32)
const PDATA_SAFE 2
const OFFSET_ACTIVE_ITEM 373

public plugin_init() 
{
    
register_plugin("Shield""1.0""CHyC")

    
RegisterHam(Ham_Killed"player""PlayerKilled"1);
    
RegisterHam(Ham_Item_Deploy"weapon_knife""FwdDeployKnifePost");

    
register_forward(FM_TraceLine"Get_Traceline_Post"1)
    
register_event("HLTV""event_round_start""a""1=0""2=0")
}

public 
plugin_precache()
{
    
precache_model(SHIELD_V_MODEL)
    
precache_model(SHIELD_P_MODEL)
}

public 
plugin_natives()    
{
    
register_native("zp_give_shield""native_give_shield"1)
}

public 
native_give_shield(id)    give_shield(id)

public 
client_connect(id)
{
    
g_hasShield[id] = false
}

public 
client_disconnect(id)
{
    
g_hasShield[id] = false
}

public 
event_round_start()
{
    for (new 
1<= 32i++)
        
g_hasShield[i] = false
}

public 
PlayerKilled(Victimattacker)
{
    
ham_strip_weapon (Victim,"weapon_shield")
    
g_hasShield[Victim] = false
}

public 
give_shield(id)
{
    
g_hasShield[id] = true

        fm_give_item
(id"weapon_knife");
        
fm_give_item(id"weapon_shield");
}

public 
FwdDeployKnifePost(iEntity)
{
    new 
id get_pdata_cbase(iEntity414);

    if (
g_hasShield[id])
    {
        
entity_set_string(idEV_SZ_viewmodelSHIELD_V_MODEL);
        
entity_set_string(idEV_SZ_weaponmodelSHIELD_P_MODEL)
    }
}

stock ham_strip_weapon(index, const weapon[])
{
    
// Get weapon id
    
new weaponid get_weaponid(weapon)
    if (!
weaponid)
        return 
false;
    
    
// Get weapon entity
    
new weapon_ent fm_find_ent_by_owner(-1weaponindex)
    if (!
weapon_ent)
        return 
false;
    
    
// If it's the current weapon, retire first
    
new current_weapon_ent fm_cs_get_current_weapon_ent(index)
    new 
current_weapon pev_valid(current_weapon_ent) ? cs_get_weapon_id(current_weapon_ent) : -1
    
if (current_weapon == weaponid)
        
ExecuteHamB(Ham_Weapon_RetireWeaponweapon_ent)
    
    
// Remove weapon from player
    
if (!ExecuteHamB(Ham_RemovePlayerItemindexweapon_ent))
        return 
false;
    
    
// Kill weapon entity and fix pev_weapons bitsum
    
ExecuteHamB(Ham_Item_Killweapon_ent)
    
set_pev(indexpev_weaponspev(indexpev_weapons) & ~(1<<weaponid))
    return 
true;
}



stock fm_cs_get_current_weapon_ent(id)
{
    
// Prevent server crash if entity's private data not initalized
    
if (pev_valid(id) != PDATA_SAFE)
        return -
1;
    
    return 
get_pdata_cbase(idOFFSET_ACTIVE_ITEM);
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang3082\\ f0\\ fs16 \n\\ par }
*/ 

Last edited by CHyCMyMpNk; 10-19-2011 at 13:48.
CHyCMyMpNk is offline
Send a message via ICQ to CHyCMyMpNk
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-19-2011 , 15:16   Re: Give shield (problem)
Reply With Quote #2

PHP Code:
 RegisterHam(Ham_Item_Deploy"weapon_knife""FwdDeployKnifePost"); 
I think it has something to do with this, because you do not mention a chield in it, but don't ask me the solution :/
</span></span>
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
CHyCMyMpNk
Senior Member
Join Date: Jun 2008
Location: PTZ
Old 10-19-2011 , 15:25   Re: Give shield (problem)
Reply With Quote #3

tried this, so too did not work ...

PHP Code:
register_event("CurWeapon","checkWeapon","be","1=1");

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

public 
checkModel(id)
{
    if (
zp_core_is_zombie(id)) //for ZP 5.0
        
return PLUGIN_HANDLED
    
    set_pev
(idpev_viewmodel2SHIELD_V_MODEL)
    
set_pev(idpev_weaponmodel2SHIELD_P_MODEL)

    return 
PLUGIN_HANDLED


Last edited by CHyCMyMpNk; 10-19-2011 at 15:26.
CHyCMyMpNk is offline
Send a message via ICQ to CHyCMyMpNk
CHyCMyMpNk
Senior Member
Join Date: Jun 2008
Location: PTZ
Old 10-19-2011 , 15:41   Re: Give shield (problem)
Reply With Quote #4

mb this hero of the occasion?)

PHP Code:
/*================================================================================
    
    -------------------------------------
    -*- [CS] Weapons Restrict API 0.4 -*-
    -------------------------------------
    
    - Allows easily restricting player's weapons in CS and CZ
    - ToDo: PODBots support?? (does engclient_cmd work for them?)
    
================================================================================*/

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

#define MAXPLAYERS 32
#define NO_WEAPON 0

// CS Weapon CBase Offsets (win32)
const PDATA_SAFE 2
const OFFSET_WEAPONOWNER 41
const OFFSET_LINUX_WEAPONS // weapon offsets are only 4 steps higher on Linux
const OFFSET_NEXTPRIMARYATTACK 46
const OFFSET_NEXTSECONDARYATTACK 47

// CS Player CBase Offsets (win32)
const OFFSET_ACTIVE_ITEM 373
const OFFSSET_NEXTATTACK 83

// Weapon entity names
new const WEAPONENTNAMES[][] = { """weapon_p228""""weapon_scout""weapon_hegrenade""weapon_xm1014""weapon_c4""weapon_mac10",
            
"weapon_aug""weapon_smokegrenade""weapon_elite""weapon_fiveseven""weapon_ump45""weapon_sg550",
            
"weapon_galil""weapon_famas""weapon_usp""weapon_glock18""weapon_awp""weapon_mp5navy""weapon_m249",
            
"weapon_m3""weapon_m4a1""weapon_tmp""weapon_g3sg1""weapon_flashbang""weapon_deagle""weapon_sg552",
            
"weapon_ak47""weapon_knife""weapon_p90" }

// Weapon bitsums
const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const 
SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
const 
GRENADES_WEAPONS_BIT_SUM = (1<<CSW_HEGRENADE)|(1<<CSW_FLASHBANG)|(1<<CSW_SMOKEGRENADE)
const 
OTHER_WEAPONS_BIT_SUM = (1<<CSW_KNIFE)|(1<<CSW_C4)

#define flag_get(%1,%2)        (%1 & (1 << (%2 & 31)))
#define flag_set(%1,%2)        %1 |= (1 << (%2 & 31))
#define flag_unset(%1,%2)    %1 &= ~(1 << (%2 & 31))

new g_HasWeaponRestrictions
new g_AllowedWeaponsBitsum[MAXPLAYERS+1]
new 
g_DefaultAllowedWeapon[MAXPLAYERS+1]

public 
plugin_init()
{
    
register_plugin("[CS] Weapons Restrict API""0.4""WiLS")
    
    for (new 
1sizeof WEAPONENTNAMESi++)
        if (
WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_DeployWEAPONENTNAMES[i], "fw_Item_Deploy_Post"1)
}

public 
plugin_natives()
{
    
register_library("cs_weap_restrict_api")
    
register_native("cs_set_player_weap_restrict""native_set_player_weap_restrict")
    
register_native("cs_get_player_weap_restrict""native_get_player_weap_restrict")
}

public 
native_set_player_weap_restrict(plugin_idnum_params)
{
    new 
id get_param(1)
    
    if (!
is_user_connected(id))
    {
        
log_error(AMX_ERR_NATIVE"[CS] Player is not in game (%d)"id)
        return 
false;
    }
    
    new 
set get_param(2)
    
    if (!
set)
    {
        
// Player doesn't have weapon restrictions, no need to reset
        
if (!flag_get(g_HasWeaponRestrictionsid))
            return 
true;
        
        
flag_unset(g_HasWeaponRestrictionsid)
        
        
// Re-deploy current weapon, to unlock weapon's firing if we were blocking it
        
new current_weapon_ent fm_cs_get_current_weapon_ent(id)
        if (
pev_valid(current_weapon_ent)) ExecuteHamB(Ham_Item_Deploycurrent_weapon_ent)
        return 
true;
    }
    
    new 
allowed_bitsum get_param(3)
    new 
allowed_default get_param(4)
    
    if (!(
allowed_bitsum PRIMARY_WEAPONS_BIT_SUM) && !(allowed_bitsum SECONDARY_WEAPONS_BIT_SUM)
        && !(
allowed_bitsum GRENADES_WEAPONS_BIT_SUM) && !(allowed_bitsum OTHER_WEAPONS_BIT_SUM))
    {
        
// Bitsum does not contain any weapons, set allowed default weapon to NO_WEAPON
        
allowed_default NO_WEAPON
    
}
    else if (!(
allowed_bitsum & (1<<allowed_default)))
    {
        
log_error(AMX_ERR_NATIVE"[CS] Default allowed weapon must be in allowed weapons bitsum")
        return 
false;
    }
    
    
flag_set(g_HasWeaponRestrictionsid)
    
g_AllowedWeaponsBitsum[id] = allowed_bitsum
    g_DefaultAllowedWeapon
[id] = allowed_default
    
    
// Update weapon restrictions
    
new current_weapon_ent fm_cs_get_current_weapon_ent(id)
    if (
pev_valid(current_weapon_ent)) fw_Item_Deploy_Post(current_weapon_ent)
    return 
true;
}

public 
native_get_player_weap_restrict(plugin_idnum_params)
{
    new 
id get_param(1)
    
    if (!
is_user_connected(id))
    {
        
log_error(AMX_ERR_NATIVE"[CS] Player is not in game (%d)"id)
        return 
false;
    }
    
    if (!
flag_get(g_HasWeaponRestrictionsid))
        return 
false;
    
    
set_param_byref(2g_AllowedWeaponsBitsum[id])
    
set_param_byref(3g_DefaultAllowedWeapon[id])
    return 
true;
}

public 
client_disconnect(id)
{
    
flag_unset(g_HasWeaponRestrictionsid)
}

public 
fw_Item_Deploy_Post(weapon_ent)
{
    
// Get weapon's owner
    
new owner fm_cs_get_weapon_ent_owner(weapon_ent)
    
    
// Owner not valid or does not have any restrictions set
    
if (!is_user_alive(owner) || !flag_get(g_HasWeaponRestrictionsowner))
        return;
    
    
// Get weapon's id
    
new weaponid cs_get_weapon_id(weapon_ent)
    
    
// Owner not holding an allowed weapon
    
if (!((1<<weaponid) & g_AllowedWeaponsBitsum[owner]))
    {
        new 
weapons[32], num
        
new current_weapons_bitsum get_user_weapons(ownerweaponsnum)
        
        if (
current_weapons_bitsum & (<< g_DefaultAllowedWeapon[owner]))
        {
            
// Switch to default weapon
            
engclient_cmd(ownerWEAPONENTNAMES[g_DefaultAllowedWeapon[owner]])
        }
        else
        {
            
// Otherwise, block weapon firing and hide current weapon
            
block_and_hide_weapon(owner)
        }
    }
}

// Prevent player from firing and hide current weapon model
block_and_hide_weapon(id)
{
    
fm_cs_set_user_next_attack(id99999.0)
    
set_pev(idpev_viewmodel2"")
    
set_pev(idpev_weaponmodel2"")
}

stock fm_cs_get_weapon_ent_owner(ent)
{
    
// Prevent server crash if entity's private data not initalized
    
if (pev_valid(ent) != PDATA_SAFE)
        return -
1;
    
    return 
get_pdata_cbase(entOFFSET_WEAPONOWNEROFFSET_LINUX_WEAPONS);
}

// Get User Current Weapon Entity
stock fm_cs_get_current_weapon_ent(id)
{
    
// Prevent server crash if entity's private data not initalized
    
if (pev_valid(id) != PDATA_SAFE)
        return -
1;
    
    return 
get_pdata_cbase(idOFFSET_ACTIVE_ITEM);
}

stock fm_cs_set_user_next_attack(idFloat:next_attack)
{
    
// Prevent server crash if entity's private data not initalized
    
if (pev_valid(id) != PDATA_SAFE)
        return 
false;
    
    
set_pdata_float(idOFFSSET_NEXTATTACKnext_attack)
    return 
true;
}

// ConnorMcLeod
// 99999.0 = 27hours, should be enough.
// want to block attack1 ?
//set_pdata_float(weapon_ent, OFFSET_NEXTPRIMARYATTACK, 99999.0, OFFSET_LINUX_WEAPONS)
// want to block attack2 ?
//set_pdata_float(weapon_ent, OFFSET_NEXTSECONDARYATTACK, 99999.0, OFFSET_LINUX_WEAPONS)
// also want to block +use ? (may block other things as impulse(impulse are put in a queue))
//set_pdata_float(owner, OFFSSET_NEXTATTACK, 99999.0) 
block_and_hide_weapon
CHyCMyMpNk is offline
Send a message via ICQ to CHyCMyMpNk
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-20-2011 , 06:37   Re: Give shield (problem)
Reply With Quote #5

try to set the users current weapon to knife and try to give him a shield using give_item(id, "weapon_shield")

Dunno if that works.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
CHyCMyMpNk
Senior Member
Join Date: Jun 2008
Location: PTZ
Old 10-20-2011 , 11:46   Re: Give shield (problem)
Reply With Quote #6

for me it's not work too = (
CHyCMyMpNk is offline
Send a message via ICQ to CHyCMyMpNk
Reply


Thread Tools
Display Modes

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 04:17.


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