PDA

View Full Version : Spawning units with upgrades



MarkDawg
21st Jan 10, 2:34 PM
Hello I was wondering if there was any way to Spawn units with upgrades we choose using the scar files not rbf's?

Miguel
21st Jan 10, 4:26 PM
Yes, there is. It seems that most of your problems can be solved by a quick look through the SCARDoc, so if you don't already have it, here it is (http://cohpatch.relic.com/relic/dow2/dow2scardoc.zip)

The function you want is

Util_CreateSquads( PlayerID player, SGroupID sgroup, SquadBlueprint/Table sbp, Integer/String level, Marker/Pos/SGroup/EGroup spawn_point[, Position destination, Integer numsquads, Integer loadout, WargearTable wargear] )
The last argument is a table of wargear that the squad will start the game with. If you really want an upgrade, and not wargear, then you'll have to apply one just after the squad is spawned by using

Cmd_InstantSquadUpgrade( SGroupID sgroup, UpgradeID upgradeid[, Integer count] ) .

Remember to use the SCARDoc ;)

MarkDawg
21st Jan 10, 4:42 PM
Wow thanks man!

PrivateJson
22nd Jan 10, 12:10 AM
Thanks for the ScarDoc Miguel, just what I needed! :)

I've actually tried with exactly that method, without any luck. I'm trying to spawn a tac marine squad with the sergeant. No luck so far. I'm thinking that maybe the restrictions (in this case, level 2 hq for sergeant upgrade) is blocking. I'm still a newbie with this modding thing, so I'm not sure yet whether these scar methods can ignore any requirements, or not.

EDIT: Or maybe this is what's making it not work: "Note that this command will do nothing if called from within scenario initialization. It will only work if the simulation is already running."

Thanks,
Steen

Miguel
22nd Jan 10, 1:03 AM
Ah, well if you're adding leaders, that's a bit different.

There is a function SGroup_AddLeaders( SGroupID sgroup ), but I'm not sure if it actually works (some functions Relic have half made, but didn't finish)

As for using Cmd_InstantSquadUpgrade(), yes, you'll have to do that a but not inside the OnGameSetup() and OnInit() methods. Try using a one shot rule (Rule_AddOneShot(), look it up in the SCARDoc) that fires less than a second after.

PrivateJson
22nd Jan 10, 1:24 AM
Thanks, I'll try playing around with those fine ideas when I get back from work!

I actually never did find a OnGameSetup or OnInit method, but well, it works anyway I guess! :rofl:

Miguel
22nd Jan 10, 2:17 AM
Well I'd seriously consider using the OnInit() function so that its all setup before the game actually starts.

You have to add OnInit functions by using the AddInit() function, but you can name your function whatever you want. E.G:


Scar_AddInit(fMyInitiateFunction)
function fMyInitiateFunction()
--Insert Code Here
end

Whereas the On Game Setup method is automatically called, but it has to be named the same thing each time:

function OnGameSetup()
--Insert Code Here
end

PrivateJson
24th Jan 10, 5:18 AM
Well, I got it working now!

It looks like the problem was: "It will only work if the simulation is already running". I've moved it to my "tick" method, so the first time the method is called, all units are upgraded with the selected upgrades (including adding a sergeant).

So the method I use is: Cmd_InstantSquadUpgrade

Again, thanks,
Steen

Miguel
24th Jan 10, 4:42 PM
How often is that tick function? I'd be careful not to make it an every frame rule.

PrivateJson
25th Jan 10, 12:15 AM
It's a 2 sec tick, but the upgrades are only added the first time it runs! I'll probably move it to a "run once" rule. But for now I'm good.