-
Notifications
You must be signed in to change notification settings - Fork 10
/
use_pickup_detection.txt
58 lines (37 loc) · 1.67 KB
/
use_pickup_detection.txt
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
@name use-pickup detection
@persist
# Ever tried to detect when someone picks up or drops an entity with use?
# This chip may prove useful if so:
if( first() ){
runOnTick(1)
# When a prop is picked up by a player, do the following with it:
function onPropPickup(Prop:entity,Player:entity){
print(Player:name() + " picked up " + Prop:toString())
}
# When a prop is dropped by a player, do the following with it:
function onPropDropped(Prop:entity,Player:entity){
print(Player:name() + " dropped " + Prop:toString())
}
}
foreach( N, Ply:entity = players() ){
local Use = Ply:keyAttack2()
if( Ply["use",number] != Use ){ # if( changed(Use) )
Ply["use",number] = Use
if(!Use){ continue } # if they were letting go of E, abort.
rangerFilter(Ply)
local Trace = rangerOffsetHull(60,Ply:shootPos(),Ply:eye(),vec(-8),vec(8))
local Ent = Trace:entity()
if( !Ent:isValid() ){
Trace = rangerOffset(60,Ply:shootPos(),Ply:eye())
Ent = Trace:entity()
}
if( !Ent:isPlayerHolding() ){ continue } # entity didn't actually get picked up; abort
Ply["held",entity] = Ent # update held entity
onPropPickup(Ent, Ply)
}
local Ent = Ply["held",entity]
if( !Ent:isValid() ){ continue } # they're already not holding anything; they have nothing to drop
if( Ent:isPlayerHolding() ){ continue } # if still holding the prop, don't run dropped event
Ply["held",entity] = noentity() # update held entity
onPropDropped(Ent,Ply)
}