in making my mod i realized that i want to forbid some items be carryed by player.
How can i do this?
forbit carrying of some items.
- AlexPhoenix
- Fast Inserter
- Posts: 149
- Joined: Tue Feb 18, 2014 7:48 am
- Contact:
Re: forbit carrying of some items.
Check the player's inventories periodically for those items and if they are carrying them then either remove the items or damage the player.
I know the F-mod does this and so does/did the Nuclear Mod by Immibis, and I believe that DyTech also does, so if you want to see some code for it those are a few places to look though the obvious pseudo code is: ontick then event.tick%60==1(if game.player.character then if game.player.getitemcount("iron-plate") then game.player.character.damage(5) end if game.player.getitemcount("copper-plate") then game.player.character.damage(5) end end).
I know the F-mod does this and so does/did the Nuclear Mod by Immibis, and I believe that DyTech also does, so if you want to see some code for it those are a few places to look though the obvious pseudo code is: ontick then event.tick%60==1(if game.player.character then if game.player.getitemcount("iron-plate") then game.player.character.damage(5) end if game.player.getitemcount("copper-plate") then game.player.character.damage(5) end end).
- AlexPhoenix
- Fast Inserter
- Posts: 149
- Joined: Tue Feb 18, 2014 7:48 am
- Contact:
Re: forbit carrying of some items.
hm, thanks.
this even better idea, will be like you cannot carry overweighed items.
this even better idea, will be like you cannot carry overweighed items.
Re: forbit carrying of some items.
this can be done, the easiest way is to simply set game.player.character.active=false, but you could also create a new character (with a slower walking/running speed) and when the player is carrying a 'heavy' item use game.createentity{name="your_slow_player", position=game.player.position} and move all items from old character inventories to new then connect to the new character and kill the old. If you actually wanted each item to have a weight, you'd have to assign the weights yourself (in a table) and loop through the player's inventories to count the total weight.AlexPhoenix wrote:this even better idea, will be like you cannot carry overweighed items.