This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Plugin modification help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ilko
New Member
Join Date: Jul 2006
Old 12-31-2014 , 18:38   Plugin modification help
Reply With Quote #1

Hi there. I'm asking for help because the mp5+m203 grenade launcher doesn't work properly. In fact, it works only while going back or when looking straight in front. Otherwise the grenade blow and do self damage if forwading or even simply looking up too much. I believe that it would need a simple modification of the origin of the shot, maybe. I like this plugin and would really appreciate any help.

Code:
/*/// Mp5+M203 Launcher - by PaintLancer
/////////////////////////////
Resources used
       - Thantik - HE-conc for knockback
       - Asskickr - Grentrail
       - EKS - sprite - doing hud sprites
Directions
	Players buy normal mp5 and buy grenades for it through buying
	normal HE grenades

1.9 - Fixed kill given to killed
    - Raised start origin of nade fired so it more the actual height of the gun
    
2.0 - Upgraded to newer versions of amxmodx

*/


#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <cstrike>
#include <fun>

new g_mp5[33]
new g_m203_loaded[33]
new g_ammo[33]
new g_lastweap[33]
new g_buyzone[33]

new gmsgDeathMsg
new gMsgID

//sprites
new m_iTrail
new xplode

#define ICON_HIDE 0
#define ICON_SHOW 1
#define TE_BEAMFOLLOW 22

public plugin_init() 
{ 
  register_plugin("Mp5 Mod","1.9","PaintLancer")

  register_event("DeathMsg","player_die","a")  
  register_event("CurWeapon","handle_gun","be","1=1")
  register_event("StatusIcon","Buy_Icon","be","2=buyzone") 

  //handle buying nades
  register_menucmd(-34,(1<<3),"BuyNade")
  register_clcmd("hegren", "BuyNade")

  //handle when player presses attack2
  register_forward(FM_PlayerPreThink, "forward_playerprethink") 
  // handle world model
  register_forward(FM_SetModel, "forward_setmodel") 

  //cvars
  register_cvar("amx_m203cost","300")  //cost for nade
  register_cvar("amx_m203ammo","2")  //ammo limit for backpack
  register_cvar("amx_crazynade","0") //makes nades bounce off all walls with perfect elasticity until it hits an entity or player...can get crazy
  register_cvar("amx_m203conc","10.0")  //force of knockback
  register_cvar("amx_m203trail","1")  //nade trails
  register_cvar("amx_m203rad","200")  //radius of dmg
  register_cvar("amx_m203dmg","75")  //dmg

  gmsgDeathMsg = get_user_msgid("DeathMsg")
  gMsgID = get_user_msgid("StatusIcon")

  return PLUGIN_CONTINUE
}

public player_die(id)
{
  if(g_mp5[id])
    ammo_hud(id,0)
  g_ammo[id] = 0
  
  return PLUGIN_CONTINUE
}

public BuyNade(id)
{
  new money = cs_get_user_money(id)

  if(g_mp5[id] && g_ammo[id] < get_cvar_num("amx_m203ammo") && money >= get_cvar_num("amx_m203cost") && g_buyzone[id])
  {
    ammo_hud(id,0)
    g_ammo[id]++
    ammo_hud(id,1)
    client_print(id, print_center, "You bought a grenade for your M203 Launcher %d/%d", g_ammo[id], get_cvar_num("amx_m203ammo"))
    
    cs_set_user_money(id, money - get_cvar_num("amx_m203cost"))
    return PLUGIN_HANDLED
  }
  return PLUGIN_CONTINUE
}

public forward_setmodel(entity, model[]) 
{
  if (!is_valid_ent(entity)) 
  {
    return FMRES_IGNORED
  }

  if (equal(model, "models/w_mp5.mdl")) 
  {
    new classname[11]
    entity_get_string(entity, EV_SZ_classname, classname, 10)
  
    //client_print(0, print_chat, "Model: %s Classname: %s", model, classname)

    if (equal(classname, "weaponbox")) 
    {
      //client_print(0, print_chat, "Setting model")

      entity_set_model(entity, "models/w_9mmar.mdl")

      return FMRES_SUPERCEDE
    }
  }

  return FMRES_IGNORED
}

public forward_playerprethink(id)
{
  if(is_user_alive(id))
  {
    if (entity_get_int(id, EV_INT_button) & IN_ATTACK2)
    {
      launch_nade(id)
      return FMRES_IGNORED
    }
  }
  return FMRES_IGNORED
}

public handle_gun(id)
{
  new clip, ammo
  new weap = get_user_weapon(id,clip,ammo)

  if(weap == CSW_MP5NAVY && g_lastweap[id] != weap)
  {
    ammo_hud(id,1)
    //client_print(id, print_chat, "Setting Model")
    entity_set_string(id, EV_SZ_viewmodel, "models/v_mp5m203.mdl")
    entity_set_string(id, EV_SZ_weaponmodel, "models/p_9mmar.mdl")
    g_mp5[id] = 1
  }
  else if(weap != CSW_MP5NAVY)
  {
    ammo_hud(id,0)
    g_mp5[id] = 0
  }
  g_lastweap[id] = weap

  return PLUGIN_HANDLED
}

public launch_nade(id)
{
  if(g_mp5[id] == 0 || g_m203_loaded[id] == 0 || !(is_user_alive(id)))
    return PLUGIN_CONTINUE

  if(g_ammo[id] == 0)
  {
    client_print(id, print_center, "You are out of m203 grenades!")
    return PLUGIN_CONTINUE
  }

  entity_set_int(id, EV_INT_weaponanim, 3)

  new Float: Origin[3], Float: Velocity[3], Float: vAngle[3], Ent

  entity_get_vector(id, EV_VEC_origin , Origin)
  entity_get_vector(id, EV_VEC_v_angle, vAngle)

  //client_print(id, print_center, "Origin: %f-%f-%f", Origin[0], Origin[1], Origin[2])
  //client_print(id, print_center, "vAngle: %f-%f-%f", vAngle[0], vAngle[1], vAngle[2])

  Origin[2] = Origin[2] + 10

  Ent = create_entity("info_target")

  if (!Ent) return PLUGIN_HANDLED

  entity_set_string(Ent, EV_SZ_classname, "m203_nade")
  entity_set_model(Ent, "models/grenade.mdl")

  new Float:MinBox[3] = {-1.0, -1.0, -1.0}
  new Float:MaxBox[3] = {1.0, 1.0, 1.0}
  entity_set_vector(Ent, EV_VEC_mins, MinBox)
  entity_set_vector(Ent, EV_VEC_maxs, MaxBox)

  entity_set_origin(Ent, Origin)
  entity_set_vector(Ent, EV_VEC_angles, vAngle)

  entity_set_int(Ent, EV_INT_effects, 2)
  entity_set_int(Ent, EV_INT_solid, 1)
  entity_set_int(Ent, EV_INT_movetype, 10)
  entity_set_edict(Ent, EV_ENT_owner, id)

  VelocityByAim(id, 2000 , Velocity)
  entity_set_vector(Ent, EV_VEC_velocity ,Velocity)
	
  emit_sound(id,CHAN_VOICE,"misc/glauncher.wav", 1.0, ATTN_NORM, 0, PITCH_NORM) 

  g_m203_loaded[id] = 0

  ammo_hud(id,0)
  g_ammo[id]--
  ammo_hud(id,1)

  new parm[1]
  parm[0] = Ent

  if(get_cvar_num("amx_m203trail"))
    set_task(0.2, "grentrail",id,parm,1)
  
  parm[0] = id
  set_task(2.0, "m203_reload",id+9910,parm,1)

  return PLUGIN_CONTINUE
}

public m203_reload(parm[])
{  
  g_m203_loaded[parm[0]] = 1
}

public vexd_pfntouch(pToucher, pTouched) 
{
  new szClassName[32]

  if ( pToucher > 0) 
  {
    entity_get_string(pToucher, EV_SZ_classname, szClassName, 31)
  }
  if(equal(szClassName, "m203_nade")) 
  {
    if(!pTouched && get_cvar_num("amx_crazynade"))
      return

    new damradius = get_cvar_num("amx_m203rad")//200
    new maxdamage = get_cvar_num("amx_m203dmg")//70
    
    new tkill = 0
    new Float:fl_vExplodeAt[3]
    entity_get_vector(pToucher, EV_VEC_origin, fl_vExplodeAt)
    new vExplodeAt[3]
    vExplodeAt[0] = floatround(fl_vExplodeAt[0])
    vExplodeAt[1] = floatround(fl_vExplodeAt[1])
    vExplodeAt[2] = floatround(fl_vExplodeAt[2])
    new oid = entity_get_edict(pToucher, EV_ENT_owner)
    new origin[3],dist,i,Float:dRatio,damage

    for ( i = 0; i < 32; i++) 
    {
      if((is_user_alive(i)))
      {
        get_user_origin(i,origin)
	dist = get_distance(origin,vExplodeAt)
	if (dist <= damradius) 
	{	  
          dRatio = floatdiv(float(dist),float(damradius))
	  damage = maxdamage - floatround(floatmul(float(maxdamage),dRatio))

	  set_velocity_from_origin(i, fl_vExplodeAt, get_cvar_float("amx_m203conc")*damage) // ThantiK's he-conc function - tried getting it to recognize m203 nades but failed so imported function         
 
          if(cvar_exists("mp_friendlyfire")) 
	  {
            if(i == oid)
              do_victim(i, oid, damage, 2)
	    else if( get_cvar_num("mp_friendlyfire")) 
	    {
	      if(get_user_team(i) == get_user_team(oid)) tkill = 1
	      do_victim(i,oid,damage,tkill)
	    }
	    else 
	    {
	      if(get_user_team(i) != get_user_team(oid)) 
	      {
		do_victim(i,oid,damage,0)
	      }	      		    	
	    }
	  }
          else if(i == oid)
            do_victim(i, oid, damage, 2)
	  else 
  	    do_victim(i,oid,damage,0)	  
        }
      }
    }

    message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    write_byte(17)
    write_coord(vExplodeAt[0])
    write_coord(vExplodeAt[1])
    write_coord(vExplodeAt[2] + 60)
    write_short(xplode)
    write_byte(20)
    write_byte(200)
    message_end()

    emit_sound(pToucher, CHAN_WEAPON, "misc/a_exm2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    
    remove_entity(pToucher)
  }
}

do_victim(victim,attacker,damage,tk) 
{
  new namek[32],namev[32],authida[35],authidv[35],teama[32],teamv[32]
  get_user_name(victim,namev,31)
  get_user_name(attacker,namek,31)
  get_user_authid(victim,authidv,34)
  get_user_authid(attacker,authida,34)
  get_user_team(victim,teamv,31)
  get_user_team(attacker,teama,31)

  new Float:fl_dmg = float(damage)

  if(damage >= get_user_health(victim))
  {
    set_msg_block(gmsgDeathMsg,BLOCK_SET)
    fakedamage(victim, "grenade", fl_dmg, DMG_BLAST)  //user_kill(victim,1)
    set_msg_block(gmsgDeathMsg,BLOCK_NOT)

    if(is_user_alive(victim)) //some cases where damage is messed with WC3? then return
      return

    message_begin(MSG_ALL, get_user_msgid("DeathMsg"), {0,0,0}, 0)
    write_byte(attacker)
    write_byte(victim)
    write_byte(0)
    write_string("grenade")
    message_end()
     
    if(tk == 1)
    {
      client_print(attacker,print_center,"You killed a teammate")
      set_user_frags(attacker,get_user_frags(attacker) - 1 )
      set_user_frags(victim, get_user_frags(victim) + 1)
      log_message("^"%s<%d><%s><%s>^" killed ^"%s<%d><%s><%s>^" with ^"grenade^"",
				namek,get_user_userid(attacker),authida,teama,namev,get_user_userid(victim),authidv,teamv)
    }
    else if(tk == 2)
    {
      log_message("^"%s<%d><%s><%s>^" killed self with ^"grenade^"",
				namek,get_user_userid(attacker),authida,teama)
    }
    else
    {
      new money = cs_get_user_money(attacker)
      cs_set_user_money(attacker, money + 300) // award for kill

      set_user_frags(attacker,get_user_frags(attacker) + 1 )
      //set_user_frags(attacker,get_user_frags(victim) + 1 )
      log_message("^"%s<%d><%s><%s>^" killed ^"%s<%d><%s><%s>^" with ^"grenade^"",
				namek,get_user_userid(attacker),authida,teama,namev,get_user_userid(victim),authidv,teamv)
    }    
  }
  else 
  {
    fakedamage(victim, "grenade", fl_dmg, DMG_BLAST) //set_user_health(victim,get_user_health(victim) - damage )

    if(tk == 1)
    {
	client_print(0,print_chat,"%s attacked a teammate",namek)
    }
  }
}

public client_connect(id)
{
  g_mp5[id] = 0
  g_m203_loaded[id] = 1
  g_ammo[id] = 0
}

public Buy_Icon(id) 
{ 
  if (read_data(1)) 
  { 
    g_buyzone[id] = true 
  } 
  else 
  { 
    g_buyzone[id] = false 
  } 
  return PLUGIN_CONTINUE 
} 

ammo_hud(id, sw)
{
  new s_sprite[33]
  format(s_sprite,32,"number_%d",g_ammo[id])
  
  if(sw)
  {
    message_begin( MSG_ONE, gMsgID, {0,0,0}, id )
    write_byte( ICON_SHOW ) // status
    write_string( s_sprite ) // sprite name
    write_byte( 0 ) // red
    write_byte( 160 ) // green
    write_byte( 0 ) // blue
    message_end()
  }
  else
  {
    message_begin( MSG_ONE, gMsgID, {0,0,0}, id )
    write_byte( ICON_HIDE ) // status
    write_string( s_sprite ) // sprite name
    write_byte( 0 ) // red
    write_byte( 160 ) // green
    write_byte( 0 ) // blue
    message_end()
  }
}

/////////////////////
//Thantik's he-conc functions
stock get_velocity_from_origin( ent, Float:fOrigin[3], Float:fSpeed, Float:fVelocity[3] )
{
    new Float:fEntOrigin[3];
    entity_get_vector( ent, EV_VEC_origin, fEntOrigin );

    // Velocity = Distance / Time

    new Float:fDistance[3];
    fDistance[0] = fEntOrigin[0] - fOrigin[0];
    fDistance[1] = fEntOrigin[1] - fOrigin[1];
    fDistance[2] = fEntOrigin[2] - fOrigin[2];

    new Float:fTime = ( vector_distance( fEntOrigin,fOrigin ) / fSpeed );

    fVelocity[0] = fDistance[0] / fTime;
    fVelocity[1] = fDistance[1] / fTime;
    fVelocity[2] = fDistance[2] / fTime;

    return ( fVelocity[0] && fVelocity[1] && fVelocity[2] );
}


// Sets velocity of an entity (ent) away from origin with speed (speed)

stock set_velocity_from_origin( ent, Float:fOrigin[3], Float:fSpeed )
{
    new Float:fVelocity[3];
    get_velocity_from_origin( ent, fOrigin, fSpeed, fVelocity )

    entity_set_vector( ent, EV_VEC_velocity, fVelocity );

    return ( 1 );
} 

public grentrail(parm[])
{
  new gid = parm[0]

  if (gid) 
  {
    message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
    write_byte( TE_BEAMFOLLOW )
    write_short(gid) // entity
    write_short(m_iTrail)  // model
    write_byte( 10 )       // life
    write_byte( 5 )        // width
    write_byte( 255 )      // r, g, b
    write_byte( 255 )    // r, g, b
    write_byte( 255 )      // r, g, b
    write_byte( 100 ) // brightness
		
    message_end() // move PHS/PVS data sending into here (SEND_ALL, SEND_PVS, SEND_PHS)
  }
}

public plugin_precache()
{
  precache_model("models/v_mp5m203.mdl")
  precache_model("models/p_9mmar.mdl")
  precache_model("models/w_9mmar.mdl")
  precache_model("models/grenade.mdl")
  precache_sound("misc/glauncher.wav")
  precache_sound("misc/a_exm2.wav")

  m_iTrail = precache_model("sprites/smoke.spr")
  xplode = precache_model("sprites/zerogxplode2.spr")
}
Ilko is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 12-31-2014 , 23:06   Re: Plugin modification help
Reply With Quote #2

Post in the plugin's thread
RateX is offline
Ilko
New Member
Join Date: Jul 2006
Old 01-01-2015 , 14:53   Re: Plugin modification help
Reply With Quote #3

@Ratex I did not because other members already did and the author of the plugin had no any activity since 9 years. I'm not asking for an update, I'm asking for scripting help.

I've found a way to fix the problem in changing this :
Code:
Origin[2] = Origin[2] + 10
to this :
Code:
Origin[2] = Origin[2] + 40
But now the projectile seems being fired from over my head
Ilko is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-02-2015 , 03:08   Re: Plugin modification help
Reply With Quote #4

That's because it's the z axis. Play with Origin[1] till you're satisfy.
RateX is offline
Ilko
New Member
Join Date: Jul 2006
Old 01-02-2015 , 21:43   Re: Plugin modification help
Reply With Quote #5

Thanks for the suggest, could you tell me how to that ?

I guess that the projectile is created with "entity", and the start point is "origin" or maybe the "owner", but there is no "Origin[1]" define for the entity creation part. This is the Y axis, right ? So is Origin3 the X one ?

Can I play with "entity_set_origin(Ent, Origin)" or something else to make the entity look like it's fired from the gun instead of from the head ?
Ilko is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 01-03-2015 , 22:58   Re: Plugin modification help
Reply With Quote #6

Quote:
could you tell me how to that ?
Just add/subtract like you did with Origin[2]. Also, Origin[0], Origin[1], Origin[2] are float.
Quote:
I guess that the projectile is created with "entity", and the start point is "origin" or maybe the "owner", but there is no "Origin[1]" define for the entity creation part. This is the Y axis, right ? So is Origin3 the X one ?
The start point is "Origin", and Origin[0], Origin[1], Origin[2] are defined using:
PHP Code:
entity_get_vector(idEV_VEC_origin Origin// Getting origin of the owner 
And Origin[0] is actually the x axis
Quote:
Can I play with "entity_set_origin(Ent, Origin)" or something else to make the entity look like it's fired from the gun instead of from the head ?
Yes, you can. A better way:
PHP Code:
engfunc(EngFunc_GetAttachmentid0OriginAngle
RateX is offline
Ilko
New Member
Join Date: Jul 2006
Old 01-04-2015 , 13:06   Re: Plugin modification help
Reply With Quote #7

Thanks a lot Ratex, the weird thing is that all axises seem independent of where I'm looking. It's like a static position and it's not inverted when I move. I mean, it's like it's simply mirrored, so it can be fired from any of my side.

And sorry, I don't know how to include your last suggest in the code. Guessing I may replace other parts of the code maybe, and you may be helpful. For now, playing with axises didn't give satisfying results.

Thanks mate.

Last edited by Ilko; 01-04-2015 at 13:38.
Ilko is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode