aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Custom/mod/scripts/vscripts/_northstar_devcommands.gnut
blob: ac08c7b559291be6ae37382920b4c02a8121cda5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
untyped
global function NorthstarDevCommands_Init

void function NorthstarDevCommands_Init()
{
	AddClientCommandCallback( "noclip", ClientCommandCallbackToggleNoclip )
	AddClientCommandCallback( "script", ClientCommandCallbackEvalScript )
	AddClientCommandCallback( "kill", ClientCommandCallbackKill )
	AddClientCommandCallback( "explode", ClientCommandCallbackExplode )
}

bool function ClientCommandCallbackToggleNoclip( entity player, array<string> args )
{
	if ( GetConVarInt( "sv_cheats" ) != 1 )
		return true

	if ( player.IsNoclipping() )
		player.SetPhysics( MOVETYPE_WALK )
	else
		player.SetPhysics( MOVETYPE_NOCLIP )
		
	return true
}

bool function ClientCommandCallbackEvalScript( entity player, array<string> args )
{
	if ( args.len() < 1  || GetConVarInt( "sv_cheats" ) != 1 )
		return true
	
	// todo: rewrite this at some point to use a concommand because clientcommands can't just take in a single string with spaces, quotes etc
	// should just have the concommand call a clientcommand manually with properly formatted args
	string joinedArgs = args[0]
	for ( int i = 1; i < args.len(); i++ )
		joinedArgs += " " + args[i]

	try
	{
		compilestring( joinedArgs )()
	}
	catch (exception)
	{
		// should probably send this to the client at some point
		// no need to log here because compilestring errors already do that
	}

	return true
}

bool function ClientCommandCallbackKill( entity player, array<string> args )
{
	if ( IsAlive( player ) && GetConVarInt( "sv_cheats" ) == 1 )
		player.Die()
	
	return true
}

bool function ClientCommandCallbackExplode( entity player, array<string> args )
{
	if ( IsAlive( player ) && GetConVarInt( "sv_cheats" ) == 1 )
		player.Die( null, null, { scriptType = DF_GIB } )
	
	return true
}