Forum

> > CS2D > Scripts > [LUA] Adding score to survivors/CTs
Forums overviewCS2D overview Scripts overviewLog in to reply

English [LUA] Adding score to survivors/CTs

5 replies
To the start Previous 1 Next To the start

old [LUA] Adding score to survivors/CTs

SkullFace
User Off Offline

Quote
I wanted to make it so that every minute a survivor gets score for surviving.

I've realized I'll need
--player(0,"team2")
table, yet I don't know how to "access" it and my head hurts already.

1
2
3
4
5
6
7
8
9
10
addhook("minute","increaseZombieDifficulty")
function increaseZombieDifficulty(id,score)
--player(0,"team2")
--scoreIncrease = score+2
	for id=1,32 do
	if player(id,"team")==2 then --CT
		parse("setscore "..id.." "..score)
	end
	end
end

If it's complicated, I'll reward survivors with cash instead.

old Re: [LUA] Adding score to survivors/CTs

Bowlinghead
User Off Offline

Quote
Each Minute
For each alive CT
Give each aliveCT 1 point
1
2
3
4
5
6
7
8
9
addhook("minute","min")
function min()
	for k,v in pairs(player(0,"team2living"))
		local playerCurrentScore = player(v,"score")
		parse("setscore "..v.." "..playerCurrentScore+1)
		msg2(v,"You got 1 point ^^")
	end
	msg("System feeded "..#player(0,"team2living").. " amount of alive humans")
end

Every player(0,"xxx") gives you a list of ids (something like {2,6,29,16,25} <- player-ids). For every ID in that list (for k,v ... line aka foreach value in my list/array) you do something while k is the index (so it runs: 1,2,3,4,...) and v is the individual id (so it runs: 2,6,29,16,25).
So k is most likely to be irrelevant.

The amount of team2living's are:
local amountCTs = #player(0,"team2living")


Correction to your code:
You almost did it almost right:
You are using for id=1,32 do. So the code get executed 32 times and each time the id changes from 1 to 32. Then you check wether or not the id is a CT, but not that he is alive (additional if (player(id,"health") > 0) then ).
Then what you tried was probably something like this:
parse("setscore "..id.." "..player(id,"score")+1) -- change current playerscore by 1 <-- this is what I did in my code too, but I used an additional variable (playerCurrentScore) to make things more clear
edited 4×, last 01.07.23 02:51:43 am

old Re: [LUA] Adding score to survivors/CTs

SkullFace
User Off Offline

Quote
It works great!
Thanks for the help, learned a couple of new things.

Spoiler >


Still gonna give a try for the buy menu table to modify it after some time, using table array ofc.

(Don't close the thread yet, don't wanna clutter with another thread involving table which is gonna be soon)

old Re: [LUA] Adding score to survivors/CTs

Cure Pikachu
User Off Offline

Quote
Your implementation could have side effects though, such as the first difficulty increase actually adding 0 points because the variable wasn't initalised yet as far as your snippet goes.
Code (Optimised) >

Code (Difficulty scales with # of survivors at the time) >
edited 1×, last 04.07.23 11:13:28 am

old Re: [LUA] Adding score to survivors/CTs

SkullFace
User Off Offline

Quote
I've noticed that the hard way. It's a nice idea to add difficulty scale with number of players, will implement later, now I'm messing with tables and random loot.

I feel like I learned a lot, but there's always 10x more to learn.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview