-
-
Save spentak/816d340200c7dafd7673e7f915b31b5b to your computer and use it in GitHub Desktop.
using { /Fortnite.com/Devices } | |
using { /Verse.org/Simulation } | |
using { /Fortnite.com/Teams } | |
using { /Fortnite.com/Game } | |
using { /Fortnite.com/Characters } | |
using { /UnrealEngine.com/Temporary/Diagnostics } | |
# This code is a UEFN Fortnite "Device" for managing a Gun Game feature | |
# where players fight online and get a new weapon after each elimination | |
# A Verse-authored creative device that can be placed in a level | |
game_manager := class(creative_device): | |
# Map data structure that stores players as the key | |
# and current WeaponTier as the value | |
var PlayerMap : [player]int = map{} | |
# Item granters stored in an array so we can give the player | |
# new weapons | |
@editable | |
var WeaponGranters : []item_granter_device = array{} | |
# Array of bots for beating up and testing | |
@editable | |
var Sentries : []sentry_device = array{} | |
# This is how we end the game later | |
@editable | |
EndGameDevice : end_game_device = end_game_device{} | |
# Needed to let the game know when to end | |
var ElimsToEndGame : int = 0 | |
# Runs when the device is started in a running game | |
OnBegin<override>()<suspends>:void= | |
set ElimsToEndGame = WeaponGranters.Length; | |
InitPlayers() | |
InitTestMode() | |
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) | |
GrantWeapon(Player : player, WeaponTier: int) : void= | |
Print("Attempting to grant weapon") | |
if (ItemGranter := WeaponGranters[WeaponTier]): | |
Print("Granted item to player") | |
ItemGranter.GrantItem(Player) | |
OnPlayerEliminated(Result : elimination_result) : void= | |
Eliminator := Result.EliminatingCharacter | |
if (FortCharacter := Eliminator?, EliminatingAgent := FortCharacter.GetAgent[]): | |
Print("We need to promote player") | |
PromotePlayer(Agent : agent) : void= | |
var WeaponTier : int = 0 | |
if (Player := player[Agent], PlayerWeaponTier := PlayerMap[Player]): | |
set WeaponTier = PlayerWeaponTier + 1 | |
CheckEndGame(Agent, WeaponTier) | |
if (Player := player[Agent], set PlayerMap[Player] = WeaponTier): | |
GrantWeapon(Player, WeaponTier) | |
InitTestMode() : void= | |
for (Sentry : Sentries): | |
Sentry.EliminatedEvent.Subscribe(TestPlayerElimination) | |
TestPlayerElimination(Agent : ?agent) : void= | |
Print("Sentry eliminated!") | |
if (Player := Agent?): | |
PromotePlayer(Player) | |
CheckEndGame(Player : agent, WeaponTier : int) : void= | |
if (WeaponTier >= ElimsToEndGame): | |
EndGameDevice.Activate(Player) |
How to take it off test mode? everytime I upload, it only implys for the sentry only, but if I eliminate a player, there’s no weapon change for some reason… only when I eliminate the sentry bot.
Actually you don`t need to take test mode off, i only added one line on the "OnPlayerEliminated" function :
PromotePlayer(EliminatingAgent)
Does this Script handle Respawns?
I almost copyed it 1 to 1 and everytime i die i get no weapon.
Does this Script handle Respawns?
I almost copyed it 1 to 1 and everytime i die i get no weapon.
when i used it, i died and killed the same person and we both got our weapons upgraded
you need to put the : PromotePlayer(EliminatingAgent) inside the if identation
This would give the Player who mad the Elim the next Weapon, but the Player who reaspawns dosen't get anything.
Because we don't listen for Respawns/Spawns.
Two settings I changed so the game functions as it should.....
- Item Granters: Drop Items at Players Location: Never
2.Island Settings: Eliminated Players Items: Keep (This is the important one)
Edit
I also turn off Allow Item Drop and Auto Pick Up just so players cant drop items. Both in island settings
How do we listen for respawn event?
Lets say I want to give ammo or other consumables on respawn from an Item granter.
I'm fairly confident I can handle writing a function if I knew what to listen for.
Edit: Worked it out.
Spawner.SpawnedEvent.Subscribe()
@BaSSa8 are you able to share how to make players joining in progress.
It won't work when I'm fighting players, it only works when I fight a sentry bot. How can I fix it?
@DanielHalfeld
Can you put what exactly you wrote, I am unsure on where/ how to put it.
@DanielHalfeld
How exactly/ where exactly did you write this, could you post a ss?
I start with no weapons. Not sure why. Can someone tell me?
So I've copied this exactly into verse I've put drop items at players location to never as well as keep items on respawn but my issue is when you get a elim the gun dosnt change, but if you have a bot the guns do change is there a fix to this ?
Hi i just started using verse, i am confused on where to put it
The current code only applies to the sentry bot, not the player. When I eliminate a player, the weapon doesn't switch, but it does switch after eliminating a sentry bot. Additionally, new players who join mid-game don't receive a weapon. Could you please fix the code so that eliminating a player triggers a weapon switch and ensure that players joining mid-game also receive a weapon?
How to take it off test mode? everytime I upload, it only implys for the sentry only, but if I eliminate a player, there’s no weapon change for some reason… only when I eliminate the sentry bot.
Actually you don`t need to take test mode off, i only added one line on the "OnPlayerEliminated" function : PromotePlayer(EliminatingAgent)
have you figure out the code if so can please share it
Hey, so I copied the code exactly and my game didn't end...
The current code only applies to the sentry bot, not the player. When I eliminate a player, the weapon doesn't switch, but it does switch after eliminating a sentry bot. Additionally, new players who join mid-game don't receive a weapon. Could you please fix the code so that eliminating a player triggers a weapon switch and ensure that players joining mid-game also receive a weapon?
I changed the code and everything works as it should
How to take it off test mode? everytime I upload, it only implys for the sentry only, but if I eliminate a player, there’s no weapon change for some reason… only when I eliminate the sentry bot.