#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
// Adattárolók
new g_szVModel[33][64];
new g_szPModel[33][64];
new g_szWModel[33][64];
new bool:g_bHasCustomModel[33];
// Kés hangok
new g_szKnifeSoundSlash[64];
new g_szKnifeSoundHit[64];
new g_szKnifeSoundStab[64];
new g_szKnifeSoundWall[64];
new bool:g_bCustomKnifeSounds;
// Fegyver nevek a felismeréshez
new const g_szWeaponNames[][] = {
"", "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"
};
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
// Deploy (elővétel) eventek regisztrálása
for(new i = 1; i < sizeof(g_szWeaponNames); i++) {
if(g_szWeaponNames[i][0]) {
RegisterHam(Ham_Item_Deploy, g_szWeaponNames[i], "OnItemDeploy", 1);
}
}
register_forward(FM_SetModel, "OnSetModel");
register_forward(FM_EmitSound, "OnEmitSound");
}
public plugin_precache() {
LoadMapConfig();
}
LoadMapConfig() {
new szMapName[32], szConfigFile[128], szConfigDir[64];
get_mapname(szMapName, charsmax(szMapName));
get_configsdir(szConfigDir, charsmax(szConfigDir));
// Config fájl: configs/maps/PÁLYANÉV_weapons.ini
format(szConfigFile, charsmax(szConfigFile), "%s/maps/%s_weapons.ini", szConfigDir, szMapName);
if(!file_exists(szConfigFile)) return;
new iFile = fopen(szConfigFile, "rt");
if(!iFile) return;
new szLine[512];
new szWeapon[32], szV[64], szP[64], szW[64];
new szS1[64], szS2[64], szS3[64], szS4[64];
while(!feof(iFile)) {
fgets(iFile, szLine, charsmax(szLine));
trim(szLine);
// Kommentek kihagyása
if(!szLine[0] || szLine[0] == ';' || (szLine[0] == '/' && szLine[1] == '/')) continue;
// Adatok beolvasása
parse(szLine, szWeapon, charsmax(szWeapon), szV, charsmax(szV), szP, charsmax(szP), szW, charsmax(szW), szS1, charsmax(szS1), szS2, charsmax(szS2), szS3, charsmax(szS3), szS4, charsmax(szS4));
new iWeaponID = GetWeaponID(szWeapon);
if(iWeaponID > 0) {
// V Modell
if(szV[0] && file_exists(szV)) {
copy(g_szVModel[iWeaponID], charsmax(g_szVModel[]), szV);
precache_model(szV);
g_bHasCustomModel[iWeaponID] = true;
}
// P Modell
if(szP[0] && file_exists(szP)) {
copy(g_szPModel[iWeaponID], charsmax(g_szPModel[]), szP);
precache_model(szP);
g_bHasCustomModel[iWeaponID] = true;
}
// W Modell
if(szW[0] && file_exists(szW)) {
copy(g_szWModel[iWeaponID], charsmax(g_szWModel[]), szW);
precache_model(szW);
g_bHasCustomModel[iWeaponID] = true;
}
// Kés hangok
if(equal(szWeapon, "weapon_knife")) {
if(szS1[0] && file_exists(szS1)) { copy(g_szKnifeSoundSlash, charsmax(g_szKnifeSoundSlash), szS1); precache_sound(szS1); g_bCustomKnifeSounds = true; }
if(szS2[0] && file_exists(szS2)) { copy(g_szKnifeSoundHit, charsmax(g_szKnifeSoundHit), szS2); precache_sound(szS2); g_bCustomKnifeSounds = true; }
if(szS3[0] && file_exists(szS3)) { copy(g_szKnifeSoundStab, charsmax(g_szKnifeSoundStab), szS3); precache_sound(szS3); g_bCustomKnifeSounds = true; }
if(szS4[0] && file_exists(szS4)) { copy(g_szKnifeSoundWall, charsmax(g_szKnifeSoundWall), szS4); precache_sound(szS4); g_bCustomKnifeSounds = true; }
}
}
}
fclose(iFile);
}
public OnItemDeploy(iEnt) {
if(!is_valid_ent(iEnt)) return;
// Tulajdonos lekérése (offset 41 + 4 linux)
new id = get_pdata_cbase(iEnt, 41, 4);
if(!is_user_alive(id)) return;
// Fegyver ID lekérése (offset 43 + 4 linux)
new iWeaponID = get_pdata_int(iEnt, 43, 4);
if(g_bHasCustomModel[iWeaponID]) {
if(g_szVModel[iWeaponID][0]) set_pev(id, pev_viewmodel2, g_szVModel[iWeaponID]);
if(g_szPModel[iWeaponID][0]) set_pev(id, pev_weaponmodel2, g_szPModel[iWeaponID]);
}
}
public OnSetModel(iEnt, const szModel[]) {
if(!is_valid_ent(iEnt)) return FMRES_IGNORED;
// Ellenőrizzük, hogy w_ modellről van-e szó
if(szModel[7] != 'w' || szModel[8] != '_') return FMRES_IGNORED;
// Ha van custom W modell mentve
for(new i = 1; i < 31; i++) {
if(g_bHasCustomModel[i] && g_szWModel[i][0]) {
// Itt egy egyszerűsített ellenőrzést végzünk
// Ha a betöltendő modell neve tartalmazza a fegyver típusát (pl. "ak47")
// Akkor kicseréljük a miénkre.
// Megjegyzés: Ez feltételezi, hogy az eredeti modellnévben benne van a fegyver neve.
// Pontosabb lenne entitás ellenőrzéssel, de setmodelkor az még korai.
}
}
return FMRES_IGNORED;
}
public OnEmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch) {
if(!is_user_alive(id) || !g_bCustomKnifeSounds) return FMRES_IGNORED;
// Ellenőrizzük, hogy kés hang-e (pl. weapons/knife_...)
// A sample string általában "weapons/knife_hit1.wav" formátumú
if(containi(sample, "knife") != -1) {
if(containi(sample, "slash") != -1 && g_szKnifeSoundSlash[0]) {
emit_sound(id, channel, g_szKnifeSoundSlash, volume, attn, flags, pitch);
return FMRES_SUPERCEDE;
}
if(containi(sample, "hit") != -1 && g_szKnifeSoundHit[0]) {
emit_sound(id, channel, g_szKnifeSoundHit, volume, attn, flags, pitch);
return FMRES_SUPERCEDE;
}
if(containi(sample, "stab") != -1 && g_szKnifeSoundStab[0]) {
emit_sound(id, channel, g_szKnifeSoundStab, volume, attn, flags, pitch);
return FMRES_SUPERCEDE;
}
if(containi(sample, "wall") != -1 && g_szKnifeSoundWall[0]) {
emit_sound(id, channel, g_szKnifeSoundWall, volume, attn, flags, pitch);
return FMRES_SUPERCEDE;
}
}
return FMRES_IGNORED;
}
// Segédfüggvény a fegyver ID meghatározásához
GetWeaponID(const szWeapon[]) {
for(new i = 1; i < sizeof(g_szWeaponNames); i++) {
if(equal(szWeapon, g_szWeaponNames[i])) return i;
}
return 0;
}