-
Notifications
You must be signed in to change notification settings - Fork 10
/
queuepropspawn.txt
117 lines (100 loc) · 3.54 KB
/
queuepropspawn.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@name queuepropspawn
@persist Queue:table
#[ ]#
## E2 Library: QueuePropSpawn ##
## ##
## Adds asynchronous prop spawning ##
## with function callbacks. ##
#[ ]#
if( first() ){
function supressInitializationWarnings(){
Queue = table()
}
###############
##
# queuePropSpawn( MDL:string, POS:vector, ANG:angle )
# Queues a prop spawn for a frozen prop with the provided model, position, and angle.
#
function queuePropSpawn(MDL:string,POS:vector,ANG:angle){
local MiniTable = table()
MiniTable["model",string] = MDL
MiniTable["pos",vector] = POS
MiniTable["ang",angle] = ANG
Queue:pushTable(MiniTable)
}
###############
##
# queuePropSpawn( MDL:string, POS:vector, ANG:angle, CALLBACK:function )
# Queues a prop spawn for a frozen prop with the provided model, position, and angle.
# Calls the provided callback with the spawned entity when the prop spawns.
#
function queuePropSpawn(MDL:string,POS:vector,ANG:angle,CALLBACK:function){
local MiniTable = table()
MiniTable["model",string] = MDL
MiniTable["pos",vector] = POS
MiniTable["ang",angle] = ANG
MiniTable["func",function] = CALLBACK
Queue:pushTable(MiniTable)
}
##
# Callback Example
# Prop is the newly spawned prop
##
function onPropSpawn( Prop:entity ){
print("Prop spawned: " + Prop:toString())
}
###############
##
# queuePropSpawn( MDL:string, POS:vector, ANG:angle, CALLBACK:function, DATA:table )
# Queues a prop spawn for a frozen prop with the provided model, position, and angle.
# Calls the provided callback with the spawned entity and provided DATA when the prop spawns.
#
# DATA is used to pass additional properties into the callback function where needed, such as colors.
#
function queuePropSpawn(MDL:string,POS:vector,ANG:angle,CALLBACK:function,DATA:table){
local MiniTable = table()
MiniTable["model",string] = MDL
MiniTable["pos",vector] = POS
MiniTable["ang",angle] = ANG
MiniTable["func",function] = CALLBACK
MiniTable["data",table] = DATA
Queue:pushTable(MiniTable)
}
##
# Callback Example
# Prop is the newly spawned prop
# Data is the earlier provided DATA:table from when queuePropSpawn was called
##
function onPropSpawnData( Prop:entity, Data:table ){
print("Prop spawned: " + Prop:toString() + " with the following extra data:")
printTable(Data)
}
### INTERNAL ##
##
# queueRead()
# Processes queued prop spawns
#
function number queueRead(){
if(propCanCreate()){
local Read = Queue[1,table]
TMP = propSpawn(Read["model",string],Read["pos",vector],Read["ang",angle],1)
if(!TMP:isValid()){ return 0 }
if(Read:exists("func")){
if(Read:exists("data")){
Read["func",function](TMP,Read["data",table])
}
else{
Read["func",function](TMP)
}
}
Queue:remove(1)
return 1
}
return 0
}
}
event tick(){
while(Queue:exists(1)){
if(!queueRead()){ break }
}
}