Use a table.
Tables index by strings.
Edit:
You didn't persist Movetype.
I'm trying to save myself a bit of coding here and putting all possible vectors into an array where I can easily call them from with chat commands. Unfortunately It's not working.
This is my code (Most irrelevant code has been removed. I don't want minges coming in and stealing the code for this and minging with it):
My problem is that Movetarg does not change from 0.0,0.0,0.0Code:@outputs Count VecTarget:vector PTick Spawn Weight Add1 R P Target:entity Movetarg:vector MovArray:array @persist Vectarget GPS:vector Array:array Prop:entity A:angle LastSaid:array runOnTick(2) runOnChat(1) MovArray = array(((owner():pos()-GPS+vec(0,0,200))*Weight),((owner():aimPos()-GPS+vec(0,0,200))*Weight),((Target:pos()-GPS+vec(0,0,200))*Weight)) GPS = Prop:pos() LastSaid=owner():lastSaid():explode(" ") if(chatClk(owner())&LastSaid:string(1)=="!move"){ Movetype=LastSaid:string(2):toNumber() } Movetarg = MovArray[Movetype,vector] Prop:applyForce(Movetarg + $Movetarg*8)
It's likeisn't executingCode:Movetarg = MovArray[Movetype,vector]
Last edited by Legendsmith; 04-27-2010 at 12:45 AM.
Use a table.
Tables index by strings.
Edit:
You didn't persist Movetype.
.siht daer ot gniyrt emit detsaw ev'uoY
Not sure how to set retrieve keys when creating the table.
Would this work?
*Facepalm* Of course. I can't believe I didn't see that. That fixed it but having a table to retrieve with actual strings seems nice.Code:@outputs Count VecTarget:vector PTick Spawn Weight Add1 R P Target:entity Movetarg:vector MovTable:table LastSaid:array @persist Vectarget GPS:vector Array:array Prop:entity A:angle Movetype:string runOnTick(2) runOnChat(1) if(first() | duped()){ Prop = entity():isWeldedTo() Add1 = 0 Weight = 0 MovTable = table() } MovTable["follow",vector]=((owner():pos()-GPS+vec(0,0,200))*Weight) MovTable["aim",vector]=((owner():aimPos()-GPS+vec(0,0,200))*Weight) MovTable["target",vector]=((Target:pos()-GPS+vec(0,0,200))*Weight)
Last edited by Legendsmith; 04-27-2010 at 02:40 AM. Reason: Fixing syntax
Working on code for this. Will edit later, but lunch is now and I gotta hurry.
EDIT:
This is an example of how to retrieve vectors from a table by chat:
Code:@name Archive @outputs [Retrieved]:vector @persist [Said]:array @persist [Archive]:table @persist [Target]:entity @persist [Mode]:string if (first()|duped()|clk("Update")) { Archive["aim",vector] = owner():aimPos() Archive["follow",vector] = owner():toWorld(owner():forward()*-50) ##This makes the position 50 units behind you## Archive["target",vector] = Target:toWorld(Target:boxCenter()) ##timer## timer("Update",100) runOnChat(1) if (first()) { Mode = "follow" } } if (chatClk(owner())) { Said = owner():lastSaid():lower():explode(" ") if (Said[1,string]=="archive") { Mode = Said[2,string] } } Retrieved = Archive[Mode,vector] if (clk("Find") & Mode=="target") { Target = findPlayerByName(Said[3,string]) timer("Find",10000) }
Last edited by ktccd; 04-27-2010 at 04:34 AM.
Bookmarks