你的人 发表于 2006-12-3 04:36:15

代码求助

下列是我的代码
我做了一个c4随机奖励武器
我不知道怎么做到,手上已经有武器的..
随机奖励武器,刚好奖励你手上的武器
怎么做到不奖励你已经有的武器呢??

#include <amxmodx>
#include <cstrike>
#include <engine>
#include <csx>
#include <fun>
new primary_weapon
new name
new id
new weapon
new ammo_type
new gBombReward = 1
public plugin_init()
{
register_plugin("C4成功拆除或爆炸,随机奖励武器", "0.1", "你的人")
register_concmd("amx_bombreward","admin_bombreward",0,"C4成功拆除或爆炸,随机奖励武器 <1 | 0 >")
}
public admin_bombreward(id,level,cid)
{
if (!(get_user_flags(id)&ADMIN_IMMUNITY)){
client_print(id, print_console, "你没有权限执行这个参数")
return PLUGIN_HANDLED
}
if (read_argc() < 2)
{
console_print(id,"使用方法: amx_bombreward < 1 | 0 >")
return PLUGIN_HANDLED
}
new bombtarget = find_ent_by_class(-1, "func_bomb_target")
if ( !bombtarget )
{
gBombReward = 0
console_print(id,"此地图没有炸弹安装点^nC4成功拆除或爆炸,随机奖励武器 - 已关闭")
}
new sArg1
read_argv(1,sArg1,31)
if (str_to_num(sArg1) == 1)
{
if ( bombtarget )
{
   gBombReward = 1
   client_print(id,print_console,"C4成功拆除或爆炸,随机奖励武器 - 已开启.")
   client_print(0,print_chat,"C4成功拆除或爆炸,随机奖励武器 - 已开启.")
}
}
if (str_to_num(sArg1) == 0)
{
if ( bombtarget )
{
   gBombReward = 0
   client_print(id,print_console,"C4成功拆除或爆炸,随机奖励武器 - 已关闭.")
   client_print(0,print_chat,"C4成功拆除或爆炸,随机奖励武器 - 已关闭.")
}
}
if ( str_to_num(sArg1) > 1 )
{
console_print(id,"使用方法: amx_bombreward < 1 | 0 >")
}
return PLUGIN_HANDLED
}
public bomb_explode(planter, defuser)
{
if (gBombReward == 0)
{
}
if (gBombReward)
{
get_user_name(planter,name,31)
randomize_primary(id)
get_weaponname(primary_weapon, weapon, 20)
give_item(planter, weapon)
ammo_type = get_ammotype(primary_weapon)
give_item(planter, ammo_type)
give_item(planter, ammo_type)
set_hudmessage(200,200,200,-1.0,0.40,0,6.0,6.0,0.5,0.15,2)
show_hudmessage(0,"C4爆炸成功,奖励%s给予%s", weapon, name)
client_print(id, print_chat, "C4爆炸成功,奖励%s给予%s", weapon, name)
}
}
public bomb_defused (defuser)
{
if (gBombReward == 0)
{
}
if (gBombReward)
{
get_user_name(defuser,name,31)
randomize_primary(id)
get_weaponname(primary_weapon, weapon, 20)
give_item(defuser, weapon)
ammo_type = get_ammotype(primary_weapon)
give_item(defuser, ammo_type)
give_item(defuser, ammo_type)
set_hudmessage(200,200,200,-1.0,0.40,0,6.0,6.0,0.5,0.15,2)
show_hudmessage(0,"C4成功拆除,奖励%s给予%s", weapon, name)
client_print(id, print_chat, "C4成功拆除,奖励%s给予%s", weapon, name)
}
}
public randomize_primary(id)
{
new rand = random_num(1, 18)

switch(rand)
{   
case 1: primary_weapon = CSW_SCOUT

case 2: primary_weapon = CSW_XM1014

case 3: primary_weapon = CSW_MAC10

case 4: primary_weapon = CSW_AUG

case 5: primary_weapon = CSW_UMP45

case 6: primary_weapon = CSW_SG550

case 7: primary_weapon = CSW_FAMAS

case 8: primary_weapon = CSW_AWP
         
case 9: primary_weapon = CSW_MP5NAVY

         case 10: primary_weapon = CSW_M249

case 11: primary_weapon = CSW_M3

case 12: primary_weapon = CSW_M4A1

case 13: primary_weapon = CSW_TMP

case 14: primary_weapon = CSW_G3SG1

case 15: primary_weapon = CSW_SG552

         case 16: primary_weapon = CSW_AK47

case 17: primary_weapon = CSW_P90

case 18: primary_weapon = CSW_HEGRENADE
}

return PLUGIN_CONTINUE
}
stock get_ammotype(weapon)
{
new ammo

switch(weapon)
{
case CSW_SCOUT: ammo = "ammo_762nato"
case CSW_XM1014: ammo = "ammo_buckshot"
case CSW_MAC10: ammo = "ammo_45acp"
case CSW_AUG: ammo = "ammo_556nato"
case CSW_UMP45: ammo = "ammo_45acp"
case CSW_SG550: ammo = "ammo_556nato"
case CSW_FAMAS: ammo = "ammo_556nato"
case CSW_AWP: ammo = "ammo_338magnum"
case CSW_MP5NAVY: ammo = "ammo_9mm"
case CSW_M249: ammo = "ammo_556natobox"
case CSW_M3: ammo = "ammo_buckshot"
case CSW_M4A1: ammo = "ammo_556nato"
case CSW_TMP: ammo = "ammo_9mm"
case CSW_G3SG1: ammo = "ammo_762nato"
case CSW_SG552: ammo = "ammo_556nato"
case CSW_AK47: ammo = "ammo_762nato"
case CSW_P90: ammo = "ammo_57mm"
}

return ammo
}

jim_yang 发表于 2006-12-3 11:22:44

回复: 代码求助

get_user_weapons

你的人 发表于 2006-12-3 12:00:34

回复: 代码求助

Post by jim_yang
get_user_weapons
我已經想過用get_user_weapons
但是我不懂用這涵數= ="

jim_yang 发表于 2006-12-3 12:07:03

回复: 代码求助

Syntax:

   get_user_weapons ( index, weapons, &num ) Type:

    Native Notes:

index is a player index from 1 to 32.

The weapons array passed as the second parameter is filled with a list of weapon indices, from 0 to num-1. num will be filled with the number of weapons found (passed byref).

Example:
new Weapons
new numWeapons, i, weapon
get_user_weapons(id, Weapons, numWeapons)
for (i=0; i<numWeapns; i++)
{
   weapon = Weapons
}
页: [1]
查看完整版本: 代码求助