Page 1 of 1

Limiting Weapon use in zone

Posted: Wed Jan 27, 2016 4:35 am
by abregado
Im working on some scripts for a modified version of Factorio to use in schools and holiday programs. The next step is to be able to define zones in the control.lua for a scenario in which the players are not allowed to fire weapons, activate capsules/grenades, or drive vehicles.

Stopping players from driving inside an area is trivial using the teleport function but the weapon removal/disable is a bit trickier.

My first ideas were:
When players enter these zones strip them of the items and then return them upon leaving the area
or
Remove the equipped slots from players inside the areas
or
replace weapons with "dummy versions when entering zones, and replace them again when leaving zones

Is there a way to intercept the fire keypress or capsule deployment?
How can I store confiscated items that persists across loads/server restarts?
Can anyone think of a better way to do this?

Re: Limiting Weapon use in zone

Posted: Wed Jan 27, 2016 4:54 pm
by jorgenRe
If you can't disable the use you can confiscate items and store them in a global table example
D = 2

Does not persist, but
Global.D = 2
Will ;)!

Defining the zones could probably be done by checking for an item with no texture or collision.

Re: Limiting Weapon use in zone

Posted: Thu Jan 28, 2016 2:03 am
by abregado
Ive got the zones working well so far.

So anything added to the Global object will be stored on save and retrieved on load?

Re: Limiting Weapon use in zone

Posted: Thu Jan 28, 2016 10:01 am
by jorgenRe
abregado wrote:Ive got the zones working well so far.

So anything added to the Global object will be stored on save and retrieved on load?
Yes :)!
Trye this:

Code: Select all

if (global.dd == null) then
global.dd = 1
end

Then in the on load function
global.dd += 10

THen in the on_tick 
game.players[0].print(global.dd)
Now this should print an increasing number that increases by 1 for every load since it will only set global.dd to 1 if it does not exist, but since its a global variable it should stay!
PS if you arent already aware of it if you only change the script you will only need to reload the save, not the whole game :)!