This is what I’ve been trying, and it’s not working. I’m not sure why I can’t associate subscribe from the “OnPlayerSpawn” part to the “GrantVisualEffect” part.
@editable
var PlayerSpawners : []player_spawner_device = array{}
@editable
PlayerVisualEffect : visual_effect_powerup_device = visual_effect_powerup_device{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
set ElimsToEndGame = WeaponGranters.Length;
InitPlayers()
InitPlayers() : void=
AllPlayers := GetPlayspace().GetPlayers()
for (Player : AllPlayers, FortCharacter := Player.GetFortCharacter[]):
if (set PlayerMap[Player] = 0, WeaponTier := PlayerMap[Player]):
FortCharacter.EliminatedEvent().Subscribe(OnPlayerEliminated)
GrantWeapon(Player, WeaponTier)
OnPlayerSpawn(Player : player) : void=
Print("Player spawning")
for (PlayerSpawned : PlayerSpawners):
PlayerSpawned.SpawnedEvent.Subscribe(GrantVisualEffect)
GrantVisualEffect(Agent : ?agent) : void=
if (Player := Agent?):
PlayerVisualEffect.Pickup(Player)
The error is at the last part of the OnPlayerSpawn section with (GrantVisualEffect) underlined in red. The error message reads:
“This function parameter expects a value of type agent->void, but this argument is an incompatible value of type ?agent->void.(3509)”
Try changing your GrantVisualEffect function to this!
GrantVisualEffect(Agent : agent) : void=
if (Player := Agent):
PlayerVisualEffect.Pickup(Player)
I dont think it’s possible for the PlayerSpawner SpawnedEvent to return without a Player/Agent (I’m not sure which it returns!), so it’s not necessary to use a ?
(This is my first time attempting to help someone here! I don’t know too much and I could be wrong, good luck though!)
Thanks for the help! I’m open to anything ideas, including a completely different way applying an effect on a player spawn. Unfortunately, the edit you suggested underlined “(Player := Agent):” on that second line you posted with the error message “Expected an expression that can fail in the ‘if’ condition clause(3513)” It did make the previous red underline go away, though!
in the if statement you’re not testing anything
i assume you wanna test if agent is a player so i would write it as
# tests if agent is a player. typecast Agent to player
# if the cast is successful then grant the powerup
if (Player := player[Agent]):
PlayerVisualEffect.Pickup(Player)
Thanks, that resolved the error! Unfortunately, the visual effect is still not applying at spawn! Well, I’ll keep looking for new approaches, and thanks for your help anyway.
is OnPlayerSpawn(Player : player) : void= called somewhere?
if not then all your player spawners aren’t being subscribed to.
which would mean GrantVisualEffect is never called
Hey, that worked! thanks! And most importantly I learned something. I get what you mean by “nothing being passed into it” so I should have left it blank. I appreciate the help!
no problem, when i replicated it i noticed its firing at the beginning as well. i would put a Sleep to avoid giving the players the powerup when the game starts. unless thats what you want as well
OnBegin<override>()<suspends>:void=
set ElimsToEndGame = WeaponGranters.Length;
InitPlayers()
Sleep(1.0)
OnPlayerSpawn()
Ahh cool, thanks. I do want it to be applied at start as well, but it’s always helpful to learn more about functionality in case I need it later, so I appreciate that.