Skip to content

Commit 7c47787

Browse files
committed
Add paintgun local addon.
1 parent a681fbd commit 7c47787

4 files changed

Lines changed: 106 additions & 0 deletions

File tree

paintgun/.assets/thumb.jpg

339 KB
Loading

paintgun/addon.kv3

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
2+
{
3+
mod = "Paintgun (★)"
4+
description = "Grants the Paintgun to the player in every map.\n\nEnables sv_cheats 1!\n\nVersion 1.0.0"
5+
type = "Other"
6+
id = 0
7+
thumbnail = ".assets/thumb.jpg"
8+
authors =
9+
[
10+
"P2:CE Team"
11+
]
12+
dependencies = [ ]
13+
tags =
14+
[
15+
"Scripts"
16+
]
17+
ignore = [ ]
18+
metadata =
19+
{
20+
}
21+
assets =
22+
{
23+
}
24+
mounted_by_default = false
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// table containing useful dev functions
2+
if(!("PG_Dev" in getroottable())) {
3+
::PG_Dev <- {
4+
function msg(msg) {
5+
printl("[PAINT GUN] " + msg)
6+
}
7+
8+
function msgDeveloper(msg) {
9+
if(GetDeveloperLevel() > 0) printl("[PAINT GUN - DEV] " + msg)
10+
}
11+
12+
function msgError(msg) {
13+
printl("[PAINT GUN - ERROR] " + msg)
14+
}
15+
16+
function EntFireByHandleCompressed(ent, input, param = "", delay = 0.0, activator = null, caller = null) {
17+
if(ent != null) EntFireByHandle(ent, input, param, delay, activator, caller)
18+
else PG_Dev.msgDeveloper("Tried to fire null entity!")
19+
}
20+
}
21+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
if(!("Entities" in this)) return
2+
3+
IncludeScript("paintgun/helper.nut")
4+
5+
function PG_scriptInit() {
6+
if(GetPlayer() != null) {
7+
// check if the script has already been initialised
8+
if(Entities.FindByName(null, "paintgun_setupdone") != null) {
9+
PG_Dev.msgDeveloper("Setup has already been completed, skipping...")
10+
return
11+
} else {
12+
// check if paint is enabled, if not, enable it and restart the map
13+
if(!IsPaintEnabled()) {
14+
PG_Dev.msgError("Paint is not enabled! Enabling paint and restarting map...")
15+
16+
local serverCommand = CreateEntityByName("point_servercommand", {})
17+
PG_Dev.EntFireByHandleCompressed(serverCommand, "Command", "sv_cheats 1; sv_force_enable_paint_in_map 1; restart", FrameTime())
18+
19+
return
20+
}
21+
22+
PG_GivePaintgun()
23+
24+
// spawn initialisation marker entity
25+
local hasBeenSetupEntity = CreateEntityByName("info_target", {
26+
targetname = "paintgun_setupdone"
27+
})
28+
29+
PG_Dev.msgDeveloper("Script initialised.")
30+
}
31+
} else {
32+
PG_Dev.msgError("Player entity not found!")
33+
}
34+
}
35+
36+
function PG_GivePaintgun() {
37+
PG_Dev.msg("Giving player the paintgun...")
38+
39+
// give paintgun with all paints
40+
UpgradePlayerPaintgun()
41+
42+
// allow cubes to become visibly painted
43+
SendToConsole("sv_force_upgrade_weighted_cube 1")
44+
45+
// kill any weapon_portalgun entities in the map
46+
for(local pgun = null; pgun = Entities.FindByClassname(pgun, "weapon_portalgun");) {
47+
PG_Dev.EntFireByHandleCompressed(pgun, "Kill")
48+
}
49+
}
50+
51+
// override these functions to not do anything to prevent the player being given a portal gun too soon (and prevent console errors!)
52+
function GivePlayerPortalgun() {
53+
PG_Dev.msg("Preventing player from receiving a portal gun...")
54+
}
55+
function UpgradePlayerPortalgun() {
56+
PG_Dev.msg("Preventing player from receiving a portal gun upgrade...")
57+
}
58+
59+
PG_auto <- CreateEntityByName("logic_auto", {spawnflags = 1})
60+
PG_auto.ConnectOutput("OnMapSpawn", "PG_scriptInit")

0 commit comments

Comments
 (0)