forbit carrying of some items.

Place to get help with not working mods / modding interface.
Post Reply
User avatar
AlexPhoenix
Fast Inserter
Fast Inserter
Posts: 149
Joined: Tue Feb 18, 2014 7:48 am
Contact:

forbit carrying of some items.

Post by AlexPhoenix »

in making my mod i realized that i want to forbid some items be carryed by player.

How can i do this?

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: forbit carrying of some items.

Post by FreeER »

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).

User avatar
AlexPhoenix
Fast Inserter
Fast Inserter
Posts: 149
Joined: Tue Feb 18, 2014 7:48 am
Contact:

Re: forbit carrying of some items.

Post by AlexPhoenix »

hm, thanks.
this even better idea, will be like you cannot carry overweighed items.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: forbit carrying of some items.

Post by FreeER »

AlexPhoenix wrote:this even better idea, will be like you cannot carry overweighed 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.

Post Reply

Return to “Modding help”