地面放置武器插件!
本帖最后由 123315517 于 2022-12-11 11:18 编辑地面放置武器的插件,来源网络。
地面放置武器后会绊脚、经过时候有上台阶的感觉,求高手解决。
代码过长,拆分为3段放下面评论区了。 本帖最后由 123315517 于 2022-12-10 14:30 编辑
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
//ent name
#define wp_ent "weapon_entity"
//ent values
#define WP_Type pev_iuser4
#define WP_Left pev_iuser3
#define WP_Maxpev_iuser2
//primary and secondary weapons
#define PRIMARY_WEAPONS ((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))
#define SECONDARY_WEAPONS ((1<<CSW_P228) | (1<<CSW_ELITE) | (1<<CSW_FIVESEVEN) | (1<<CSW_USP) | (1<<CSW_GLOCK18) | (1<<CSW_DEAGLE))
//offsets
#define OFFSET_AWM_AMMO 377
#define OFFSET_SCOUT_AMMO 378
#define OFFSET_PARA_AMMO 379
#define OFFSET_FAMAS_AMMO 380
#define OFFSET_M3_AMMO 381
#define OFFSET_USP_AMMO 382
#define OFFSET_FIVESEVEN_AMMO 383
#define OFFSET_DEAGLE_AMMO 384
#define OFFSET_P228_AMMO 385
#define OFFSET_GLOCK_AMMO 386
#define OFFSET_FLASH_AMMO 387
#define OFFSET_HE_AMMO 388
#define OFFSET_SMOKE_AMMO 389
#define OFFSET_C4_AMMO 390
#define linuxdiff 5
//ammo for each gun
#define AMMO_P228 52
#define AMMO_SCOUT 90
#define AMMO_Xm1014 32
#define AMMO_Mac10 100
#define AMMO_Aug 90
#define AMMO_Elite 120
#define AMMO_Fiveseven 100
#define AMMO_Ump45 100
#define AMMO_Sg550 90
#define AMMO_Galil 90
#define AMMO_Famas 90
#define AMMO_Usp 100
#define AMMO_Glock18 120
#define AMMO_Awp 30
#define AMMO_Mp5navy 120
#define AMMO_M249 200
#define AMMO_M3 32
#define AMMO_M4a1 90
#define AMMO_Tmp 120
#define AMMO_G3sg1 90
#define AMMO_Deagle 35
#define AMMO_Sg552 90
#define AMMO_Ak47 90
#define AMMO_P90 100
//array whit primary and secondary weapons
new const Secondary[] = {CSW_P228, CSW_ELITE, CSW_FIVESEVEN, CSW_USP, CSW_GLOCK18, CSW_DEAGLE};
new const Primary[]={CSW_SCOUT,CSW_XM1014,CSW_MAC10,CSW_AUG,CSW_UMP45,CSW_SG550,CSW_GALIL,CSW_FAMAS,CSW_AWP,CSW_MP5NAVY,CSW_M249,CSW_M3,CSW_M4A1,CSW_TMP,CSW_G3SG1,CSW_SG552,CSW_AK47,CSW_P90}
//will store the weapon id after picking it on menu
new Selected
new pcvar,Float:Time
public plugin_init()
{
register_plugin("Weapon Spawner", "1.3", "Fxfighter")
register_clcmd("ws_menu","Menu")
pcvar = register_cvar("ws_auto_remove","0")
if(get_pcvar_num(pcvar))remove_normal()
pcvar = register_cvar("ws_auto_load","1")
if(get_pcvar_num(pcvar))load()
//regisetr reset cvar and get its value
pcvar = register_cvar("ws_reset_round","1")
if(get_pcvar_num(pcvar))
{
register_logevent("reset", 2, "1=Round_End")
register_event("TextMsg", "reset", "a", "2=#Game_will_restart_in")
}
pcvar = register_cvar("ws_reset_gun","0")
if(get_pcvar_num(pcvar))
{
register_forward(FM_Think, "Forward_Think")
pcvar = register_cvar("ws_reset_gun_time","10")
Time = get_pcvar_float(pcvar)
pcvar = register_cvar("ws_reset_gun_amount","10")
pcvar = get_pcvar_num(pcvar)
}
register_forward(FM_Touch,"Equip")
}
public Equip(id,weapon)
{
if(!pev_valid(weapon) || !pev_valid(id) )return
static classname
pev(weapon, pev_classname, classname,19)
if(!equal(classname,wp_ent))return
static left,type,i
left = pev(weapon,WP_Left)
if(!left)return
type = pev(weapon,WP_Type)
//check if its a primary
if(PRIMARY_WEAPONS & ( 1 << type))
{
for (i = 0; i < sizeof Primary; ++i)
{
//cant have more then 1 primary
if(user_has_weapon(id,Primary))return
}
}
//check if its secondary
else if(SECONDARY_WEAPONS & ( 1 << type))
{
for (i = 0; i < sizeof Secondary; ++i)
{
//cant have more then 2 secondary
if(user_has_weapon(id,Secondary))return
}
}
//if its armor
else if(type == 31||type==32)
{
//cant have moret hen 100 in armor
if(pev(id,pev_armorvalue) == 100.0)return
}
//if its granade or knife and he already got one
else if(user_has_weapon(id,type))return
//give weapon and ammo
switch(type)
{
case 1 :
{
fm_give_item(id,"weapon_p228")
set_pdata_int(id,OFFSET_P228_AMMO,AMMO_P228,linuxdiff)
}
case 2 :fm_give_item(id,"weapon_shield")
case 3 :
{
fm_give_item(id,"weapon_scout")
set_pdata_int(id,OFFSET_SCOUT_AMMO,AMMO_SCOUT,linuxdiff)
}
case 4 :
{
fm_give_item(id,"weapon_hegrenade")
//set_pdata_int(id,OFFSET_HE_AMMO,amount,linuxdiff)
}
case 5 :
{
fm_give_item(id,"weapon_xm1014")
set_pdata_int(id,OFFSET_M3_AMMO,AMMO_Xm1014,linuxdiff)
}
case 7 :
{
fm_give_item(id,"weapon_mac10")
set_pdata_int(id,OFFSET_USP_AMMO,AMMO_Mac10,linuxdiff)
}
case 8 :
{
fm_give_item(id,"weapon_aug")
set_pdata_int(id,OFFSET_FAMAS_AMMO,AMMO_Aug,linuxdiff)
}
case 9 :
{
fm_give_item(id,"weapon_smokegrenade")
//set_pdata_int(id,OFFSET_SMOKE_AMMO,amount,linuxdiff)
}
case 10:
{
fm_give_item(id,"weapon_elite")
set_pdata_int(id,OFFSET_GLOCK_AMMO,AMMO_Elite,linuxdiff)
}
case 11:
{
fm_give_item(id,"weapon_fiveseven")
set_pdata_int(id,OFFSET_FIVESEVEN_AMMO,AMMO_Fiveseven,linuxdiff)
}
case 12:
{
fm_give_item(id,"weapon_ump45")
set_pdata_int(id,OFFSET_USP_AMMO,AMMO_Ump45,linuxdiff)
}
case 13:
{
fm_give_item(id,"weapon_sg550")
set_pdata_int(id,OFFSET_FAMAS_AMMO,AMMO_Sg550,linuxdiff)
}
case 14:
{
fm_give_item(id,"weapon_galil")
set_pdata_int(id,OFFSET_FAMAS_AMMO,AMMO_Galil,linuxdiff)
}
case 15:
{
fm_give_item(id,"weapon_famas")
set_pdata_int(id,OFFSET_FAMAS_AMMO,AMMO_Famas,linuxdiff)
}
case 16:
{
fm_give_item(id,"weapon_usp")
set_pdata_int(id,OFFSET_USP_AMMO,AMMO_Usp,linuxdiff)
}
case 17:
{
fm_give_item(id,"weapon_glock18")
set_pdata_int(id,OFFSET_GLOCK_AMMO,AMMO_Glock18,linuxdiff)
}
case 18:
{
fm_give_item(id,"weapon_awp")
set_pdata_int(id,OFFSET_AWM_AMMO,AMMO_Awp,linuxdiff)
}
case 19:
{
fm_give_item(id,"weapon_mp5navy")
set_pdata_int(id,OFFSET_GLOCK_AMMO,AMMO_Mp5navy,linuxdiff)
}
case 20:
{
fm_give_item(id,"weapon_m249")
set_pdata_int(id,OFFSET_PARA_AMMO,AMMO_M249,linuxdiff)
}
case 21:
{
fm_give_item(id,"weapon_m3")
set_pdata_int(id,OFFSET_M3_AMMO,AMMO_M3,linuxdiff)
}
case 22:
{
fm_give_item(id,"weapon_m4a1")
set_pdata_int(id,OFFSET_FAMAS_AMMO,AMMO_M4a1,linuxdiff)
}
case 23:
{
fm_give_item(id,"weapon_tmp")
set_pdata_int(id,OFFSET_GLOCK_AMMO,AMMO_Tmp,linuxdiff)
}
case 24:
{
fm_give_item(id,"weapon_g3sg1")
set_pdata_int(id,OFFSET_SCOUT_AMMO,AMMO_G3sg1,linuxdiff)
}
case 25:
{
fm_give_item(id,"weapon_flashbang")
//set_pdata_int(id,OFFSET_FLASH_AMMO,amount,linuxdiff)
}
case 26:
{
fm_give_item(id,"weapon_deagle")
set_pdata_int(id,OFFSET_DEAGLE_AMMO,AMMO_Deagle,linuxdiff)
}
case 27:
{
fm_give_item(id,"weapon_sg552")
set_pdata_int(id,OFFSET_FAMAS_AMMO,AMMO_Sg552,linuxdiff)
}
case 28:
{
fm_give_item(id,"weapon_ak47")
set_pdata_int(id,OFFSET_SCOUT_AMMO,AMMO_Ak47,linuxdiff)
}
case 29:fm_give_item(id,"weapon_knife")
case 30:
{
fm_give_item(id,"weapon_p90")
set_pdata_int(id,OFFSET_FIVESEVEN_AMMO,AMMO_P90,linuxdiff)
}
case 31:fm_give_item(id,"item_kevlar")
case 32:fm_give_item(id,"item_assaultsuit")
}
//lower the weapons number whit 1
left-=1
set_pev(weapon,WP_Left,left)
//set refill
if(pcvar != 0)set_pev(weapon, pev_nextthink, get_gametime() + Time)
//if nothing left make invisiable
if(!left)
{
set_pev(weapon, pev_renderfx, kRenderFxNone)
set_pev(weapon, pev_rendercolor, {0.0,0.0,0.0})
set_pev(weapon, pev_rendermode, kRenderTransAlpha)
set_pev(weapon, pev_renderamt, 0.0)
}
} 本帖最后由 123315517 于 2022-12-11 11:17 编辑
public Forward_Think(ent)
{
if(!pev_valid(ent))return
static classname
pev(ent, pev_classname, classname, 31)
//not our weapon
if(!equal(classname, wp_ent))return
//get values
classname = pev(ent,WP_Max)
classname = pev(ent,WP_Left)
//if its full return
if(classname == classname)return
//if invisiable
if(!classname)
{
set_pev(ent, pev_renderfx, kRenderNormal)
set_pev(ent, pev_rendercolor, {255.0,255.0,255.0})
set_pev(ent, pev_rendermode, kRenderTransAlpha)
set_pev(ent, pev_renderamt, 255.0)
}
//add
classname +=pcvar
//set it
if(classname > classname)set_pev(ent,WP_Left,classname)
else set_pev(ent,WP_Left,classname)
if(classname != classname)set_pev(ent, pev_nextthink, get_gametime() + Time)
}
public Menu(id,nr)
{
//not havign kick flag
if(!(get_user_flags(id, 0) & ADMIN_KICK))return PLUGIN_CONTINUE
new menu
switch(nr)
{
//pages
case 1:
{
menu = menu_create("\rSpawn A Weapon", "handler")
menu_additem(menu, "Rifles", "110" , 0)
menu_additem(menu, "Pistols", "111" , 0)
menu_additem(menu, "Others", "112" , 0)
}
case 2:
{
menu = menu_create("\rRifles", "handler")
menu_additem(menu, "Scout","3" , 0)
menu_additem(menu, "Autoshotgun","5" , 0)
menu_additem(menu, "Mac10","7" , 0)
menu_additem(menu, "Bullpup","8" , 0)
menu_additem(menu, "Ump45","12" , 0)
menu_additem(menu, "Krieg550","13" , 0)
menu_additem(menu, "Defender","14" , 0)
menu_additem(menu, "Clarion","15" , 0)
menu_additem(menu, "Awp","18" , 0)
menu_additem(menu, "Mp5","19", 0)
menu_additem(menu, "M249","20" , 0)
menu_additem(menu, "M3","21" , 0)
menu_additem(menu, "M4A1","22" , 0)
menu_additem(menu, "TMP","23", 0)
menu_additem(menu, "G3SG1","24" , 0)
menu_additem(menu, "sg552","27" , 0)
menu_additem(menu, "ak47","28" , 0)
menu_additem(menu, "P90","30", 0)
}
case 3:
{
menu = menu_create("\rPistols", "handler")
menu_additem(menu, "228compact","1",0)
menu_additem(menu, "fiveseven", "11" , 0)
menu_additem(menu, "usp", "16" , 0)
menu_additem(menu, "glock ", "17" , 0)
menu_additem(menu, "deagle", "26" , 0)
menu_additem(menu, "elite", "10" , 0)
}
case 4:
{
menu = menu_create("\rOthers", "handler")
menu_additem(menu, "hegrenade","4" , 0)
menu_additem(menu, "smokegrenade","9" , 0)
menu_additem(menu, "flashbang","25" , 0)
menu_additem(menu, "knife","29" , 0)
menu_additem(menu, "kevlar","31" , 0)
menu_additem(menu, "assaultsuit","32" , 0)
}
case 5:
{
menu = menu_create("\rNumber of Weapons", "handler")
menu_additem(menu, "1", "105" , 0)
menu_additem(menu, "2", "105" , 0)
menu_additem(menu, "3", "105" , 0)
menu_additem(menu, "4", "105" , 0)
menu_additem(menu, "5", "105" , 0)
menu_additem(menu, "10", "105" , 0)
menu_additem(menu, "15", "105" , 0)
menu_additem(menu, "20", "105" , 0)
menu_additem(menu, "30", "105" , 0)
menu_additem(menu, "40", "105" , 0)
menu_additem(menu, "50", "105" , 0)
menu_additem(menu, "75", "105" , 0)
menu_additem(menu, "100","105" , 0)
menu_additem(menu, "200","105" , 0)
}
default:{
menu = menu_create("\rWeapon Spawner", "handler")
menu_additem(menu, "Create A Spawn","100", 0)
menu_additem(menu, "Save Spawns","101", 0)
menu_additem(menu, "Load Spawns","102", 0)
menu_additem(menu, "Remove all normal Spawns","103", 0)
menu_additem(menu, "Remove all costum Spawns","104", 0)
}
}
//show menu
menu_setprop(menu , MPROP_EXIT , MEXIT_ALL)
menu_display(id , menu , 0)
return PLUGIN_HANDLED
}
public handler(id, menu, item)
{
//if hes dead or he choiced exit close
if(item == MENU_EXIT||!is_user_alive(id))
{
menu_destroy(menu)
return
}
//get info
new data, iName
new access, callback
menu_item_getinfo(menu, item, access, data,4, iName, 10, callback)
data = str_to_num(data)
switch(data)
{
case 1..32:
{
Selected = data
Menu(id,5)
}
case 100:Menu(id,1)
case 110:Menu(id,2)
case 111:Menu(id,3)
case 112:Menu(id,4)
case 101:
{
save()
Menu(id,0)
client_print(id,print_chat," All costum spawns have been saved")
}
case 102:
{
load()
Menu(id,0)
client_print(id,print_chat," All costum spawns have been loaded")
}
case 103:
{
Menu(id,0)
remove_normal()
client_print(id,print_chat," All normal spawns have been removed")
}
case 104:
{
Menu(id,0)
remove_costum()
client_print(id,print_chat," All costum spawns have been removed")
}
case 105:
{
Menu(id,0)
new Float:origin
pev(id,pev_origin,origin)
origin+=30.0
set_pev(id,pev_origin,origin)
origin-=30.0
create_weapon(Selected,str_to_num(iName),origin)
client_print(id,print_chat," You have created a new spawn")
}
}
menu_destroy(menu)
}
public remove_normal()
{
new weapon
while((weapon = engfunc(EngFunc_FindEntityByString, weapon, "classname", "armoury_entity")) != 0)if(!pev(weapon,WP_Type))engfunc(EngFunc_RemoveEntity,weapon)
}
public remove_costum()
{
new weapon
while((weapon = engfunc(EngFunc_FindEntityByString, weapon, "classname", wp_ent)) != 0)if(pev(weapon,WP_Type)!= 0)engfunc(EngFunc_RemoveEntity,weapon)
}
public load()
{
new config,Info,map,data,Float:origin
get_configsdir(config,29)
get_mapname(map,29)
formatex(config,49,"%s/ws/%s.ini",config,map)
if(!file_exists(config))return
new File = fopen(config,"r")
if(File)
{
while(fgets(File,Info,40))
{
parse(Info, data, 5, data, 5,data, 10, data, 10, data, 10)
if(!data)data = 48
origin = str_to_float(data)
origin = str_to_float(data)
origin = str_to_float(data)
create_weapon(str_to_num(data),str_to_num(data),origin)
}
}
fclose(File)
}
public reset()
{
new value,weapon
while((weapon = engfunc(EngFunc_FindEntityByString, weapon, "classname", wp_ent)) != 0)
{
value=pev(weapon,WP_Left)
if(!value)
{
set_pev(weapon, pev_renderfx, kRenderNormal)
set_pev(weapon, pev_rendercolor, {255.0,255.0,255.0})
set_pev(weapon, pev_rendermode, kRenderTransAlpha)
set_pev(weapon, pev_renderamt, 255.0)
}
value=pev(weapon,WP_Max)
set_pev(weapon,WP_Left,value)
}
}
public save()
{
new config,Info,map,Float:origin
get_configsdir(config,29)
get_mapname(map,29)
formatex(config,49,"%s/ws/%s.ini",config,map)
if(file_exists(config))delete_file(config)
new File = fopen(config,"w")
if(File)
{
new weapon
while((weapon = engfunc(EngFunc_FindEntityByString, weapon, "classname", wp_ent)) != 0)
{
pev(weapon,pev_origin,origin)
formatex(Info,40,"%i %i %.2f %.2f %.2f",pev(weapon,WP_Type),pev(weapon,WP_Max),origin,origin,origin)
write_file(config,Info,-1)
}
}
fclose(File)
}
public create_weapon(wid,count,Float:origin[])
{
new weapon = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "func_wall"))
set_pev(weapon,pev_classname, wp_ent)
switch(wid)
{
case 1:engfunc(EngFunc_SetModel, weapon, "models/w_p228.mdl")
case 2:engfunc(EngFunc_SetModel, weapon, "models/w_shield.mdl")
case 3:engfunc(EngFunc_SetModel, weapon, "models/w_scout.mdl")
case 4:engfunc(EngFunc_SetModel, weapon, "models/w_hegrenade.mdl")
case 5:engfunc(EngFunc_SetModel, weapon, "models/w_xm1014.mdl")
case 7:engfunc(EngFunc_SetModel, weapon, "models/w_mac10.mdl")
case 8:engfunc(EngFunc_SetModel, weapon, "models/w_aug.mdl")
case 9:engfunc(EngFunc_SetModel, weapon, "models/w_smokegrenade.mdl")
case 10:engfunc(EngFunc_SetModel, weapon, "models/w_elite.mdl")
case 11:engfunc(EngFunc_SetModel, weapon, "models/w_fiveseven.mdl")
case 12:engfunc(EngFunc_SetModel, weapon, "models/w_ump45.mdl")
case 13:engfunc(EngFunc_SetModel, weapon, "models/w_sg550.mdl")
case 14:engfunc(EngFunc_SetModel, weapon, "models/w_galil.mdl")
case 15:engfunc(EngFunc_SetModel, weapon, "models/w_famas.mdl")
case 16:engfunc(EngFunc_SetModel, weapon, "models/w_usp.mdl")
case 17:engfunc(EngFunc_SetModel, weapon, "models/w_glock18.mdl")
case 18:engfunc(EngFunc_SetModel, weapon, "models/w_awp.mdl")
case 19:engfunc(EngFunc_SetModel, weapon, "models/w_mp5navy.mdl")
case 20:engfunc(EngFunc_SetModel, weapon, "models/w_m249.mdl")
case 21:engfunc(EngFunc_SetModel, weapon, "models/w_m3.mdl")
case 22:engfunc(EngFunc_SetModel, weapon, "models/w_m4a1.mdl")
case 23:engfunc(EngFunc_SetModel, weapon, "models/w_tmp.mdl")
case 24:engfunc(EngFunc_SetModel, weapon, "models/w_g3sg1.mdl")
case 25:engfunc(EngFunc_SetModel, weapon, "models/w_flashbang.mdl")
case 26:engfunc(EngFunc_SetModel, weapon, "models/w_deagle.mdl")
case 27:engfunc(EngFunc_SetModel, weapon, "models/w_sg552.mdl")
case 28:engfunc(EngFunc_SetModel, weapon, "models/w_ak47.mdl")
case 29:engfunc(EngFunc_SetModel, weapon, "models/w_knife.mdl")
case 30:engfunc(EngFunc_SetModel, weapon, "models/w_p90.mdl")
case 31:engfunc(EngFunc_SetModel, weapon, "models/w_kevlar.mdl")
case 32:engfunc(EngFunc_SetModel, weapon, "models/w_assault.mdl")
}
engfunc(EngFunc_SetSize, weapon, {-0.2,-0.2,-0.2},{0.2,0.2,0.2})
set_pev(weapon,pev_solid,2) // 武器捡不起
set_pev(weapon,pev_origin,origin) //origin pev_origin
set_pev(weapon,WP_Type,wid)
set_pev(weapon,WP_Left,count)
set_pev(weapon,WP_Max,count)
engfunc(EngFunc_DropToFloor, weapon)
} 本帖最后由 123315517 于 2022-12-10 14:32 编辑
stock fm_set_kvd(entity, const key[], const value[], const classname[] = "")
{
if (classname)set_kvd(0, KV_ClassName, classname)
else
{
new class
pev(entity, pev_classname, class, sizeof class - 1)
set_kvd(0, KV_ClassName, class)
}
set_kvd(0, KV_KeyName, key)
set_kvd(0, KV_Value, value)
set_kvd(0, KV_fHandled, 0)
return dllfunc(DLLFunc_KeyValue, entity, 0)
}
stock fm_give_item(index, const item[])
{
new ent =engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item))
if (!pev_valid(ent))return 0;
new Float:origin;
pev(index, pev_origin, origin);
set_pev(ent, pev_origin, origin);
set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN);
dllfunc(DLLFunc_Spawn, ent);
new save = pev(ent, pev_solid);
dllfunc(DLLFunc_Touch, ent, index);
if(pev(ent, pev_solid) != save)return ent;
engfunc(EngFunc_RemoveEntity, ent);
return -1;
} set_pev(weapon,pev_solid,2)把2改为1 zhangsheng 发表于 2022-12-9 12:39
set_pev(weapon,pev_solid,2)把2改为1
改了之后,人物经过不绊脚了,但是武器又捡不起来了。 zhangsheng 发表于 2022-12-9 12:39
set_pev(weapon,pev_solid,2)把2改为1
十分感谢指出问题所在,把上面的映射大小改小后完美解决。
{:6_201:}
页:
[1]