Jump to content

code/script (examples to learn), 1: [solved]


DZomboid

Recommended Posts

I thank the attention of the gentlemen. Please ONLY/JUST code/script. I need a code/script to two conditions:

Condition 1: Start a new game with 1 pistol, 9mm rounds, 1 axe, 1 hammer and strength 50 (this condition is for unemployed and any chosen profession to start new game).

Condition 2: If the player kill ten zombies, he finds in the zombie number ten: 1 pistol and 9mm rounds.

Sorry for my noob english.

Edited by DZomboid
Link to comment
Share on other sites

Oh tommysticksthanks for your attention. Ye! I need code/scripts for this 2 conditions. I am new to programming language. I am learning code/script. I am brazilian. I speak portuguese language. The forum does not have guides in portuguese language. Examples codes help much. If you can help, just paste the codes here. Ah! your mod is wonderful! Long live to tommysticks.  Long live to Project Zomboid!

 

Link to comment
Share on other sites

3 hours ago, DZomboid said:

Oh tommysticksthanks for your attention. Ye! I need code/scripts for this 2 conditions. I am new to programming language. I am learning code/script. I am brazilian. I speak portuguese language. The forum does not have guides in portuguese language. Examples codes help much. If you can help, just paste the codes here. Ah! your mod is wonderful! Long live to tommysticks.  Long live to Project Zomboid!

 

I won't be able to get to it til Tuesday, but just to make sure:

Every profession starts with a hammer, ax, pistol, ammo, and high strength

And every 10th zed drops pistol and ammo

 

Anything else?

Link to comment
Share on other sites

19 hours ago, tommysticks said:

I won't be able to get to it til Tuesday, but just to make sure:

Every profession starts with a hammer, ax, pistol, ammo, and high strength

And every 10th zed drops pistol and ammo

 

Anything else?

Oh tommysticksthanks for your attention. Ye! This! XD. Unemployed and every profession. (Strength 50). You are my teacher. XD. Don´t worry about the day to get ready. I wait. XD. Thanks  tommysticks!

Link to comment
Share on other sites

Here it is dawg:

local function startUp()
	local player = getPlayer();
	player:getDescriptor():setForename("Tommy"); --sets character firstname to Tommy
	player:getDescriptor():setSurname("Sticks"); --sets character lastname to Sticks
	
	local pistol = player:getInventory():AddItem("Base.Pistol"); --stores new pistol in variable
	pistol:setName("Tommy's Pistol"); --sets new pistol's name to Tommy's Pistol
	-- player:getInventory():AddItem("Base.Pistol"); --adds a pistol without storing it in a variable
	player:getInventory():AddItems("Base.Bullets9mm", 9); --adds 45 9mm rounds
	player:getInventory():AddItem("Base.Hammer"); --adds the hammer
	player:getInventory():AddItem("Base.Axe"); --adds the axe
	player:getXp():AddXP(Perks.Strength, 30000000); --sets the perk strength to the max
	player:getModData().zKills = 0; --initializes zKills in the player mod data
	-- print(player:getModData().zKills);	
	
	--adding a bag that contains items
	-- local bag = player:getInventory():AddItem("tommyguns_items.Rucksack");
	-- bag:getItemContainer():AddItems("tommyguns_items.Box556", 3);
	-- bag:getItemContainer():AddItem("tommyguns_items.BoxMRE", 1);
	-- bag:getItemContainer():AddItem("tommyguns_items.machete", 1);
	-- bag:getItemContainer():AddItems("Base.WaterBottleFull", 2);
	-- bag:getItemContainer():AddItem("tommyguns_items.BoxMRE", 1);
	-- bag:getItemContainer():AddItems("Base.BulletsBox", 2);
	
	--adding a gun that has attachments
	-- local startGun = player:getInventory():AddItem("tommyguns_items.weapon_ar15");
	-- local part1 = InventoryItemFactory.CreateItem("Base.RedDot");
	-- local part2 = InventoryItemFactory.CreateItem("Base.Sling");
	-- local part3 = InventoryItemFactory.CreateItem("Base.RecoilPad"); 
	-- local part4 = InventoryItemFactory.CreateItem("Base.FiberglassStock");
	-- startGun:attachWeaponPart(part2);
	-- startGun:attachWeaponPart(part3);
	-- startGun:attachWeaponPart(part4);
	-- startGun:attachWeaponPart(part1);
end

local function killPlus()
	getPlayer():getModData().zKills = getPlayer():getModData().zKills + 1; --have to access player moddata and increase zed kills by 1
	-- print(getPlayer():getModData().zKills); --prints zed kills for debugging
end

local function zedCheck(room, containerType, container) --i don't know how parameters work
	if (container:getType() == "inventorymale" or container:getType() == "inventoryfemale") and getPlayer():getModData().zKills >= 10 then --checks to for container zed and if player has 10 or more kills
		-- getPlayer():Say("Gun and Ammo Spawned"); --for debugging
		getPlayer():getModData().zKills = getPlayer():getModData().zKills - 10; --remove 10 kills from the player moddata zKills
		container:AddItem("Base.Pistol"); --adds pistol to 10th zed killed
		container:AddItems("Base.Bullets9mm", 6); --adds 30 9mm rounds to 10th zed killed
		-- print("zed kills"); --debugging
		-- print(getPlayer():getModData().zKills); --debugging
	end
end

Events.OnFillContainer.Add(zedCheck);
Events.OnZombieDead.Add(killPlus);
Events.OnNewGame.Add(startUp);

Everything works out as requested:

Every new character starts with strength maxed

Every new character starts with a pistol, ammo, axe, and hammer

Every 10th Zed drops a new pistol and ammo

 

I left in some other code snippets for you to check out.

Edited by tommysticks
added notes to code
Link to comment
Share on other sites

On 10/09/2016 at 10:52 PM, tommysticks said:

Client. 

 

But for modding purposes you should make a new mod and put the code into this directory:

 

C:\Users\YOUR USERNAME\Zomboid\mods\DZomboid's Mod\media\lua\client

 

There should be an example mod in the mods folder that shows how it needs to be put together.

Thanks! tommysticks the great! (Solved)

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...