yaim904 wrote: Tue Jul 26, 2022 3:28 pm
Thanks for your help.
What you say is not confirmed in the code.
When I try to get the player character in the
on_player_changed_force event the value of
Player.character does not exist and
get_associated_characters() gives me the previous character.
Items are added successfully, but to the old inventory not the new one.
Sorry, your links are garbled (there's real text instead of a URL), so perhaps I don't understand you correctly.
The following will give a rocket-silo to any player who joins another force:
Code: Select all
script.on_event(defines.on_player_changed_force, function(event)
local player = game.players[event.player_index]
if player and player.valid then
player.insert("rocket-silo")
end
end)
If you have a player on force "player", and player.character is not nil, the command
will trigger the event and
your character should have a rocket-silo in its inventory.
Now, use
Code: Select all
/c
c = game.player.character
game.player.character = nil
to enter god mode. If your character's inventory was open, it will be closed now. Open it again to see that you have an empty inventory. Then run
to trigger the event again. You still have no character, but you'll find that a rocket-silo has been added to your
player inventory.
Now try
Code: Select all
/c
game.player.character = c
game.player.force = "enemy"
to get back your old character and trigger the event again. This time, there should be 2 rocket-silos in your inventory.
In god mod, you don't have a character but you still get an empty inventory. When you switch from god mode to character mode (i.e., when player.character is not nil), the contents of your god-mode inventory will be lost. It's similar with editor mode, but there's an important difference: When you enter /editor, your old character (if you had one) will be stored and you will get an empty inventory. When you leave editor mode again, everything that was in your editor-mode inventory will be lost, but your old character (if you had one) will be restored to you.
I hope that makes sense.
