+ Reply to Thread
Results 1 to 4 of 4

Thread: Help: Using Chat commands to retreive vectors from an Array

  1. #1
    Wire Noob Legendsmith's Avatar
    Join Date
    Jul 2009
    Posts
    7

    Question Help: Using Chat commands to retreive vectors from an Array

    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):

    Code:
    @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)
    My problem is that Movetarg does not change from 0.0,0.0,0.0
    It's like
    Code:
    Movetarg = MovArray[Movetype,vector]
    isn't executing
    Last edited by Legendsmith; 04-27-2010 at 12:45 AM.

  2. #2
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Re: Help: Using Chat commands to retreive vectors from an Array

    Use a table.
    Tables index by strings.
    Edit:
    You didn't persist Movetype.
    .siht daer ot gniyrt emit detsaw ev'uoY

  3. #3
    Wire Noob Legendsmith's Avatar
    Join Date
    Jul 2009
    Posts
    7

    Default Re: Help: Using Chat commands to retreive vectors from an Array

    Quote Originally Posted by Whosdr View Post
    Use a table.
    Tables index by strings.
    Not sure how to set retrieve keys when creating the table.
    Would this work?
    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)
    Quote Originally Posted by Whosdr View Post
    Edit:
    You didn't persist Movetype.
    *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.
    Last edited by Legendsmith; 04-27-2010 at 02:40 AM. Reason: Fixing syntax

  4. #4
    Wire Sofaking ktccd's Avatar
    Join Date
    Sep 2009
    Posts
    751

    Default Re: Help: Using Chat commands to retreive vectors from an Array

    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.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots