Spawning units with a script

Interesting mapping tools and mapping help.

Moderator: Morax

Spawning units with a script

Postby TREEMAN » 12 Dec 2016, 00:25

Hey guys, I've been studying the lua code of survival maps for about 4 days now. No matter how much I try I can't get units to spawn. You use the "createunithpr" function correct?
TREEMAN
 
Posts: 4
Joined: 12 Dec 2016, 00:17
Has liked: 0 time
Been liked: 0 time
FAF User Name: TREEMAN437

Re: Spawning units with a script

Postby KeyBlue » 12 Dec 2016, 00:38

You should be able to use that, yes.

Need to see some code snippets, or even your entire map.
Can't exactly give feedback when I don't know what you're trying to do.
User avatar
KeyBlue
Priest
 
Posts: 403
Joined: 28 Jan 2016, 01:06
Has liked: 140 times
Been liked: 93 times
FAF User Name: KeyBlue

Re: Spawning units with a script

Postby TREEMAN » 12 Dec 2016, 00:43

I'll post some when I get home from work. Really I'm just trying to test it with a basic spawn function.
TREEMAN
 
Posts: 4
Joined: 12 Dec 2016, 00:17
Has liked: 0 time
Been liked: 0 time
FAF User Name: TREEMAN437

Re: Spawning units with a script

Postby TREEMAN » 12 Dec 2016, 07:10

Ok, so I just tested this script and it broke my map.
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')

function OnPopulate()
ScenarioUtils.InitializeArmies();
SpawnUnit();
end

function OnStart(self)
end

function SpawnUnit()
local spawn = CreateUnitHPR("URB0101", "NEUTRAL_CIVILIAN", Random(312,492), 25.984375, Random(312,492), 0,0,0);
end
TREEMAN
 
Posts: 4
Joined: 12 Dec 2016, 00:17
Has liked: 0 time
Been liked: 0 time
FAF User Name: TREEMAN437

Re: Spawning units with a script

Postby speed2 » 12 Dec 2016, 09:01

You should open the game log "F9" and the game will tell you what you did wrong

This works:
Code: Select all
local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua')

function OnPopulate()
   ScenarioUtils.InitializeArmies()
   SpawnUnit()
end

function OnStart(self)
end

function SpawnUnit()
   local spawn = CreateUnitHPR('urb0101', 'NEUTRAL_CIVILIAN', Random(40,50), 25.984375, Random(40,50), 0,0,0)
end
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: Spawning units with a script

Postby TREEMAN » 12 Dec 2016, 19:56

Thank you for the advice, I didn't know that you could open a log in game.
TREEMAN
 
Posts: 4
Joined: 12 Dec 2016, 00:17
Has liked: 0 time
Been liked: 0 time
FAF User Name: TREEMAN437


Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest