Added CGameRules::MaxItemPerSlot to let gamemodes/rules allow how many

items we allow per inventory/HUD slot. CS's is 1 in multiplayer.
This commit is contained in:
Marco Cawthorne 2020-04-23 21:02:38 +02:00
parent b95f7c37eb
commit 7c0315d56f
11 changed files with 83 additions and 6 deletions

View file

@ -1,6 +1,7 @@
r_part effect r_part effect
{ {
texture ball texture "particles/fteparticlefont.tga"
tcoords 97 97 191 191 256
count 1 count 1
scale 512 scale 512
scalefactor 1 scalefactor 1

View file

@ -75,6 +75,25 @@ CSEv_BuyWeapon_f(float fWeapon)
} }
if ((pl.money - g_cstrikeWeaponPrice[iWeapon]) >= 0) { if ((pl.money - g_cstrikeWeaponPrice[iWeapon]) >= 0) {
/* let's check if we've got a limit */
int maxit;
maxit = rules.MaxItemPerSlot();
if (maxit > 0) {
int wantslot = g_weapons[iWeapon].slot;
int c;
for (int i = 0; i < g_weapons.length; i++) {
if (pl.g_items & g_weapons[i].id && g_weapons[i].slot == wantslot) {
c++;
/* we're over the slot limit. */
if (c >= maxit) {
pl.activeweapon = i;
CSEv_DropWeapon();
}
}
}
}
Weapons_AddItem(pl, iWeapon); Weapons_AddItem(pl, iWeapon);
Money_AddMoney(pl, -g_cstrikeWeaponPrice[iWeapon]); Money_AddMoney(pl, -g_cstrikeWeaponPrice[iWeapon]);
Sound_Play(pl, CHAN_ITEM, "buy.weapon"); Sound_Play(pl, CHAN_ITEM, "buy.weapon");

View file

@ -74,4 +74,5 @@ class CSMultiplayerRules:CSGameRules
virtual void(player) PlayerMakeSpectator; virtual void(player) PlayerMakeSpectator;
virtual void(player, int) PlayerRespawn; virtual void(player, int) PlayerRespawn;
virtual entity(float) PlayerFindSpawn; virtual entity(float) PlayerFindSpawn;
virtual int(void) MaxItemPerSlot;
}; };

View file

@ -788,6 +788,12 @@ CSMultiplayerRules::PlayerSpawn(player pl)
forceinfokey(pl, "*team", "0"); forceinfokey(pl, "*team", "0");
} }
int
CSMultiplayerRules::MaxItemPerSlot(void)
{
return 1;
}
void void
CSMultiplayerRules::CSMultiplayerRules(void) CSMultiplayerRules::CSMultiplayerRules(void)
{ {

View file

@ -104,6 +104,12 @@ CGameRules::SpectatorThink(player pl)
//print("SpectatorThink!\n"); //print("SpectatorThink!\n");
}*/ }*/
int
CGameRules::MaxItemPerSlot(void)
{
return -1;
}
void void
CGameRules::CGameRules(void) CGameRules::CGameRules(void)
{ {

View file

@ -38,6 +38,8 @@ class CGameRules
virtual void(void) LevelNewParms; virtual void(void) LevelNewParms;
virtual void(player) LevelChangeParms; virtual void(player) LevelChangeParms;
virtual int(void) MaxItemPerSlot;
/* spectator */ /* spectator */
/*virtual void(player) SpectatorConnect; /*virtual void(player) SpectatorConnect;
virtual void(player) SpectatorDisconnect; virtual void(player) SpectatorDisconnect;

View file

@ -17,6 +17,8 @@
/* PICKUP ITEMS */ /* PICKUP ITEMS */
class item_pickup:CBaseTrigger class item_pickup:CBaseTrigger
{ {
int m_iClip;
int m_iWasDropped;
int id; int id;
void(void) item_pickup; void(void) item_pickup;
@ -72,7 +74,10 @@ void item_pickup::Respawn(void)
think = __NULL__; think = __NULL__;
nextthink = -1; nextthink = -1;
sound(this, CHAN_ITEM, "items/suitchargeok1.wav", 1, ATTN_NORM, 150);
if (!m_iWasDropped)
sound(this, CHAN_ITEM, "items/suitchargeok1.wav", 1, ATTN_NORM, 150);
droptofloor(); droptofloor();
} }

View file

@ -16,6 +16,7 @@
#ifdef CLIENT #ifdef CLIENT
var int FX_EXPLOSION_MAIN; var int FX_EXPLOSION_MAIN;
var int FX_EXPLOSION_BS;
void void
FX_Explosion_Init(void) FX_Explosion_Init(void)
@ -25,6 +26,7 @@ FX_Explosion_Init(void)
precache_sound("weapons/explode5.wav"); precache_sound("weapons/explode5.wav");
precache_model("sprites/fexplo.spr"); precache_model("sprites/fexplo.spr");
FX_EXPLOSION_MAIN = particleeffectnum("fx_explosion.main"); FX_EXPLOSION_MAIN = particleeffectnum("fx_explosion.main");
FX_EXPLOSION_BS = particleeffectnum("fx_explosion.blacksmoke");
} }
#endif #endif
@ -56,6 +58,7 @@ FX_Explosion(vector vecPos)
eExplosion.nextthink = time + 0.05f; eExplosion.nextthink = time + 0.05f;
pointparticles(FX_EXPLOSION_MAIN, vecPos, [0,0,0], 1); pointparticles(FX_EXPLOSION_MAIN, vecPos, [0,0,0], 1);
pointparticles(FX_EXPLOSION_BS, vecPos, [0,0,0], 1);
#endif #endif
} }

View file

@ -284,6 +284,25 @@ int Weapons_AddItem(player pl, int w)
entity oldself = self; entity oldself = self;
self = pl; self = pl;
/* let's check if we've got a limit */
int maxit;
CGameRules rules = (CGameRules)g_grMode;
maxit = rules.MaxItemPerSlot();
if (maxit > 0) {
int wantslot = g_weapons[w].slot;
int c;
for (int i = 0; i < g_weapons.length; i++) {
if (pl.g_items & g_weapons[i].id && g_weapons[i].slot == wantslot) {
c++;
/* we're over the slot limit. */
if (c >= maxit) {
return FALSE;
}
}
}
}
/* in case programmer decided not to add a pickup callback */ /* in case programmer decided not to add a pickup callback */
if (g_weapons[w].pickup == __NULL__) { if (g_weapons[w].pickup == __NULL__) {
if (pl.g_items & g_weapons[w].id) { if (pl.g_items & g_weapons[w].id) {
@ -384,7 +403,7 @@ void CSEv_DropWeapon(void)
if (!pl.activeweapon) if (!pl.activeweapon)
return; return;
item_pickup drop = spawn(item_pickup); item_pickup drop = spawn(item_pickup, m_iWasDropped: TRUE, m_iClip: pl.a_ammo1);
drop.setitem(pl.activeweapon); drop.setitem(pl.activeweapon);
setorigin(drop, pl.origin); setorigin(drop, pl.origin);
drop.solid = SOLID_NOT; drop.solid = SOLID_NOT;

View file

@ -9,7 +9,7 @@ r_part ember
scalefactor 1 scalefactor 1
friction 8 friction 8
gravity 50 gravity 50
die 1 die 1.5
blend add blend add
randomvel 5 randomvel 5
veladd 1 veladd 1
@ -52,3 +52,18 @@ r_part main
blend add blend add
assoc expgib assoc expgib
} }
r_part blacksmoke
{
texture "particles/fteparticlefont.tga"
tcoords 97 97 191 191 256
count 1
scale 324
scalefactor 1
die 3
alpha 1
rgb 0 0 0
spawnmode ball
gravity -25
veladd -20
}