Well I seem to have hit a wall. I tried making it store offsets per-side and per-model. it does this by reading convars/using concmd.
Problem is, the values keep getting confused with each other due to some unseen delay somewhere. Yesterday it started deciding to randomly subtract 0.01 from all the values.
It's an insanely useful feature, but it's almost unusable in ti's current state. I've tried everything I can think of.
Only reason for it that I can think of is that it's reading and storing the convars before the ones for the new side actually take effect.
At this point, I actually could use a little code advice.
Code:
#Stacker
if (Mode==4 & owner():weapon():type()=="gmod_tool" & owner():tool()=="ol_stacker"){
if (owner():aimEntity():owner()==owner()){
Ent=owner():aimEntity()
}
else {
Ent=noentity()
}
if (Ent:type()=="prop_physics"){
Dir=Ent:toLocal(Ent:pos()+owner():eyeTrace():hitNormal())
if (!changed(Dir)){
if(!Delay) {
#Read the convars, round them to 3 decimal places.
STR=round(convarnum("ol_stacker_offsetx"),3)+"|"+round(convarnum("ol_stacker_offsety"),3)+"|"+round(convarnum("ol_stacker_offsetz"),3)+"|"+round(convarnum("ol_stacker_rotp"),3)+"|"+round(convarnum("ol_stacker_roty"),3)+"|"+round(convarnum("ol_stacker_rotr"),3)
if (STR!=OLDSTR){
#Removes models/ from the path, in an attempt to save filesize.
#Filesize is my main concern right now, work with enough different props and it could conceivably become too large.
#Each path gets saved up to 6 times with a number in front of it for the side.
Model=StackDir+Ent:model():sub(8)
Stacker[Model,string]=STR
}
OLDSTR=STR
Delay=1
timer("delay",30)
}
}
else {
if (Dir:x()>0.8){
StackDir=3
}
if (Dir:x()<-0.8){
StackDir=4
}
if (Dir:y()>0.8){
StackDir=6
}
if (Dir:y()<-0.8){
StackDir=5
}
if (Dir:z()>0.8){
StackDir=1
}
if (Dir:z()<-0.8){
StackDir=2
}
concmd("ol_stacker_dir "+StackDir)
Model=StackDir+Ent:model():sub(8)
if (Stacker[Model,string]){
Offsets=Stacker[Model,string]:explode("|")
}
else {
Offsets="0|":repeat(6):explode("|")
}
concmd("ol_stacker_offsetx "+Offsets[1,string])
concmd("ol_stacker_offsety "+Offsets[2,string])
concmd("ol_stacker_offsetz "+Offsets[3,string])
concmd("ol_stacker_rotp "+Offsets[4,string])
concmd("ol_stacker_roty "+Offsets[5,string])
concmd("ol_stacker_rotr "+Offsets[6,string])
}
}
} In my attempts to fix this, I made it not store values when it needs to write them, and then I also made it not try to write the values unless they changed. I also added a 30 ms delay between writes. (all the delay timer does is set Delay to 0, all my timers are the last things to run in the code.)
I just thought that maybe I can move the delay to occur after I WRITE the values, so I'll try that. Any other ideas are welcome.
Other than that, anyone have any ideas on how I can "compress" the model path to save filesize? Saving the entire model path 6 times for each different model will eat up space pretty quick if you use the stacker with a lot of different props.
I'm looking into hash algorithms at the moment, should be able to come up with something simple to reduce any string to some small hex number or something easy to calculate.
EDIT: nevermind this part, I grew a brain and realized I can glon inside of gloned glon. One index for the model storing an array containing arrays of the values. Whee.
Bookmarks