Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions game/jbmod.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
"A bridge entity that sets the active JBMod game mode and runs the corresponding mode script."
[
gamemode(string) : "Game Mode Name" : "" : "The name of the game mode (e.g. 'sandbox'). This will automatically load 'scripts/vscripts/gamemodes/<name>.nut'."

spawnflags(flags) =
[
1: "Start Disabled" : 0
]

input Enable(void) : "Apply the game mode settings and run the mode script."
]


4 changes: 4 additions & 0 deletions game/jbmod/scripts/vscripts/gamemodes/cstrike.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
printl( "Loading Counter-Strike..." );

RegisterEntityClass( "info_player_counterterrorist", "info_player_start" );
RegisterEntityClass( "info_player_terrorist", "info_player_start" );
5 changes: 5 additions & 0 deletions game/jbmod/scripts/vscripts/gamemodes/deathmatch.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
printl( "Loading Deathmatch..." );

RegisterEntityClass( "info_player_deathmatch", "info_player_start" );
RegisterEntityClass( "info_player_combine", "info_player_start" );
RegisterEntityClass( "info_player_rebel", "info_player_start" );
23 changes: 23 additions & 0 deletions game/jbmod/scripts/vscripts/gamemodes/default.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Default gamemode selector
// This script runs if no jbmod_logic_gamemode is found in the map.

// TODO: Once we have mounting place, we can also match by folder/vpk
// This is just a demo for now

local mapname = GetMapName();
local lastSlash = mapname.find( "/" );
if ( lastSlash != null )
mapname = mapname.slice( lastSlash + 1 );

local dot = mapname.find( ".bsp" );
if ( dot != null )
mapname = mapname.slice( 0, dot );

if ( mapname.slice( 0, 3 ) == "dm_" )
IncludeScript( "gamemodes/deathmatch.nut" );
else if ( mapname.slice( 0, 3 ) == "cs_" || mapname.slice( 0, 3 ) == "de_" )
IncludeScript( "gamemodes/cstrike.nut" );
else if ( mapname.slice( 0, 4 ) == "dod_" )
IncludeScript( "gamemodes/dod.nut" );
else if ( mapname.slice( 0, 6 ) == "arena_" || mapname.slice( 0, 3 ) == "cp_" || mapname.slice( 0, 4 ) == "ctf_" || mapname.slice( 0, 5 ) == "koth_" || mapname.slice( 0, 3 ) == "pl_" )
IncludeScript( "gamemodes/tf.nut" );
4 changes: 4 additions & 0 deletions game/jbmod/scripts/vscripts/gamemodes/dod.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
printl( "Loading Day of Defeat..." );

RegisterEntityClass( "info_player_allies", "info_player_start" );
RegisterEntityClass( "info_player_axis", "info_player_start" );
3 changes: 3 additions & 0 deletions game/jbmod/scripts/vscripts/gamemodes/tf.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printl( "Loading Team Fortress..." );

RegisterEntityClass( "info_player_teamspawn", "info_player_start" );
56 changes: 56 additions & 0 deletions game/jbmod/scripts/vscripts/weapons/weapon_leafblower.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local FORCE = 500.0
local FORCE_MULTIPLIER = 4.0
local RANGE = 512.0

function PrimaryAttack()
{
if (SERVER) // No prediction for now
{
self.EmitSound( "Weapon_Crossbow.BoltFly" )
Blow(FORCE)
}
}

function SecondaryAttack()
{
if (SERVER) // No prediction for now
{
self.EmitSound( "Weapon_PhysCannon.Launch" )
Blow( FORCE * FORCE_MULTIPLIER )
}
}

function Blow(force)
{
if ( owner == null ) return

local shootPos = owner.Weapon_ShootPosition()
local forward = owner.GetForwardVector()

local trace = {
start = shootPos,
end = shootPos + forward * 16384,
hullmin = Vector( -8, -8, -8 ),
hullmax = Vector( 8, 8, 8 ),
mask = 0x4600400b,
ignore = owner
}

TraceHull( trace )

if ( !("enthit" in trace) || trace.enthit == null )
return

local ent = trace.enthit
if ( !ent.IsPhysicsObject() )
return

local delta = owner.GetCenter() - ent.GetCenter()
local dist = delta.Length()
local ratio = 1.0 - (dist / RANGE)
if (ratio < 0) ratio = 0
if (ratio > 1) ratio = 1

local appliedForce = forward * force * ratio
ent.ApplyForceCenter( appliedForce )
}
59 changes: 59 additions & 0 deletions game/jbmod/scripts/weapon_leafblower.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Leafblower

WeaponData
{
// Weapon data is loaded by both the Game and Client DLLs.
"classname" "weapon_scripted"
"vscript" "weapons/weapon_leafblower"

"printname" "#jbmod_Leafblower"
"viewmodel" "models/weapons/v_pistol.mdl"
"playermodel" "models/weapons/w_pistol.mdl"
"anim_prefix" "pistol"
"bucket" "0"
"bucket_position" "4"

"clip_size" "-1"
"clip2_size" "-1"
"default_clip" "-1"
"default_clip2" "-1"

"primary_ammo" "None"
"secondary_ammo" "None"

"weight" "0"
"item_flags" "0"

// Weapon Sprite data is loaded by the Client DLL.
TextureData
{
"weapon"
{
"font" "WeaponIcons"
"character" "d"
}
"weapon_s"
{
"font" "WeaponIconsSelected"
"character" "d"
}
"weapon_small"
{
"font" "WeaponIconsSmall"
"character" "d"
}
"crosshair"
{
"font" "Crosshairs"
"character" "Q"
}
"autoaim"
{
"file" "sprites/crosshairs"
"x" "0"
"y" "48"
"width" "24"
"height" "24"
}
}
}
6 changes: 6 additions & 0 deletions src/game/client/c_baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ BEGIN_PREDICTION_DATA( C_BaseAnimating )

END_PREDICTION_DATA()

#ifdef JBMOD
BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, CBaseEntity, "Animating models" )

END_SCRIPTDESC();
#endif // JBMOD

LINK_ENTITY_TO_CLASS( client_ragdoll, C_ClientRagdoll );

BEGIN_DATADESC( C_ClientRagdoll )
Expand Down
3 changes: 3 additions & 0 deletions src/game/client/c_baseanimating.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
DECLARE_CLIENTCLASS();
DECLARE_PREDICTABLE();
DECLARE_INTERPOLATION();
#ifdef JBMOD
DECLARE_ENT_SCRIPTDESC();
#endif

enum
{
Expand Down
6 changes: 6 additions & 0 deletions src/game/client/c_basecombatweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

#ifdef JBMOD
BEGIN_ENT_SCRIPTDESC( C_BaseCombatWeapon, BASECOMBATWEAPON_DERIVED_FROM, "Base Combat Weapon" )

END_SCRIPTDESC();
#endif // JBMOD

//-----------------------------------------------------------------------------
// Purpose: Gets the local client's active weapon, if any.
//-----------------------------------------------------------------------------
Expand Down
26 changes: 26 additions & 0 deletions src/game/client/c_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "cdll_bounded_cvars.h"
#include "inetchannelinfo.h"
#include "proto_version.h"
#include "gamestringpool.h"

#ifdef TF_CLIENT_DLL
#include "c_tf_player.h"
Expand Down Expand Up @@ -568,6 +569,12 @@ BEGIN_PREDICTION_DATA_NO_BASE( C_BaseEntity )
#endif
END_PREDICTION_DATA()

#ifdef JBMOD
BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities" )

END_SCRIPTDESC();
#endif // JBMOD

//-----------------------------------------------------------------------------
// Helper functions.
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -6479,6 +6486,25 @@ int C_BaseEntity::GetCreationTick() const
return m_nCreationTick;
}

#ifdef JBMOD
HSCRIPT C_BaseEntity::GetScriptInstance()
{
if ( !m_hScriptInstance )
{
if ( m_iszScriptId == NULL_STRING )
{
char *szName = (char *)stackalloc( 1024 );
g_pScriptVM->GenerateUniqueKey( GetClassname(), szName, 1024 );
m_iszScriptId = AllocPooledString( szName );
}

m_hScriptInstance = g_pScriptVM->RegisterInstance( GetScriptDesc(), this );
g_pScriptVM->SetInstanceUniqeId( m_hScriptInstance, STRING(m_iszScriptId) );
}
return m_hScriptInstance;
}
#endif // JBMOD

//------------------------------------------------------------------------------
void CC_CL_Find_Ent( const CCommand& args )
{
Expand Down
12 changes: 12 additions & 0 deletions src/game/client/c_baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "particle_property.h"
#include "toolframework/itoolentity.h"
#include "tier0/threadtools.h"
#include "vscript_client.h"

class C_Team;
class IPhysicsObject;
Expand Down Expand Up @@ -184,6 +185,9 @@ class C_BaseEntity : public IClientEntity
DECLARE_DATADESC();
DECLARE_CLIENTCLASS();
DECLARE_PREDICTABLE();
#ifdef JBMOD
DECLARE_ENT_SCRIPTDESC();
#endif

C_BaseEntity();
virtual ~C_BaseEntity();
Expand Down Expand Up @@ -1709,6 +1713,14 @@ class C_BaseEntity : public IClientEntity
color32 m_PreviousRenderColor;
#endif

#ifdef JBMOD
public:
HSCRIPT GetScriptInstance();
protected:
HSCRIPT m_hScriptInstance;
string_t m_iszScriptId;
#endif // JBMOD

private:
bool m_bOldShouldDraw;
};
Expand Down
21 changes: 21 additions & 0 deletions src/game/client/classmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CClassMap : public IClassMap
virtual const char *Lookup( const char *classname );
virtual C_BaseEntity *CreateEntity( const char *mapname );
virtual int GetClassSize( const char *classname );
virtual DISPATCHFUNCTION FindFactory( const char *classname );

private:
CUtlDict< classentry_t, unsigned short > m_ClassDict;
Expand Down Expand Up @@ -135,3 +136,23 @@ int CClassMap::GetClassSize( const char *classname )

return -1;
}

DISPATCHFUNCTION CClassMap::FindFactory( const char *classname )
{
int c = m_ClassDict.Count();
int i;

for ( i = 0; i < c; i++ )
{
classentry_t *lookup = &m_ClassDict[ i ];
if ( !lookup )
continue;

if ( Q_strcmp( lookup->GetMapName(), classname ) )
continue;

return lookup->factory;
}

return NULL;
}
2 changes: 2 additions & 0 deletions src/game/client/client_jbmod.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ $Project "Client (JBMod)"
$File "$SRCDIR\game\shared\jbmod\weapon_slam.h"
$File "$SRCDIR\game\shared\jbmod\weapon_smg1.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_stunstick.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_scripted.cpp"
$File "$SRCDIR\game\shared\jbmod\weapon_scripted.h"
}

$Folder "UI"
Expand Down
1 change: 1 addition & 0 deletions src/game/client/iclassmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract_class IClassMap
virtual char const *Lookup( const char *classname ) = 0;
virtual C_BaseEntity *CreateEntity( const char *mapname ) = 0;
virtual int GetClassSize( const char *classname ) = 0;
virtual DISPATCHFUNCTION FindFactory( const char *classname ) = 0;
};

extern IClassMap& GetClassMap();
Expand Down
23 changes: 23 additions & 0 deletions src/game/client/vscript_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "usermessages.h"
#include "hud_macros.h"
#include "iclassmap.h"

#if defined( PORTAL2_PUZZLEMAKER )
#include "matchmaking/imatchframework.h"
Expand All @@ -47,6 +48,22 @@ extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );

#endif // VMPROFILE

void ScriptRegisterEntityClass( const char *pszNewClassname, const char *pszBaseClassname )
{
DISPATCHFUNCTION factory = GetClassMap().FindFactory( pszBaseClassname );
if ( !factory )
{
Warning( "ScriptRegisterEntityClass: Could not find base factory for '%s' on client\n", pszBaseClassname );
return;
}

if ( !GetClassMap().FindFactory( pszNewClassname ) )
{
int size = GetClassMap().GetClassSize( pszBaseClassname );
GetClassMap().Add( pszNewClassname, pszNewClassname, size, factory );
}
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -166,6 +183,7 @@ bool VScriptClientInit()
if( g_pScriptVM )
{
Log_Msg( LOG_VScript, "VSCRIPT: Started VScript virtual machine using script language '%s'\n", g_pScriptVM->GetLanguageName() );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptRegisterEntityClass, "RegisterEntityClass", "Registers a new entity classname mapped to an existing base class" );
ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
ScriptRegisterFunction( g_pScriptVM, Time, "Get the current server time" );
ScriptRegisterFunction( g_pScriptVM, DoIncludeScript, "Execute a script (internal)" );
Expand All @@ -174,6 +192,8 @@ bool VScriptClientInit()
ScriptRegisterFunction( g_pScriptVM, RequestMapRating, "Pops up the map rating dialog for user input" );
#endif // PORTAL2_PUZZLEMAKER

g_pScriptVM->RegisterAllClasses();

if ( GameRules() )
{
GameRules()->RegisterScriptFunctions();
Expand All @@ -183,6 +203,9 @@ bool VScriptClientInit()
g_pScriptVM->RegisterInstance( &g_ScriptPanorama, "Panorama" );
#endif

g_pScriptVM->SetValue( "CLIENT", true );
g_pScriptVM->SetValue( "SERVER", false );

if ( scriptLanguage == SL_SQUIRREL )
{
g_pScriptVM->Run( g_Script_vscript_client );
Expand Down
Loading
Loading