Page 1 of 1

Disabling spawn for a certain player in MP [Solved]

Posted: Sun Apr 12, 2015 12:16 pm
by Noobasaurus
What I want to have happen is when someone dies, they are unable to spawn back in. However, I can't do this with changing the teams of the CPs or their spawnpaths. I attempted to use a list but I have no clue to go about a) checking if they are a player who died b) marking them as a player who died. I figured the initial code might be something like this:
Hidden/Spoiler:
[code]
unitsAlive = {}

unitSpawn = OnCharacterSpawn(
function(character)
if ScriptCB_InMultiplayer() then
playerInfo = {playerUnit = GetCharacterUnit(character),
playerTeam = GetCharacterTeam(character),
playerMarked = 0
}
unitsAlive[character] = playerInfo
if unitsAlive[playerMarked] == 0 then --if they're not marked
ReleaseCharacterSpawn(character)
elseif unitsAlive[playerMarked] == 1 then --if they're marked
--don't release their spawn
end
end
end)

unitDeath = OnCharacterDeath(function(character)
if ScriptCB_InMultiplayer() then
if unitsAlive[playerUnit] == GetCharacterUnit(character) then
unitsAlive[playerMarked] = 1
end
end
end)
[/code]
But I know that it won't work in this stage, because I only know half about how to get data from lists, how it actually stores the data, and how to retrieve data. How can I use the information of a character that spawns to search the list for him, and if it finds that his playerMarked value is one, then it stops him from spawning?

Re: Disabling spawn for a certain player in MP

Posted: Sun Apr 12, 2015 12:36 pm
by razac920
I found a nice way of disabling spawn (and keeping the dead body from vanishing) by using DeactivateObject on the deceased character's CharacterUnit (note that once the character is dead, GetCharacterUnit won't work, so you'll have to store that information ahead of time).

Re: Disabling spawn for a certain player in MP

Posted: Sun Apr 12, 2015 1:49 pm
by Noobasaurus
Oh I forgot to mention that I tried that and it doesn't seem to work in MP. The dead body stays, but the player is still allowed to spawn.

OH WAIT...you said do that to their unit which would be stored ahead of time...ooooh. That would make sense.

EDIT: So I tried a few things, and I'm getting closer.
Hidden/Spoiler:
[code]
unitsAlive = {}

unitSpawn = OnCharacterSpawn(
function(character)
if IsCharacterHuman(character) then
ReleaseCharacterSpawn(unitSpawn)
--if ScriptCB_InMultiplayer() then
playerInfo = {playerUnit = GetCharacterUnit(character)
}
unitsAlive[character] = playerInfo
print("Player info recorded")
--end
end
end)

unitDeath = OnCharacterDeath(function(object, killer)
--if ScriptCB_InMultiplayer() then
print("Someone died!")
if unitsAlive[object] then
print("unitsAlive[object]", unitsAlive[object])
DeactivateObject(unitsAlive[object])
end
--end
end)
[/code]
However, I get this error:

Code: Select all

Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `DeactivateObject' (string expected, got table)
stack traceback:
	[C]: in function `DeactivateObject'
	(none): in function <(none):428>
I'm not sure on how to get a string out of this. The only string that I can think of if the player's unit class, but I don't see how that's relevant to deactivating their object.

EDIT2: Okay, so I just realized that I don't need all of that fancy stuff for what I'm doing. I'm a dummy. Here's what I've got.
Hidden/Spoiler:
[code]
unitDeath = OnObjectKill(function(object, killer)
--if ScriptCB_InMultiplayer() then
print("Someone died!")
if readyToStart == 1 then
print("check1")
print("objteam ", GetObjectTeam(object))
if GetObjectTeam(object) == 1 then
SetEntityMatrix(object, finalDestination)
DeactivateObject(object)
elseif GetObjectTeam(object) == 2 then
DeactivateObject(object)
end
end
--end
end)
[/code]
Basically if they're on one team, we don't want to see their dead body. If they're on the other, it's fine. However, I can still spawn even after the DeactivateObject. Everything else works fine. I'm not sure why I can still spawn.

EDIT3: Whoops, forgot that they needed 0 reinforcements. Solved.