Page 1 of 1
forbit carrying of some items.
Posted: Tue Feb 25, 2014 11:06 am
by AlexPhoenix
in making my mod i realized that i want to forbid some items be carryed by player.
How can i do this?
Re: forbit carrying of some items.
Posted: Tue Feb 25, 2014 2:23 pm
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).
Re: forbit carrying of some items.
Posted: Tue Feb 25, 2014 2:35 pm
by AlexPhoenix
hm, thanks.
this even better idea, will be like you cannot carry overweighed items.
Re: forbit carrying of some items.
Posted: Tue Feb 25, 2014 2:49 pm
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.