And that still doesn't solve the issue, it's now in the find.LUA, but says it expects a table.
![]()
And that still doesn't solve the issue, it's now in the find.LUA, but says it expects a table.
![]()
I wish i was good enough in E-2 to even help out. Though at least I can somewhat read the code
Just one more reason why I have to get better at E-2 ....
EPIC!
I have to see a vid of this when it is finished.
Wow! This project is amazing, and I have already learnt quite a lot just reading through the code!
Anything that's wrong with the body part finding code at the moment must be something with the LUA, because I've tried hard to sequentially remove each and every entity discovery function past the sphere and the error remains, even down to using findResult(Check) and removing the findSortByDistance(), it just sticks around for some reason.
There's only one table in the entire code and not once does any table interact with the entity discovery functions.
your little pet will destroy all servers, well done i want one. oh can it wire with any contraption like with a sort of interface part. and anyway wired wirers are rare, try a body part networking system, it will be easyer and will cause cahos on all servers, long live cronus
Body part networking system?
Care to elaborate on that?
Okay, developments with the prop finding code. Recent alterations in the find.lua seem to have cured the error I was getting so I've been forging ahead in perfecting it.
This works for the most part, but an arm and a leg aren't getting assigned (Typically I'm seeing Arm1 and Leg2) and whilst I could cancel out the duplicate assignments with a simple Potents:remove(Check) line it seems to negate any of the parts being assigned for some reason.[highlight=E2]@name Cronus body part finder
@outputs SiD TiD PiD A1iD A2iD L1iD L2iD
@persist O:entity C:entity Body:table GT
@persist Search Pierre:string Part Potents:array Pos Check
@persist Flip Switch
@persist Skull:entity Torso:entity Pelvis:entity
@persist Arm1:entity Arm2:entity Leg1:entity Leg2:entity
if(first()){
O = owner()
C = entity()
GT = 10
#Setting body part box preferentials
Body:setVector("Skull",vec(17,14,15))
Body:setVector("Torso",vec(36,36,1))
Body:setVector("Pelvis",vec(19,19,6))
Body:setVector("Arm",vec(24,24,12))
Body:setVector("Leg",vec(10,10,43))
#Running initial prop search
findInSphere(Cos(),1000)
findClipToClass("prop_physics")
findSortByDistance(Cos())
Potents = findToArray()
Check = 1
Flip = 1}
#Entity discovery flipswitch
if(Flip){
timer("playerED",findPlayerUpdateRate())
timer("chipED",findUpdateRate())
if(clk("playerED")){Switch++}
if(clk("chipED")){Switch++}
if(Switch == 2){
Switch = 0
Flip = 0}}
runOnChat(1)
#Initiating a new area check for body props
if(O:lastSaid() == "!body check" & chatClk(O) & !Flip){
findInSphere(Cos(),1000)
findClipToClass("prop_physics")
findSortByDistance(Cos())
Potents = findToArray()
Flip = 1}
#Changing the give/take value
if(O:lastSaid():lower():left(3) == "!gt" & chatClk(O)){
Mes = O:lastSaid():lower()
GT = Mes:right(Mes:length()-4):toNumber()}
#Checking for missing body parts
timer("bod_check",10)
if(clk("bod_check")){
if(!Skull){Pierre = "Skull", Part = 0}
elseif(!Torso){Pierre = "Torso", Part = 1}
elseif(!Pelvis){Pierre = "Pelvis", Part = 2}
elseif(!Arm1){Pierre = "Arm",Part = 3}
elseif(!Arm2){Pierre = "Arm",Part = 4}
elseif(!Leg1|!Leg2){Pierre = "Leg", Part = 5}
elseif(!Leg2){Pierre = "Leg", Part = 6}
Search = 1}
#Checking the props
if(Search){
runOnTick(1)
E = Potents:entity(Check)
if(tickClk()){
if(!E:isFrozen() & E:hasConstraints() == 0){
#Prop box elements
Box = E:boxSize()
L = Box:x()
W = Box:y()
H = Box:z()
#Part box elements
Bod = Body:vector(Pierre)
BodX = Bod:x()
BodY = Bod:y()
BodZ = Bod:z()
#Box element comparison
if(L < BodX+GT & L > BodX-GT){Pos++}
if(W < BodY+GT & W > BodY-GT){Pos++}
if(H < BodZ+GT & H > BodZ-GT){Pos++}
if(Pos == 3){
#Prop to body part assignment
if(!Part){Skull = E}
elseif(Part == 1){Torso = E}
elseif(Part == 2){Pelvis = E}
elseif(Part == 3){Arm1 = E}
elseif(Part == 4){Arm2 = E}
elseif(Part == 5){Leg1 = E}
elseif(Part == 6){Leg2 = E}
Search = 0
Check = 1}
else{
Pos = 0
if(Check != Potents:count()){Check++}
else{
Search = 0
Check = 1}}}
elseif(Check != Potents:count()){Check++}
else{
Search = 0
Check = 1}}}
#Body part ID output
timer("bpart_id",10)
if(clk("bpart_id")){
SiD = Skull:id()
TiD = Torso:id()
PiD = Pelvis:id()
A1id = Arm1:id()
A2iD = Arm2:id()
L1iD = Leg1:id()
L2id = Leg2:id()}[/highlight]I also broke the code up a bit and added some comments for comprehension. I've found it easier also to wrap large bundles of code in an if statement rather than add things like " & tickClk()" to them, which reduces readibility but makes it easier to understand where it is readable...I think.
And here's a quick idea for some efficiency improving:
Currently, we get the occasional find event and cut it to fit what is presently needed, and then have to wait a little bit to get a new event.
To improve efficiency, how about we make a full basic findInSphere(N,V), followed by the usual findSortByDistance(V), and findToArray() and then filter them in a looping code section into different arrays (NPCs, Players, and Props, etc.). Each time there's a new find event, the arrays are emptied and then restocked. That way, we get the biggest bang for our buck from each find event, though it takes slightly longer to respond.
So a way this might work could be using a Props array, an NPCs array, and a Players array:[highlight=E2]#Emptying arrays
Plays = NPCs = Props = array()
#Find event
findInSphere(1000,Chipos())
findSortByDistance(Chipos())
Find = findToArray()
SortFind = 1
#Sorting
if(SortFind){
timer("find_sort",10)
if(clk("find_sort")){
Ent = Find:entity(Check)
if(Ent:isPlayer){Plays:setEntity(Plays:count()+1,E nt}
elseif(Ent:isNPC){NPCs:setEntity(NPCs:count()+1,En t}
elseif(Ent:class() == "prop_physics"){ #Prop class entity that isn't already a body part
if(Ent:id() != Skull:id() & Ent:id() != Torso:id() & Ent:id() != Pelvis:id() &
Ent:id() != Leg1:id() & Ent:id() != Leg2:id() &
Ent:id() != Arm1:id() & Ent:id() != Arm2:id()){
Props:setEntity(Props:count()+1,Ent}}
if(Check != Find:count()){Check++}
else{SortFind = 0,Check = 1,Find = array()}}}[/highlight]
Last edited by Lyinginbedmon; 06-07-2009 at 04:02 AM.
The Olympus Technologies drones, totally not SkyNet in Gmod form.
Cronus: The Ultimate Drone, definitely SkyNet in Gmod form.
The gBrain Project, the drone controls system that thinks it's better than you
Bookmarks