| Dragokas |
08-06-2021 13:58 |
Re: [L4D2] l4d2_weapons.inc
Many good stocks, but to find out how to equip weapon and set the max ammo, need a bottle of vodka.
By try and fail, using some your examples, my final variant:
PHP Code:
void PlayerEquip(int client, char[] weap_name) { int type, id, iEnt, iCurWep; float vOrigin[3]; GetClientAbsOrigin(client, vOrigin); if( weap_name[0] ) { type = L4D2Wep_IdentifyItemByName(weap_name, id); if( type == ITEM_MELEE ) { if( !L4D2Wep_IsValidMelee(weap_name) ) continue; } if( L4D2Wep_IsValidItemAndID(id, type) ) { int slot = L4D2Wep_GetSlotByID(id); iEnt = L4D2Wep_SpawnItem(id, type, vOrigin, _, _, false); if( iEnt != -1 ) { iCurWep = GetPlayerWeaponSlot(client, slot); if( L4D2Wep_IsValidAndEntity(iCurWep) ) { RemovePlayerItem(client, iCurWep); AcceptEntityInput(iCurWep, "Kill"); } EquipPlayerWeapon(client, iEnt); if( slot == 0 ) { RequestFrame(Frame_SetMaxAmmo, GetClientUserId(client)); } } } } }
public void Frame_SetMaxAmmo(int UserId) { int client = GetClientOfUserId(UserId); if( client && IsClientInGame(client) ) { int ent = GetPlayerWeaponSlot(client, 0); int wep_id = L4D2Wep_Identify(ent, IDENTIFY_HOLD); int ammoId = L4D2Wep_WepIDToAmmoID(wep_id); if( ammoId != AMMOID_NONE ) { L4D2Wep_SetPlayerAmmo(client, L4D2Wep_GetAmmo(ammoId)); } } }
Will be good to have it as a stock.
|