Operation Flashpoint Dragon Rising OFDR Forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

how do you insert to a blank table?

Go down

how do you insert to a blank table? Empty how do you insert to a blank table?

Post by TheGeneral Fri 21 Dec 2012, 13:36

I would like someoen to explain how to insert into a blank table?

Before I go on, I have had this explained to me probably about as much times as I've been told, "Units id's get changed when they spawn you plank!"

But nonetheless I get told sooooo much stuff about the code that in goes in one ear and out the other if I don't have a plain english example infront of me.

NOW!

I have a pla unit spawing set on a timer so every 5 seconds another spawns, then I get my position using local x,y,z = OFP:getPosition("mdog").

Now this is ok for the first unit to find out where I am. But what about the rest that spawn after him? I've been trying to get them to update my position ever 3milsecs to no avail. I even did OFP:follow, thinking they would follow me as soon as they spawn. Nope they just run in a straight line towards where my x,y,z position, then follow me. scratch scratch

This might seem like I am detracking from the thread title but I thought maybe inserting the newly spawned units into a blank table might do it, then using a timer to update myposition ever 3 milsecs. So what effectlively happens is when ever a new unit spawns he won't just run in a straight line he'll follow position.
TheGeneral
TheGeneral
Admin

Points : 780
Reputation : 35
Join date : 2012-12-15

http://maniacaldog.wix.com/keepdralive

Back to top Go down

how do you insert to a blank table? Empty Re: how do you insert to a blank table?

Post by Guest Fri 21 Dec 2012, 13:42

yourTable = {} --this is an empty table

I guessed that much but actually coding it correctly.

where does the commands go, how does it get written inconjuction with the rest of the functions?
Anonymous
Guest
Guest


Back to top Go down

how do you insert to a blank table? Empty Re: how do you insert to a blank table?

Post by TheGeneral Fri 21 Dec 2012, 13:48

Fucking hell! I must have edited your post then sorry! lol!
TheGeneral
TheGeneral
Admin

Points : 780
Reputation : 35
Join date : 2012-12-15

http://maniacaldog.wix.com/keepdralive

Back to top Go down

how do you insert to a blank table? Empty Re: how do you insert to a blank table?

Post by TheGeneral Fri 21 Dec 2012, 13:48

here's my code anyway!

Code:
zombie_death = 0
zombie_spawn = 0

function onEnter_zone1_mdog()
    OFP:addTimer("zombiespawn", 20000)
end

function onEnter_fuelcap_mdog()       
    OFP:addTimer("fueltimer", 60000)
    OFP:displaySystemMessage("stand here to refuel the tanker")
end

function onTimer_zombiespawn()
    OFP:removeTimer("zombiespawn")
    OFP:spawnEntitySetAtEntityPosition("zombieset","zom")
   
end

function onTimer_fueltimer()
    OFP:removeTimer("fueltimer")
    OFP:displaySystemMessage("tanker is full")
end

function onSpawnedReady( setName, setID, tableOfEntities, errorCode )
   
    if setName == "zombieset" then
    local x,y,z = OFP:getPosition("mdog")
    OFP:rapidMove(tableOfEntities[1],"mdog","OVERRIDE")
    OFP:addTimer("zombiespawn",5000)
    OFP:addTimer("mdogpos",3000)
    end
end

function onTimer_mdogpos()
    OFP:removeTimer("mdogpos")
   
    if setName == "zombieset" then
    local x,y,z = OFP:getPosition("mdog")
    OFP:rapidMove("zombies","mdog","OVERRIDE")
    OFP:addTimer("mdogpos",300)
    end
end


   
function onDeath(victim, killer)
    if victim == "zombie" then
    zombie_death = zombie_death + 1
        if zombie_death == 4 then
        OFP:removeTimer("zombiespawn")
        end
    end
end
TheGeneral
TheGeneral
Admin

Points : 780
Reputation : 35
Join date : 2012-12-15

http://maniacaldog.wix.com/keepdralive

Back to top Go down

how do you insert to a blank table? Empty Re: how do you insert to a blank table?

Post by Guest Fri 21 Dec 2012, 15:54

OK, a couple of things here. You can first use the follow order in the onSpawnedReady and they should follow you. I see where you record your position, but you never use that position to tell them where to go. The rapid move order will use your position as a target, so there's no need to figure out your position anywhere else in the code.

Try this instead in your onSpawnedReady. The position timer should not be necessary at all unless you intend to order them to your position at a set interval or something.
Code:

function onSpawnedReady( setName, setID, tableOfEntities, errorCode ) 
    if setName == "zombieset" then
      OFP:follow(tableOfEntities[1], "mdog", 1, "OVERRIDE")
      OFP:addTimer("zombiespawn",5000)
    end
end
I also noticed you used the variable setName in the timer you made to get your new position. You must realize that setName is only passed to the onSpawnedReady function. It is not stored or available to any other functions unless you store it to another variable by saying something like zombieSet == setName. In this case, every time you spawn a new zombie set it will overwrite the zombieSet variable with the new setName, so you have to use a table to sort this if that is what you intend to do. The main point is that you're trying to use the variables produced by the function like setName or setID as global variables when they are local only to the function that they are passed to... in this case onSpawnedReady.

Hope this helps. Get ahold of me on Skype and I'll help explain it a bit more.

Cheers Very Happy
Anonymous
Guest
Guest


Back to top Go down

how do you insert to a blank table? Empty Re: how do you insert to a blank table?

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum