PDA

View Full Version : [HELP] Weaponlist don't work on custom weapon.



Riseless
13-05-2016, 08:47 AM
I have a problem with weaponlist. :c Can't fix this. :c

screenshot:
17254

source code:


const int AMMO_BY_GIVE=120;
const int MAX_AMMO=180;
const int MAX_CLIP=30;
const int WEIGHT=25;
const int DAMAGE_BY_SHOT=30;

enum Animations{
IDLE1=0,
FIRE1,
FIRE2,
FIRE3,
CHANGE1,
CHANGE2,
RELOAD1,
DRAW1
}
class weapon_block_ar:ScriptBasePlayerWeaponEntity{
float m_flNextAnimTime;
int m_iShell;

void Spawn(){
Precache();
g_EntityFuncs.SetModel(self,"models/riseless/w_block_ar.mdl");

self.m_iDefaultAmmo=AMMO_BY_GIVE;

self.FallInit();
}
void Precache(){
self.PrecacheCustomModels();
g_Game.PrecacheModel("models/riseless/v_block_ar.mdl");
g_Game.PrecacheModel("models/riseless/w_block_ar.mdl");
g_Game.PrecacheModel("models/riseless/p_block_ar.mdl");

m_iShell=g_Game.PrecacheModel("models/riseless/s_block_ar.mdl");

g_Game.PrecacheGeneric("sound/"+"weapons/357_cock1.wav");
g_Game.PrecacheGeneric("sound/"+"riseless/block_ar_fire1.wav");
g_Game.PrecacheGeneric("sound/"+"riseless/block_ar_draw1.wav");
g_Game.PrecacheGeneric("sound/"+"riseless/block_ar_clip_in1.wav");
g_Game.PrecacheGeneric("sound/"+"riseless/block_ar_clip_out1.wav");

g_SoundSystem.PrecacheSound("weapons/357_cock1.wav");
g_SoundSystem.PrecacheSound("riseless/block_ar_fire1.wav");

g_SoundSystem.PrecacheSound("riseless/block_ar_draw1.wav");
g_SoundSystem.PrecacheSound("riseless/block_ar_clip_in1.wav");
g_SoundSystem.PrecacheSound("riseless/block_ar_clip_out1.wav");

g_Game.PrecacheGeneric("sprites/"+"riseless/block_ar_weapon1.spr");
g_Game.PrecacheGeneric("sprites/"+"riseless/block_ar_ammo1.spr");
g_Game.PrecacheGeneric("sprites/"+"riseless/crosshair1.spr");
g_Game.PrecacheGeneric("sprites/"+"riseless/weapon_block_ar.txt");
}
bool GetItemInfo(ItemInfo& out info){
info.iMaxAmmo1=MAX_AMMO;
info.iMaxAmmo2=-1;
info.iMaxClip=MAX_CLIP;
info.iSlot=3;
info.iPosition=9;
info.iFlags=0;
info.iWeight=WEIGHT;

return true;
}
bool AddToPlayer(CBasePlayer@ pPlayer){
if(BaseClass.AddToPlayer(pPlayer)){
NetworkMessage message(MSG_ONE,NetworkMessages::WeapPickup,pPlayer.edict()) ;
message.WriteLong(self.m_iId);
message.End();
return true;
}
return false;
}
bool PlayEmptySound(){
if(self.m_bPlayEmptySound){
self.m_bPlayEmptySound=false;
g_SoundSystem.EmitSoundDyn(self.m_pPlayer.edict(),CHAN_WEAPO N,"weapons/357_cock1.wav",0.9,ATTN_NORM,0,PITCH_NORM);
}
return false;
}
float WeaponTimeBase(){
return g_Engine.time;
}
bool Deploy(){
bool bResult;{
bResult=self.DefaultDeploy(self.GetV_Model("models/riseless/v_block_ar.mdl"),self.GetP_Model("models/riseless/p_block_ar.mdl"),DRAW1,"m16");
float deployTime=1.0;
self.m_flTimeWeaponIdle=self.m_flNextPrimaryAttack=self.m_fl NextSecondaryAttack=g_Engine.time+deployTime;
return bResult;
}
}
void PrimaryAttack(){
if(self.m_pPlayer.pev.waterlevel==WATERLEVEL_HEAD){
self.PlayEmptySound();
self.m_flNextPrimaryAttack=WeaponTimeBase()+0.15f;
return;
}
if(self.m_iClip<=0){
self.PlayEmptySound();
self.m_flNextPrimaryAttack=WeaponTimeBase()+0.15f;
return;
}

self.m_flNextPrimaryAttack=WeaponTimeBase()+0.095f;

self.m_pPlayer.m_iWeaponVolume=NORMAL_GUN_VOLUME;
self.m_pPlayer.m_iWeaponFlash=BRIGHT_GUN_FLASH;

--self.m_iClip;

self.m_flTimeWeaponIdle=g_Engine.time+1.5f;

/* Lego weapon don't need a muzzle :D */
/* self.m_pPlayer.pev.effects|=EF_MUZZLEFLASH; */

self.m_pPlayer.SetAnimation(PLAYER_ATTACK1);

switch(g_PlayerFuncs.SharedRandomLong(self.m_pPlayer.random_ seed,0,2)){
case 0:self.SendWeaponAnim(FIRE1,0,0);break;
case 1:self.SendWeaponAnim(FIRE2,0,0);break;
case 2:self.SendWeaponAnim(FIRE3,0,0);break;
}

g_SoundSystem.EmitSoundDyn(self.m_pPlayer.edict(),CHAN_WEAPO N,"riseless/block_ar_fire1.wav",0.9,ATTN_NORM,0,PITCH_NORM);

Vector vecSrc=self.m_pPlayer.GetGunPosition();
Vector vecAiming=self.m_pPlayer.GetAutoaimVector(AUTOAIM_5DEGREES);

int m_iBulletDamage=DAMAGE_BY_SHOT;

self.m_pPlayer.FireBullets(1,vecSrc,vecAiming,VECTOR_CONE_6D EGREES,8192,BULLET_PLAYER_CUSTOMDAMAGE,2,m_iBulletDamage);

if(self.m_iClip==0&&self.m_pPlayer.m_rgAmmo(self.m_iPrimaryAmmoType)<=0)self.m_pPlayer.SetSuitUpdate("!HEV_AMO0",false,0);

self.m_pPlayer.pev.punchangle.x=Math.RandomLong(-3,0);
if(self.m_pPlayer.pev.punchangle.x==0){
self.m_pPlayer.pev.punchangle.x=Math.RandomLong(-3,-1);
}

if(self.m_flNextPrimaryAttack<WeaponTimeBase())self.m_flNextPrimaryAttack=WeaponTimeBase() +0.15f;

self.m_flTimeWeaponIdle=WeaponTimeBase()+Math.RandomFloat(10 ,15);

TraceResult tr;

float x,y;

g_Utility.GetCircularGaussianSpread(x,y);

Vector vecDir=vecAiming
+x*VECTOR_CONE_2DEGREES.x*g_Engine.v_right
+y*VECTOR_CONE_2DEGREES.y*g_Engine.v_up;

Vector vecEnd=vecSrc+vecDir*4096;

g_Utility.TraceLine(vecSrc,vecEnd,dont_ignore_monsters,self. m_pPlayer.edict(),tr);

if(tr.flFraction<1.0){
if(tr.pHit !is null){
CBaseEntity@ pHit=g_EntityFuncs.Instance(tr.pHit);
if(pHit is null||pHit.IsBSPModel()==true)g_WeaponFuncs.DecalGunshot(tr, BULLET_PLAYER_MP5);
}
}

Vector vecShellVelocity,vecShellOrigin;

GetDefaultShellInfo(self.m_pPlayer,vecShellVelocity,vecShell Origin,21,12,-9);

vecShellVelocity.y*=1;

g_EntityFuncs.EjectBrass(vecShellOrigin,vecShellVelocity,sel f.m_pPlayer.pev.angles[1],m_iShell,TE_BOUNCE_SHELL);
}
void Reload(){
if(self.m_iClip<MAX_CLIP)BaseClass.Reload();
self.DefaultReload(MAX_CLIP,RELOAD1,3.03,0);
}
void WeaponIdle(){
self.ResetEmptySound();
self.m_pPlayer.GetAutoaimVector(AUTOAIM_10DEGREES);

if(self.m_flTimeWeaponIdle>WeaponTimeBase())return;

self.SendWeaponAnim(IDLE1);
self.m_flTimeWeaponIdle=WeaponTimeBase()+Math.RandomFloat(10 ,15);
}
}
class BlockArAmmoBox:ScriptBasePlayerAmmoEntity{
void Spawn(){
Precache();
g_EntityFuncs.SetModel(self,"models/riseless/s_block.mdl");
BaseClass.Spawn();
}
void Precache(){
g_Game.PrecacheModel("models/riseless/s_block.mdl");
g_SoundSystem.PrecacheSound("items/9mmclip1.wav");
}
bool AddAmmo(CBaseEntity@ pither){
int iGive;
iGive=AMMO_BY_GIVE;
if(pither.GiveAmmo(iGive,"ammo_block_ar",MAX_AMMO)!=-1){
g_SoundSystem.EmitSound(self.edict(),CHAN_ITEM,"items/9mmclip1.wav",1,ATTN_NORM);
return true;
}
return false;
}
}
void RegisterBlockArAmmoBox(){
g_CustomEntityFuncs.RegisterCustomEntity("BlockArAmmoBox",GetBlockArAmmoBoxName());
}
void RegisterBlockAr(){
g_CustomEntityFuncs.RegisterCustomEntity(GetBlockArName(),Ge tBlockArName());
g_ItemRegistry.RegisterWeapon(GetBlockArName(),"weapon_block_ar","ammo_block_ar");
}
string GetBlockArName(){
return "weapon_block_ar";
}
string GetBlockArAmmoBoxName(){
return "ammo_block_ar";
}
void GetDefaultShellInfo(CBasePlayer@ pPlayer,Vector& out ShellVelocity,Vector& out ShellOrigin,float forwardScale,float rightScale,float upScale){
Vector vecForward,vecRight,vecUp;

g_EngineFuncs.AngleVectors(pPlayer.pev.v_angle,vecForward,ve cRight,vecUp);

const float fR=Math.RandomFloat(50,70);
const float fU=Math.RandomFloat(100,150);

for(int i=0;i<3;++i){
ShellVelocity[i]=pPlayer.pev.velocity[i]+vecRight[i]*fR+vecUp[i]*fU+vecForward[i]*25;
ShellOrigin[i]=pPlayer.pev.origin[i]+pPlayer.pev.view_ofs[i]+vecUp[i]*upScale+vecForward[i]*forwardScale+vecRight[i]*rightScale;
}
}


weapon_block_ar.txt:


4
weapon 640 riseless/block_ar_weapon1 0 0 170 45
weapon_s 640 riseless/block_ar_weapon1 0 45 170 45
ammo 640 riseless/block_ar_ammo1 0 0 24 24
crosshair 640 riseless/crosshair1 256 0 256 256

KernCore
13-05-2016, 08:53 AM
g_ItemRegistry.RegisterWeapon(GetBlockArName(),"weapon_block_ar","ammo_block_ar");


Try changing weapon_block_ar to riseless

should look like this:


g_ItemRegistry.RegisterWeapon(GetBlockArName(),"riseless","ammo_block_ar");

Riseless
13-05-2016, 09:32 AM
Fixed. c: Thank you. :3

Nero
15-05-2016, 04:39 PM
Aye, the first string is the name of the weapon entity (eg. weapon_shotgun), the second is the folder where you place the weapon's ui sprite definition file (eg. custom_weapons if it's in sprites\custom_weapons), and the third is the name of the ammo it uses (eg. buckshot)

Also this line:
g_CustomEntityFuncs.RegisterCustomEntity(GetBlockArName(),Ge tBlockArName());

The first string is the name of the weapon's class (eg. CShotgun) this needs to he whatever you put at
class weapon_block_ar:ScriptBasePlayerWeaponEntity
So in this case weapon_block_ar


And the second is the name of the weapon entity (eg. weapon_shotgun)