Page 1 of 3

[MOD WIP 0.6.x] Cobra Commander mod

Posted: Fri Mar 08, 2013 1:09 pm
by rk84
____________________Image____________________
Cobra has landed! And Cobra will take over control of this planet from alien foolsssss! We will harness the planet's resources in better use. HAIL COBRA!

Features: (with notes)
  • Crimson Guards: +more health, +faster mining, -bigger hitbox, -just little slower than creepers (only idle and running textured)
  • Cobra Troopers
  • Cobra Currency (Currently gold ore -> Cobra Coin. mayby change to gold ore -> gold ingot/nugget -> Cobra coin)
  • Cobra Sounds
  • Corba Flashlight
  • Yellow alert icons
New items:
  • War banner: For controlling Cobra troopers
  • Cobra guard house: Spawner for Cobra Troopers
  • Cobra coins
  • Cobra H.I.S.S Tank
  • Alarm tower: Shoots flares and sounds alarm.
  • Flare rocket: Ammunition for alarm tower
  • Cluster mine: Place stack of mines with one cluster mine.
  • Gold Ore
Images:
Cobra H.I.S.S. Tank (+ player with Crimson guards )
ImageImage

Alert Tower in action (+ Cobra flashlight :D )
Image

Cobra Troopers (Cobra Commander inspecting his troops)
Image


Sources:
Sounds&Music:

Textures&Icons:


Note: (for 0.2.10)
This mod will overwrite some default files of the game. Like demo-entities.json, freegame.lua, alot of sound and textures -files. Locale files are include in language option "CCmod-en".


Downloads:

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Sat Mar 09, 2013 1:12 am
by zlosynus
Wow, looks absolutely epic :). Finally you can play sort of Starcraft inside Factorio.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Sat Mar 09, 2013 11:32 am
by drs9999
Yes very nice mod!
Just a suggestion:
Maybe you can implement the feature that the guards will follow you instead/ as addition to placing the banners.
Because it would be a mess when they follow you all the time, so you could change your script that it looks for an unique item in the players inventory only if it is in your invetory they will follow you.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Mon Mar 11, 2013 9:58 am
by rk84
Thank you for your comments. Yes I will try to make auto banner option. I think, if I can get 'item' from onitemput event. I could use it so that if you click banner too far or over another entity it will enable auto option, but when banner is placed it will go off.
[edit]I'm also wondering if I should make banners unlimited (destroyed banner inserted back to player) or make auto option consume them from player.[/edit]

Another things I'm planning:
-add in visible aggro range for banner (when you are holding it). I just need to check out correct range.

-lowering guard house price (100 coins), but every dead trooper will cost 10 gold coins. Taken from inventory. No money will make dept and more dept will decrease guard house spawning stats or remove guard house (depends on if I have methods to change guard house stats). I think it is needed, because unlimited troopers feels bit over powered. What you think?

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Mon Mar 11, 2013 10:31 am
by drs9999
rk84 wrote:Another things I'm planning:
-add in visible aggro range for banner (when you are holding it). I just need to check out correct range.
So like electric poles? Only troops that are in the blue rectangle are affected?
rk84 wrote: -lowering guard house price (100 coins), but every dead trooper will cost 10 gold coins. Taken from inventory. No money will make dept and more dept will decrease guard house spawning stats or remove guard house (depends on if I have methods to change guard house stats). I think it is needed, because unlimited troopers feels bit over powered. What you think?
At the moment it isnt possible to substract an amount of items from an inventory, but kovarex allready said that an "extract"-method will be implemented sooner or later. Also i think it isnt possible to change entity stats at the moment, but lets say it is then adding a "can_spawn"- bool to the entity makes sense in my eyes. Also isnt it more logical that the creation of a tropper cost 10 coins and not the death?
If can_spawn==true then spawn a trooper; can_spawn==false then stop spawning. and the bool depends on your amount of coins. if coins<=0 then can-spawn=false

Btw. its so messy with all that mods that change the freeplay.lua right now. At the moment I have a folder for factorio-bvanilla, one for your mod, one for the f-mod, one for my mods and one for files im currently working on :D

EDIT: for a second i thought using entity.type="electric-pole" for the banner would be smart. just turn the maximum-wire-distance to a very small value, so they wont connect. But it seems like that the size of the blue rectangle is hard coded (not sure about this)

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Mon Mar 11, 2013 11:33 am
by rk84
drs9999 wrote:So like electric poles? Only troops that are in the blue rectangle are affected?
No. I will change war-banner's picture. If you read the CCmod-entities.json, you can see I use 2 war-banners. One for player to build and place and another for script to switch in. Also war-banner2 is actually turret. I haven't been able to get troopers to take interest in other entities (except turrets, units and spawner). :)
drs9999 wrote: At the moment it isnt possible to substract an amount of items from an inventory, but kovarex allready said that an "extract"-method will be implemented sooner or later. Also i think it isnt possible to change entity stats at the moment, but lets say it is then adding a "can_spawn"- bool to the entity makes sense in my eyes. Also isnt it more logical that the creation of a tropper cost 10 coins and not the death?
If can_spawn==true then spawn a trooper; can_spawn==false then stop spawning. and the bool depends on your amount of coins. if coins<=0 then can-spawn=false
Logical, yes. But I try to work with the tools currently available. There is no onunitspawned event, so thats why I'm thinking of using onunitdead and dept. Think of it like paying furneral cost. :)
oh I just remember. Instead removing mayby I can use setactive()
drs9999 wrote: Btw. its so messy with all that mods that change the freeplay.lua right now. At the moment I have a folder for factorio-bvanilla, one for your mod, one for the f-mod, one for my mods and one for files im currently working on :D
I'm glad you have room for this mod. :D

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Mon Mar 11, 2013 12:01 pm
by drs9999
Oh sorry i thought the onbuiltentity event would work for everything that is spawning. But it is only triggered when the player build something.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 12:30 pm
by rk84
Oh well some things have to wait for until I can extract stuff from inventory, but I have updated the download with following:
-Visual aggro range of the war banner. (30 tiles radius)
-Automatic war banners. Activate by building on top of yourself (any buildable item will do). De-activate by placing a war-banner. Script will place war banner 5 tiles behind player when distance to last one is over 25 tiles.
-CCmod.lua in lualib.
-Console (utility) commands: creativemod() and events()

I think it should work with old saves.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 1:02 pm
by drs9999
I will test it later, but for now:
I finnly managed to "extract" stuff from an inventory with this (just copied from my mod-source):

Code: Select all

            if glob.field[i].getitemcount("fertilizer") > 0 then  -- with fertilizer: tree spawn every update-cycle (only if enough space)
              grow = 10
              local fertilizer =  glob.field[i].getitemcount("fertilizer")-- store amount of items actually in the inventory
              local wood = glob.field[i].getitemcount("raw-wood")      
              local inv = glob.field[i].getinventory(1)                   -- delete all stuff from the inv
              inv.clear()

              fertilizer = fertilizer - 1                                 --decrease fertilizer = simulate  that it is used          
              if fertilizer > 0 then
                glob.field[i].insert{name="fertilizer", count = fertilizer}  -- and reload inventory
              end
              if wood ~= (nil or 0) then
                glob.field[i].insert{name="raw-wood", count = wood}
              end
            end
but as you can see this will delete every item that isnt fertilizer or wood. Maybe you will find a way to solve that, for my mod that wasnt necessary...

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 1:53 pm
by rk84
drs9999 wrote:I will test it later, but for now:
I finnly managed to "extract" stuff from an inventory with this (just copied from my mod-source):

Code: Select all

            if glob.field[i].getitemcount("fertilizer") > 0 then  -- with fertilizer: tree spawn every update-cycle (only if enough space)
              grow = 10
              local fertilizer =  glob.field[i].getitemcount("fertilizer")-- store amount of items actually in the inventory
              local wood = glob.field[i].getitemcount("raw-wood")      
              local inv = glob.field[i].getinventory(1)                   -- delete all stuff from the inv
              inv.clear()

              fertilizer = fertilizer - 1                                 --decrease fertilizer = simulate  that it is used          
              if fertilizer > 0 then
                glob.field[i].insert{name="fertilizer", count = fertilizer}  -- and reload inventory
              end
              if wood ~= (nil or 0) then
                glob.field[i].insert{name="raw-wood", count = wood}
              end
            end
but as you can see this will delete every item that isnt fertilizer or wood. Maybe you will find a way to solve that, for my mod that wasnt necessary...
well first I felt too lazy to make table of all items in game, but after cleaning freegame.lua I'm having second thoughs. If I do it, I'm sure 0.2.11 will release :lol:

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 3:58 pm
by rk84
Here is the removeitem -function. Yea, it has ugly big list and you have to keep track of items you add to game (or you can say bye bye to your items :lol: )

Code: Select all

function getstacks(inv)
	itemlist = {"basic-bullet-magazine", "flame-thrower-ammo", "flare-rocket", "piercing-bullet-magazine", "rocket", "basic-armor", "heavy-armor", "flame-thrower", "land-mine", "pistol", "rocket-launcher", "submachine-gun", "iron-axe", "steel-axe", "basic-turret", "gun-turret", "laser-turret", "rocket-turret", "advanced-circuit", "alarm-tower", "assembling-machine-1", "assembling-machine-2", "alien-artifact", "alien-science-pack", "basic-inserter", "basic-mining-drill", "basic-transport-belt", "basic-transport-belt-to-ground", "basic-splitter", "boiler", "burner-inserter", "burner-mining-drill", "car", "coal", "cobra-coin", "cobra-guardhouse", "cobra-hiss-tank", "computer", "copper-cable", "copper-ore", "copper-plate", "creeper-spawner", "curved-rail", "diesel-locomotive", "electronic-circuit", "express-transport-belt", "express-transport-belt-to-ground", "fast-inserter", "fast-transport-belt", "fast-transport-belt-to-ground", "filter-inserter", "fish", "gold-ore", "green-wire", "iron-chest", "iron-gear-wheel", "iron-ore", "iron-plate", "iron-stick", "lab", "logistic-chest-provider", "logistic-chest-requester", "logistic-chest-storage", "logistic-robot", "long-handed-inserter", "pipe", "pipe-to-ground", "player-port", "pump", "radar", "raw-wood", "red-wire", "rocket-defense", "science-pack-1", "science-pack-2", "science-pack-3", "small-electric-pole", "small-lamp", "smart-chest", "smart-inserter", "smart-loader", "solar-panel", "steam-engine", "steel-chest", "steel-plate", "stone", "stone-furnace", "straight-rail", "wall", "war-banner", "wood", "wooden-chest"}

	stacks = {}
	for i=1, # itemlist do
		count =	inv.getitemcount(itemlist[i])
		if count > 0 then
			stacks[itemlist[i]] = count
		end
	end
	return stacks
end

function removeitem(inv,item,amount)
	if inv.getitemcount(item) > amount then
		invstacks = getstacks(inv)
		invstacks[item] = invstacks[item] - amount
		inv.clear()
		for k, v in pairs(invstacks) do
			if inv.caninsert({name = k, count = v}) then inv.insert({name = k, count = v}) end
		end
		return true
	else
		return false
	end
end
I will add this to next update. Also in next update I will totally clean freegame.lua of my stuff (except function calls) and move everything to CCmod.lua
And all mod related global variables and functions will have ccmod or ccglob -prefix in their names.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 4:54 pm
by drs9999
Oh yeah this is ugly :D
The list not the code ;)
Maybe it is possible to scan all files included in the prototypes-definitions/item folder in some way? This would also include mod-items to the list automatically.

rk84 wrote:Also in next update I will totally clean freegame.lua of my stuff (except function calls) and move everything to CCmod.lua
And all mod related global variables and functions will have ccmod or ccglob -prefix in their names.
Maybe i should do the same in my next update,too. Anyway, this is maybe a way to install multiple mods easier, but it dont solve the basic problem in my opinion.

And last but no least I played a bit with your mod, sadly I just spent time with the event() and creative() commands. They are so damn useful!!!

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 7:43 pm
by drs9999
Oh boy.. I got it! :D

Code: Select all

 
recipelist = glob.player.force.getrecipes()
 recipename ={}
for k, recipe in pairs(recipelist) do
recipename[k]=recipe.name
glob.player.print(recipename[k])
end
this little baby saves all itemnames in recipename{}. so this will only work for items that have a recipe BUT it work for mod-items as well :D

EDIT: Damn, just remembered that alien-artifacts dont have a recipe, so they wont be added.. But meh.. just add them manually after the for loop :D

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Tue Mar 12, 2013 9:36 pm
by rk84
Very good idea. That will cut majority of items from list. I will look into it tomorrow

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Wed Mar 13, 2013 5:03 am
by kovarex
I feel bad for forcing you to use these tricks just because the remove method is missing in your current version.
The remove function has been implemented long ago in our dev version, but it will take some time until we release 0.3.0.

You might want to say what other functions are you missing and would like to have in the new versions, so I made separated thread just for that.
https://forums.factorio.com/forum/vie ... 3281#p3281

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Wed Mar 13, 2013 6:39 am
by rk84
kovarex wrote:I feel bad for forcing you to use these tricks just because the remove method is missing in your current version.
The remove function has been implemented long ago in our dev version, but it will take some time until we release 0.3.0.

You might want to say what other functions are you missing and would like to have in the new versions, so I made separated thread just for that.
https://forums.factorio.com/forum/vie ... 3281#p3281
Don't feel bad. It is part of the fun :)

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Wed Mar 13, 2013 5:36 pm
by rk84
drs9999 wrote:Oh boy.. I got it! :D

Code: Select all

 
recipelist = glob.player.force.getrecipes()
 recipename ={}
for k, recipe in pairs(recipelist) do
recipename[k]=recipe.name
glob.player.print(recipename[k])
end
this little baby saves all itemnames in recipename{}. so this will only work for items that have a recipe BUT it work for mod-items as well :D

EDIT: Damn, just remembered that alien-artifacts dont have a recipe, so they wont be added.. But meh.. just add them manually after the for loop :D
some reason I get empty table when I use glob.player.force.getrecipes(). I researched one technology and # glob.player.force.gettechnologies() was 0 also :?

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Wed Mar 13, 2013 6:36 pm
by rk84
Update: freegame.lua -> CCmod.lua is done. I don't have to copy-paste freegame.lua in my saves anymore :D
Cobra Troopers:
  • You need 100 cobra coins for guard house, but every casualty will now cost 10 cobra coins and every 100 in dept will de-activate one guard house.
Onscansector:
  • Radars can find (spawn) wrecks that contain random stuff inside. Search area is quite big (range 50-150), but radar prints coords (hmm I could change it to give direction and range)
    Currently there is 10% change of space-module-wreck and 10% for radar shut down. I could add other random events here.
Console commands: (for testing. I hope these do more good then harm)
  • ccmod.creative(): Restores used items.
    ccmod.giveme(word, amount): Works like insert, except when you type "set" in word parameter then you get predefined list of stuff.
    ccmod.events(): Prints all events except "ontick"
    ccmod.tprint(table): Prints first layer of table (output: glob.player.print) example. ccmod.tprint(ccglob) -> prints all mod releated global values
    ccmod.deeptprint(table): Complete print of table and tables inside of it (output: game.showmessagedialog)
Also there is boxcar entity, but it has no container... yet? :)

edit: small typo. uploaded again. I hope I fixed it in time.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Wed Mar 13, 2013 7:14 pm
by drs9999
rk84 wrote:
drs9999 wrote:Oh boy.. I got it! :D

Code: Select all

 
recipelist = glob.player.force.getrecipes()
 recipename ={}
for k, recipe in pairs(recipelist) do
recipename[k]=recipe.name
glob.player.print(recipename[k])
end
this little baby saves all itemnames in recipename{}. so this will only work for items that have a recipe BUT it work for mod-items as well :D

EDIT: Damn, just remembered that alien-artifacts dont have a recipe, so they wont be added.. But meh.. just add them manually after the for loop :D
some reason I get empty table when I use glob.player.force.getrecipes(). I researched one technology and # glob.player.force.gettechnologies() was 0 also :?
Ah maybe you didnt defined "glob.player"? Replace it with "game.getplayer()". I tested it, a second ago.

Re: [MOD WIP 0.2.10] Cobra Commander mod

Posted: Thu Mar 14, 2013 10:48 am
by rk84
drs9999 wrote: Ah maybe you didnt defined "glob.player"? Replace it with "game.getplayer()". I tested it, a second ago.
ah It works fine. I just learned that # operator and table.getn() doesn't work on dictionary tables.

Edit: Another post for remove function if needed.

Code: Select all


itemlist = {"alien-artifact", "coal", "computer", "copper-ore", "creeper-spawner", "fish", "iron-ore", "player-port", "raw-wood", "stone", "wall"}

i = 1 + #itemlist
for k, recipe in pairs(game.getplayer().force.getrecipes()) do
  itemlist[i] = recipe.name
  i = i + 1
end

function getstacks(inv)
  stacks = {}
  for i=1, # itemlist do
    count =   inv.getitemcount(itemlist[i])
    if count > 0 then
      stacks[itemlist[i]] = count
    end
  end
  return stacks
end

function removeitem(inv,item,amount)
  if inv.getitemcount(item) > amount then
    invstacks = getstacks(inv)
    invstacks[item] = invstacks[item] - amount
    inv.clear()
    for k, v in pairs(invstacks) do
      if inv.caninsert({name = k, count = v}) then inv.insert({name = k, count = v}) end
    end
    return true -- Remove success
  else
    return false --Remove failed
  end
end