Page 1 of 1
This maybe too far fetched but..
Posted: Wed Jul 02, 2014 8:28 am
by AnthonyBF2
Is there any lua code that can make objects follow the player?
etc; props, cps, an ordnance like a mine, maybe other things like destructible props.
Anything?

Re: This maybe too far fetched but..
Posted: Wed Jul 02, 2014 8:56 am
by razac920
Sure, why not? Just teleport an object behind the player, and update its position continually.
Re: This maybe too far fetched but..
Posted: Wed Jul 02, 2014 10:45 am
by MileHighGuy
Re: This maybe too far fetched but..
Posted: Wed Jul 02, 2014 12:34 pm
by AnthonyBF2
That's a nice lua stuff there but not quite what I wanted to obtain. I don't need choking or anything.
My idea is this:
player spawns, in the script a defined object will follow on constantly on player coordinate.
I suppose the object would act as a shield, if it were to follow around the player.
edit: studying Razac's code, getting an idea
Re: This maybe too far fetched but..
Posted: Wed Jul 02, 2014 8:51 pm
by razac920
Okay I don't know if you want in front of player or behind -- suppose it is in front, then have something like:
Code: Select all
object = [whatever object you want to have around player]
human = nil -- for now just assume only 1 human, this is a SP game
update = CreateTimer("update")
SetTimerValue(update,0.2) -- updates every .2 seconds, adjust as you want
OnTimerElapse(function(timer)
if human and GetCharacterUnit(human) and IsObjectAlive(GetCharacterUnit(human)) then -- human is alive, move object and restart timer
SetEntityMatrix(object, CreateMatrix(0,0,0,0,0,0,1,GetEntityMatrix(GetCharacterUnit(human)))) -- adjust the 1 based on how much in front/behind
SetTimerValue(update,0.2) -- updates every .2 seconds, adjust as you want
StartTimer(update)
end
end,
update)
OnCharacterSpawn(function(player)
if IsCharacterHuman(player) then
human = player
SetEntityMatrix(object, CreateMatrix(0,0,0,0,0,0,1,GetEntityMatrix(GetCharacterUnit(human)))) -- adjust the 1 based on how much in front/behind
StartTimer(update)
end
end)
Re: This maybe too far fetched but..
Posted: Thu Jul 03, 2014 9:48 am
by AnthonyBF2
that's some great stuff thanks for your work

Re: This maybe too far fetched but..
Posted: Thu Jul 03, 2014 10:14 am
by razac920
I haven't tested it, does it work?
Re: This maybe too far fetched but..
Posted: Thu Jul 03, 2014 1:26 pm
by AnthonyBF2
I have not tested it yet. I am trying to create an invisible command post using the geometry of the collision blocks.
That is the object I want to constantly follow the player. The goal is to have enemies spawn around the player constantly.
After I test it I will post back.
Re: This maybe too far fetched but..
Posted: Thu Jul 03, 2014 2:48 pm
by Locutus
You are aware that units spawn at paths/nodes around a command post and not around the command post prop itself?
Moving the prop won't change their spawn location. Instead, simply spawn your units around the player by using a matrix based on the players position with a certain offset.
Re: This maybe too far fetched but..
Posted: Thu Jul 03, 2014 5:07 pm
by razac920
You could try teleporting a command walker whose spawn points are just offset from the vehicle itself, or alternatively just teleport players next to human after spawning. But I agree, simply moving the location of a command post will not work
Re: This maybe too far fetched but..
Posted: Thu Jul 03, 2014 5:14 pm
by AnthonyBF2
I am aware of moving a cp object and the spawns itself.
When I get around to it I am going to mess with the SpawnPointLocation values found on command vehicles