Перевод кода на reapi

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
95
Реакции
6
Помог
2 раз(а)
Ошибка
error 017: undefined symbol "pev"
Компилятор
Локальный
Amx Mod X
1.9.0
Исходный код
public fw_TouchGrenade(entity, toucher)
{
get_entvar
if (is_health_grenade(entity) && (pev_valid(entity) != 2 || pev(toucher, pev_solid) > SOLID_TRIGGER)) {
grenade_explode(entity);
}
}
Помогите перевести на reapi
 
В этой теме было размещено решение! Перейти к решению.

d3m37r4

111111
Сообщения
1,454
Реакции
1,194
Помог
10 раз(а)
ka4a, за место pev используй get_entvar, pev_valid, думаю найдешь чем заменить, почитав инклуды reapi.
Да и цель бы этих действий сказал бы. Может оно того не стоит.
 
Сообщения
95
Реакции
6
Помог
2 раз(а)
d3m37r4, цель наткнулся на плагин, и решил переделать под reapi ибо уменьшить кол-ва кода и нагрузки
 

d3m37r4

111111
Сообщения
1,454
Реакции
1,194
Помог
10 раз(а)
ka4a, думаешь, если просто все нативы заменишь на нативы reapi нагрузка меньше будет?
уменьшить кол-ва кода
p.s. наименьшее кол-во кода - не показатель нагрузки или чего либо еще.
 
Сообщения
95
Реакции
6
Помог
2 раз(а)
d3m37r4, Может это и не даст ни чего, а научиться хочется..
p.s я мало понимаю в reapi и мне очень хочется научиться, поэтому интересный мне код переделываю
 
Сообщения
2,491
Реакции
2,794
Помог
61 раз(а)
ka4a, количество кода не пропорцианольно нагрузке
 
Сообщения
2,751
Реакции
3,017
Помог
61 раз(а)
Оптимизация, особенно преждевременная - враг.
 
Сообщения
95
Реакции
6
Помог
2 раз(а)
wopox1337, сейчас пришлю исходник из которого переделываю на reapi
Код:
#include <amxmodx>
#include <fm_cstrike>
#include <fun>

#define get_bit(%1,%2)   (%1 & (1 << (%2 & 31)))
#define set_bit(%1,%2)   %1 |= (1 << (%2 & 31))
#define clr_bit(%1,%2)   %1 &= ~(1 << (%2 & 31))
#define inv_bit(%1,%2)   %1 ^= (1 << (%2 & 31))

#define is_valid_client(%0)       ((0 < (%0) <= max_players) && get_bit(ingame, %0))
#define is_teams_equal(%0,%1)     (get_user_team(%0) == get_user_team(%1))
#define get_bpammo(%0,%1)         get_pdata_int(%0, _CSW_to_offset[%1], 5)
#define set_bpammo(%0,%1,%2)      set_pdata_int(%0, _CSW_to_offset[%1], %2, 5)
#define get_owner(%0)             get_pdata_cbase(%0, 41, 4)
#define WRITE_COORD(%0)           engfunc(EngFunc_WriteCoord,%0[0]);engfunc(EngFunc_WriteCoord, %0[1]); engfunc(EngFunc_WriteCoord, %0[2])
#define UTIL_RemoveEntity(%0)     set_pev(%0, pev_flags, FL_KILLME);set_pev(%0, pev_targetname, "")
#define is_health_grenade(%0)    (pev(%0, pev_iuser2) == CSW_HEALTH_GRENADE)

const MAX_CLIENTS        = 32;
const POST               = 1;
const CSW_HEALTH_GRENADE = 76263;

enum
{
  GRENADE_RADIUS             = 250.0,
  GRENADE_HEALTH             = 100,
  GRENADE_MAXHEALTH          = 100,
  GRENADE_FLAG               = ADMIN_LEVEL_H,
  GRENADE_COLORFADE_RED      = 0,
  GRENADE_COLORFADE_GREEN    = 255,
  GRENADE_COLORFADE_BLUE     = 0,
  GRENADE_RENDER_COLOR_RED   = 124.0,
  GRENADE_RENDER_COLOR_GREEN = 252.0,
  GRENADE_RENDER_COLOR_BLUE  = 0.0
}

enum
{
  GIBS_COUNT    = 35,
  GIBS_LIFE_MIN = 15,
  GIBS_LIFE_MAX = 25,
  GIBS_SCALE    = 2
}

enum _: model_type
{
  VIEWPORT,
  PLAYER,
  WEAPONBOX
}

new const HEALTH_GRENADE_MODEL[model_type][] = {
  "models/v_health_grenade.mdl",
  "models/p_health_grenade.mdl",
  "models/w_health_grenade.mdl"
};

enum _: sprites
{
  GIBS_RED,
  GIBS_GREEN,
  GIBS_BLUE,
  HEAL
}

new const HEALTH_GRENADE_SPRITE[sprites][] = {
  "sprites/red.spr",
  "sprites/green.spr",
  "sprites/blue.spr",
  "sprites/heal_effect.spr"
};

new const SOUND_EXPLODE[] = "health_grenade_explosion.wav";
new max_players, ingame, need_auto_eqip, gmsgScreenFade, sprite_index[sprites], have_health_grenade;

public plugin_init()
{
  register_plugin("Health Grenade", "1.1", "Autor");

  RegisterHam(Ham_Spawn, "player", "player_Spawn_Post", POST);
  RegisterHam(Ham_Touch, "grenade", "fw_TouchGrenade");
  RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "smokegrenade_Deploy_Post", POST);

  gmsgScreenFade = get_user_msgid("ScreenFade");
  max_players    = get_maxplayers();
}

public plugin_natives()
{
  register_native("give_health_grenade", "_give_health_grenade", 1);
  register_native("get_hg_auto_equip_status", "_get_hg_auto_equip_status", 1);
  register_native("set_hg_auto_equip_status", "_set_hg_auto_equip_status", 1);
}

public _give_health_grenade(id)
{
  give_health_grenade(id);
}

public _get_hg_auto_equip_status(id)
{
  return get_bit(need_auto_eqip, id) ? 1 : 0;
}

public _set_hg_auto_equip_status(id, new_status)
{
  if (new_status) {
    set_bit(need_auto_eqip, id);
  }
  else {
    clr_bit(need_auto_eqip, id);
  }
}

public plugin_precache()
{
  new i, error_index = -1;

  for (; i < sizeof HEALTH_GRENADE_MODEL; i++) {
    if (file_exists(HEALTH_GRENADE_MODEL[i])) {
      precache_model(HEALTH_GRENADE_MODEL[i]);
    }
    else {
      error_index = i;
      break;
    }
  }

  if (error_index == -1) {
    log_amx("[OK] All models precached successfully");
  }
  else {
    log_amx("[:(] Error opening ^"%s^" file", HEALTH_GRENADE_MODEL[i]);
    pause("ad");
  }

  i = 0;
  error_index = -1;

  for(; i < sizeof HEALTH_GRENADE_SPRITE; i++) {
    if (file_exists(HEALTH_GRENADE_SPRITE[i])) {
      sprite_index[i] = precache_model(HEALTH_GRENADE_SPRITE[i]);
    }
    else {
      error_index = i;
      break;
    }
  }

  if (error_index == -1) {
    log_amx("[OK] All sprites precached successfully");
  }
  else {
    log_amx("[:(] Error opening ^"%s^" file", HEALTH_GRENADE_SPRITE[i]);
    pause("ad");
  }

  precache_sound(SOUND_EXPLODE);
}

public client_putinserver(id)
{
  set_bit(ingame, id);
  clr_bit(have_health_grenade, id);
  set_bit(need_auto_eqip, id);
}

public client_disconnect(id)
{
  clr_bit(ingame, id);
}

public player_Spawn_Post(id)
{
  if (!is_user_alive(id)) {
    return;
  }

  if (get_bit(need_auto_eqip, id) && get_user_flags(id) & GRENADE_FLAG) {
    give_health_grenade(id);
  }
}

give_health_grenade(id)
{
  if (user_has_weapon(id, CSW_SMOKEGRENADE)) {
    set_bpammo(id, CSW_SMOKEGRENADE, get_bpammo(id, CSW_SMOKEGRENADE) + 1);
  }
  else {
    give_item(id, "weapon_smokegrenade");
  }

  set_bit(have_health_grenade, id);
}

public smokegrenade_Deploy_Post(entity)
{
  static owner; owner = get_owner(entity);

  if (is_valid_client(owner) && get_bit(have_health_grenade, owner)) {
    set_pev(owner, pev_viewmodel2  , HEALTH_GRENADE_MODEL[VIEWPORT]);
    set_pev(owner, pev_weaponmodel2, HEALTH_GRENADE_MODEL[PLAYER]);
  }

  return HAM_IGNORED;
}

public grenade_throw(id, grenade_entity, weaponid)
{
  if (weaponid == CSW_SMOKEGRENADE && get_bit(have_health_grenade, id)) {
    set_pev(grenade_entity, pev_renderfx, kRenderFxGlowShell);
    set_pev(grenade_entity, pev_rendercolor, Float: {GRENADE_RENDER_COLOR_RED, GRENADE_RENDER_COLOR_GREEN, GRENADE_RENDER_COLOR_BLUE});
    set_pev(grenade_entity, pev_rendermode, kRenderNormal);
    set_pev(grenade_entity, pev_renderamt, 25.0);
   
    engfunc(EngFunc_SetModel, grenade_entity, HEALTH_GRENADE_MODEL[WEAPONBOX]);
    set_pev(grenade_entity, pev_iuser2, CSW_HEALTH_GRENADE);
    clr_bit(have_health_grenade, id);
  }
}

public fw_TouchGrenade(entity, toucher)
{
  if (is_health_grenade(entity) && (pev_valid(entity) != 2 || pev(toucher, pev_solid) > SOLID_TRIGGER)) {
    grenade_explode(entity);
  }
}

public grenade_explode(grenade_entity)
{
  static grenade_owner, victim, Float: grenade_origin[3], Float: origin[3];
  grenade_owner = pev(grenade_entity, pev_owner);

  if (is_valid_client(grenade_owner)) {
    pev(grenade_entity, pev_origin, grenade_origin);
    make_gibs(grenade_origin);
    emit_sound(grenade_entity, CHAN_ITEM, SOUND_EXPLODE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
   
    victim  = -1;
   
    while ((victim = engfunc( EngFunc_FindEntityInSphere, victim, grenade_origin, GRENADE_RADIUS)) != 0) {
      if (is_user_alive(victim) && is_teams_equal(victim, grenade_owner)) {
        set_user_health(victim, clamp(get_user_health(victim) + GRENADE_HEALTH, 1, GRENADE_MAXHEALTH));
       
        pev(victim, pev_origin, origin);
        origin[2]+= 30.0;
       
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(TE_SPRITE);
        WRITE_COORD(origin);
        write_short(sprite_index[HEAL]);
        write_byte(8);
        write_byte(255);
        message_end();
       
        message_begin(MSG_ONE_UNRELIABLE, gmsgScreenFade, .player = victim);
        write_short(1 << 12);
        write_short(0);
        write_short(0);
        write_byte(GRENADE_COLORFADE_RED);
        write_byte(GRENADE_COLORFADE_GREEN);
        write_byte(GRENADE_COLORFADE_BLUE);
        write_byte(80);
        message_end();
      }
    }
  }

  UTIL_RemoveEntity(grenade_entity);
}

make_gibs(Float:origin[3])
{
  static Float: start_pos[3], Float: end_pos[3];

  start_pos[0] = origin[0]; start_pos[1] = origin[1]; start_pos[2] = origin[2] + 150.0;
  end_pos[0]   = origin[0]; end_pos[1]   = origin[1]; end_pos[2]   = origin[2] + 10.0;

  message_begin (MSG_BROADCAST,SVC_TEMPENTITY);
  write_byte(TE_SPRITETRAIL);
  WRITE_COORD(start_pos);
  WRITE_COORD(end_pos);
  write_short(sprite_index[GIBS_BLUE]);
  write_byte(GIBS_COUNT);
  write_byte(random_num(GIBS_LIFE_MIN, GIBS_LIFE_MAX));
  write_byte(GIBS_SCALE);
  write_byte(50); // (velocity along vector in 10's)
  write_byte(10); // (randomness of velocity in 10's)
  message_end() ;

  message_begin (MSG_BROADCAST,SVC_TEMPENTITY);
  write_byte(TE_SPRITETRAIL);
  WRITE_COORD(start_pos);
  WRITE_COORD(end_pos);
  write_short(sprite_index[GIBS_GREEN]);
  write_byte(GIBS_COUNT);
  write_byte(random_num(GIBS_LIFE_MIN, GIBS_LIFE_MAX));
  write_byte(GIBS_SCALE);
  write_byte(50); // (velocity along vector in 10's)
  write_byte(10); // (randomness of velocity in 10's)
  message_end();

  message_begin (MSG_BROADCAST,SVC_TEMPENTITY);
  write_byte(TE_SPRITETRAIL);
  WRITE_COORD(start_pos);
  WRITE_COORD(end_pos);
  write_short(sprite_index[GIBS_RED]);
  write_byte(GIBS_COUNT);
  write_byte(random_num(GIBS_LIFE_MIN, GIBS_LIFE_MAX));
  write_byte(GIBS_SCALE);
  write_byte(50); // (velocity along vector in 10's)
  write_byte(10); // (randomness of velocity in 10's)
  message_end();
}
Пока что получается криво, но вот
Код:
#include <amxmodx>
#include <hamsandwich>
#include <reapi>

#define get_bit(%1,%2)   (%1 & (1 << (%2 & 31)))
#define set_bit(%1,%2)   %1 |= (1 << (%2 & 31))
#define clr_bit(%1,%2)   %1 &= ~(1 << (%2 & 31))
#define inv_bit(%1,%2)   %1 ^= (1 << (%2 & 31))

#define is_valid_client(%0)       ((0 < (%0) <= max_players) && get_bit(ingame, %0))
#define is_teams_equal(%0,%1)     (get_user_team(%0) == get_user_team(%1))
#define get_bpammo(%0,%1)         get_pdata_int(%0, _CSW_to_offset[%1], 5)
#define set_bpammo(%0,%1,%2)      set_pdata_int(%0, _CSW_to_offset[%1], %2, 5)
#define get_owner(%0)             get_pdata_cbase(%0, 41, 4)
#define WRITE_COORD(%0)           engfunc(EngFunc_WriteCoord,%0[0]);engfunc(EngFunc_WriteCoord, %0[1]); engfunc(EngFunc_WriteCoord, %0[2])
#define UTIL_RemoveEntity(%0)     set_pev(%0, pev_flags, FL_KILLME);set_pev(%0, pev_targetname, "")
#define WEAPON_UID 1
#define IsCustomWeapon(%1) bool:(get_entvar(%1, var_impulse) == WEAPON_UID)
#define is_health_grenade(%0)    (pev(%0, pev_iuser2) == CSW_HEALTH_GRENADE)

const CSW_HEALTH_GRENADE = 76263;

#define WEAPON_ID HEALTH_GRANAGE // ID оружия
#define WEAPON_NAME "granage" // Название оружия
#define MODEL_V "models/gold/v_m4a1.mdl" // Модель оружия. Закоментировать если не нужно
#define MODEL_P "models/gold/p_m4a1.mdl" // Модель оружия. Закоментировать если не нужно
#define MODEL_W "models/gold/w_m4a1.mdl" // Модель оружия. Закоментировать если не нужно

public plugin_native(){
    register_native("give_health_grenade", "give_health_grenade", 1);
}

public plugin_precache() {
    precache_model(MODEL_V);
    precache_model(MODEL_P);
    precache_model(MODEL_W);
}

public plugin_init() {
    register_plugin("WeaponCustomM4A1", "2.1", "Fantom");

    RegisterHam(Ham_Item_Deploy, WEAPON_NAME, "HookItemDeploy", 1);
    RegisterHookChain(RG_CWeaponBox_SetModel, "HookSetModel", 0);
    RegisterHam(Ham_Weapon_Reload, WEAPON_NAME, "HookReloaded", 0);
    RegisterHam(Ham_Touch, "weaponbox", "HookWeaponBoxTouch", 0);
}

public HookItemDeploy(weapon) {
    new id = get_member(weapon, m_pPlayer);
    if (!is_user_connected(id) || !IsCustomWeapon(weapon)) {
        return HAM_IGNORED;
    }
    set_entvar(id, var_viewmodel, MODEL_V);
    set_entvar(id, var_weaponmodel, MODEL_P);

    return HAM_IGNORED;
}

public HookSetModel(const weaponbox, const model[]) {
    new weapon = getWeaponBoxWeapon(weaponbox);
    if (weaponbox != NULLENT && IsCustomWeapon(weapon)) {
        SetHookChainArg(2, ATYPE_STRING, MODEL_W);
    }
    return HC_CONTINUE;
}

public fw_TouchGrenade(entity, toucher)
{
    if (is_health_grenade(entity) && (pev_valid(entity) != 2 || get_entvar(toucher, pev_solid) > SOLID_TRIGGER)) {
    grenade_explode(entity);
    }
}

public grenade_explode(grenade_entity)
{
    static grenade_owner, victim, Float: grenade_origin[3], Float: origin[3];
    grenade_owner = get_entvar(grenade_entity, pev_owner);

    if (is_valid_client(grenade_owner)) {
    get_pev(grenade_entity, pev_origin, grenade_origin);
    make_gibs(grenade_origin);
    emit_sound(grenade_entity, CHAN_ITEM, SOUND_EXPLODE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
   
    victim  = -1;
   
    while ((victim = engfunc( EngFunc_FindEntityInSphere, victim, grenade_origin, GRENADE_RADIUS)) != 0) {
      if (is_user_alive(victim) && is_teams_equal(victim, grenade_owner)) {
        set_user_health(victim, clamp(get_user_health(victim) + GRENADE_HEALTH, 1, GRENADE_MAXHEALTH));
       
        get_pev(victim, pev_origin, origin);
        origin[2]+= 30.0;
       
        message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
        write_byte(TE_SPRITE);
        WRITE_COORD(origin);
        write_short(sprite_index[HEAL]);
        write_byte(8);
        write_byte(255);
        message_end();
       
        message_begin(MSG_ONE_UNRELIABLE, gmsgScreenFade, .player = victim);
        write_short(1 << 12);
        write_short(0);
        write_short(0);
        write_byte(GRENADE_COLORFADE_RED);
        write_byte(GRENADE_COLORFADE_GREEN);
        write_byte(GRENADE_COLORFADE_BLUE);
        write_byte(80);
        message_end();
      }
    }
  }

  UTIL_RemoveEntity(grenade_entity);
}

make_gibs(Float:origin[3])
{
  static Float: start_pos[3], Float: end_pos[3];

  start_pos[0] = origin[0]; start_pos[1] = origin[1]; start_pos[2] = origin[2] + 150.0;
  end_pos[0]   = origin[0]; end_pos[1]   = origin[1]; end_pos[2]   = origin[2] + 10.0;

  message_begin (MSG_BROADCAST,SVC_TEMPENTITY);
  write_byte(TE_SPRITETRAIL);
  WRITE_COORD(start_pos);
  WRITE_COORD(end_pos);
  write_short(sprite_index[GIBS_BLUE]);
  write_byte(GIBS_COUNT);
  write_byte(random_num(GIBS_LIFE_MIN, GIBS_LIFE_MAX));
  write_byte(GIBS_SCALE);
  write_byte(50); // (velocity along vector in 10's)
  write_byte(10); // (randomness of velocity in 10's)
  message_end() ;

  message_begin (MSG_BROADCAST,SVC_TEMPENTITY);
  write_byte(TE_SPRITETRAIL);
  WRITE_COORD(start_pos);
  WRITE_COORD(end_pos);
  write_short(sprite_index[GIBS_GREEN]);
  write_byte(GIBS_COUNT);
  write_byte(random_num(GIBS_LIFE_MIN, GIBS_LIFE_MAX));
  write_byte(GIBS_SCALE);
  write_byte(50); // (velocity along vector in 10's)
  write_byte(10); // (randomness of velocity in 10's)
  message_end();

  message_begin (MSG_BROADCAST,SVC_TEMPENTITY);
  write_byte(TE_SPRITETRAIL);
  WRITE_COORD(start_pos);
  WRITE_COORD(end_pos);
  write_short(sprite_index[GIBS_RED]);
  write_byte(GIBS_COUNT);
  write_byte(random_num(GIBS_LIFE_MIN, GIBS_LIFE_MAX));
  write_byte(GIBS_SCALE);
  write_byte(50); // (velocity along vector in 10's)
  write_byte(10); // (randomness of velocity in 10's)
  message_end();
}

stock getWeaponBoxWeapon(const weaponbox) {
    for (new i = 0, weapon; i < MAX_ITEM_TYPES; i++) {
        weapon = get_member(weaponbox, m_WeaponBox_rgpPlayerItems, i);
        if (!is_nullent(weapon)) {
            return weapon;
        }
    }
    return NULLENT;
}
Взял плагин кастомного оружия от fantom за основу
 
Сообщения
95
Реакции
6
Помог
2 раз(а)
подскажите какой натив в reapi заменяет user_has_weapon
 
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу