Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 238 39 40338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
@KaiserWilhelm: Oh for gods sake you're a python developer, has python taught you of nothing about tabbing blocks? T.T

old Re: Lua Scripts/Questions/Help

KaiserWilhelm
User Off Offline

Quote
leegao has written
@KaiserWilhelm: Oh for gods sake you're a python developer, has python taught you of nothing about tabbing blocks? T.T
I'm 15, cut me some slack. All the other kids i know my age can't understand how to shut a pc down correctly, none the less mess around in idle.

and I believe at the end i stated the reason for that leegao. Oh for gods sake you speak english, has language taught you nothing about finishing a paragraph?


P.S. I looked at the code before trying to sort out where your infection scripts were Blazzingxx, but like you previously stated, no code stealers are reading THAT I'll try it out, thanks.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
KaiserWilhelm has written
I'm 15, cut me some slack. All the other kids i know my age can't understand how to shut a pc down correctly, none the less mess around in idle.


Then you should go out more often and meet more people

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Oh I'm sorry, obviously age is a factor here, especially given the fact that the general age range for the visitors of this forum falls between 13 and 18. If you are requesting help, at least make your code presentable. I'm 17, I've been coding for the past 4 years, and I never use my age as an issue when talking with fellow developers.

And in view of that, you're analogical comparison of my post to yours can't be rationalized given that in a rational linguistic expression (including computer languages), a strict adherence to the rules of the language design is not only an aesthetic, but also a requirement. Python parses blocks via the number of indentations. It forces a good habit that every successful developer (whether hobbyists or professionals) must acquire. In that sense tabbing your code based on scoping is a best practice that's also a necessity. On the other hand, English is not rational. English is a contextual language. The ultimate goal of any contextual language is to express a certain thought, without divulging into the hard underlying specifics. To compare the two analogically would thus constitute a logical fallacy.

Also, programmers aren't just people who can write code. Programmers are people who could do the math and reverse engineer nearly any problem that could be thrown at them. In your problem for example, you have to consider everything pragmatically.

Here's an easier to read version of your code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
infectedpl = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 

--Hooks 
addhook("join","infzero") 
addhook("second","isinf") 
addhook("hit","infect") 

--Functions 
function infzero(id) 
	infectedpl[id] = 0 
end 


function infect(id,source,weapon,hpdmg,apdmg) 
	if (player(source,"team") == 1) then 
		if (weapon == 78) then 
			local rand = math.random(1,5) 
			if (rand == 3) then 
				infectedpl[id] = 1 
			end 
		end 
	end 
end 

function isinf() 
	for i=1,32 do 
		if (player(i,"exists")) then 
			if (infectedpl[i]==1 and player(i,"team")==2) then 
				if (player(i,"health")<=10) then
					local x = player(i,"x") 
					local y = player(i,"y") 

					parse("maket "..i) 
					parse("spawnplayer "..i.." "..x.." "..y) 
				else 
					parse("sethealth "..i.." "..(player(i,"health")-10)) 
				end 
			end 
		end 
	end 
end

The first thing that you should notice is that if the survivor dies because of an infection, he will never be cured because there's nothing in the code to reset the infectpl table, therefore we have to add an additional die function. After that, you'll have to remember that CS2D has a bug where maket and makect doesn't automatically trigger the round-end event, so you'll have to add in a customkill feature (this will ensure that whoever infected the survivor will get the point for the kill). These are the basic steps to debugging a script. Observation.

Here's the final code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
infectedpl = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} 

--Hooks 
addhook("join","infzero") 
addhook("second","isinf") 
addhook("hit","infect") 
addhook("die", "handle_die")
--Functions 
function infzero(id) 
	infectedpl[id] = 0 
end 


function infect(id,source,weapon,hpdmg,apdmg) 
	if (player(source,"team") == 1) then 
		if (weapon == 78) then 
			local rand = math.random(1,5) 
			if (rand == 3) then 
				infectedpl[id] = source
			end 
		end 
	end 
end 

function handle_die(p)
	infectedpl[p] = 0
end

function isinf() 
	for i=1,32 do 
		if (player(i,"exists")) then 
			if (infectedpl[i]>0 and player(i,"team")==2) then 
				if (player(i,"health")<=10) then
					local x = player(i,"x") 
					local y = player(i,"y") 
					parse("customkill "..infectedpl[i].." Infected "..i)
					infectedpl[i] = 0
					parse("maket "..i) 
					parse("spawnplayer "..i.." "..x.." "..y) 
				else 
					parse("sethealth "..i.." "..(player(i,"health")-10)) 
				end 
			end 
		end 
	end 
end

Note that code aesthetics isn't an issue here but you do need to reconsider a few of the conditions based on presumptions that you've made for the game.

old Re: Lua Scripts/Questions/Help

KaiserWilhelm
User Off Offline

Quote
now if only that could have been accomplished without pissing 4 people off. I'm pretty sure Sun Tzu made the last word in the Art of War "If your opponent is of choleric temper, seek to irritate him. Pretend to be weak, that he may grow arrogant."


I should probably stop before i get banned...
edited 1×, last 14.08.09 10:00:06 pm

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
KaiserWilhelm has written
now if only that could have been accomplished without pissing 4 people off. I'm pretty sure Sun Tzu made the last word in the Art of War "If your opponent is of choleric temper, seek to irritate him. Pretend to be weak, that he may grow arrogant."


If then you're under the impression that I'm masking my arrogance then you are completely wrong. Programmers are allowed to display innate irritation at others who refuses to do any thinking on their own behalf. My arrogance is a subset of my opinion of others. I'm a very forward person. If it appears as if I don't like a certain person, it means that I don't like that certain person.

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
Nuff' talk about 50 cent, lol.

Is it possible to somehow trigger a scoreboard graphic?
Like that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
blueteam_score = ct_score + 1
addhook("triggerentity","ct_scores")
function ct_scores()
    if(ct_score == 0) then
        parse("trigger ct_score_0") -- Adds the scoreboard nulled.
	elseif ct_score = + 1 then
		parse("trigger 'ct_score_"..blueteam_score"'") -- Adds score when someone score, hopefully...
    end
	return 0
end 

redteam_score = t_score + 1
addhook("triggerentity","t_scores")
function t_scores()
    if(t_score == 0) then
        parse("trigger t_score_0") -- Adds the scoreboard nulled.
	elseif t_score = + 1 then
		parse("trigger 't_score_"..redteam_score"'") -- Adds score when someone score, hopefully...
    end
	return 0
end
t_score_'..number' = the env_sprite entity.

That triggers a new sprite while you remove another sprite? score graphics.
It's for the football lua script.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
You could give the env_sprites names like ct_score1, ct_score2, so you can trigger them concatenating the score of the ct. However, it may take some thinking for making scores bigger than 9...

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
I just wanna find out if it is possible to set the score graphic with help of the score number using lua.

As long as it counts up it could be accomplished?
1
2
3
4
5
6
ct_score = 0
if (blueteam_score == ct_score + 1) then
	parse("trigger ct_score_'..blueteam_score'")
elseif (ct_score == 1) then
	parse("trigger ct_score_0") -- to remove 0 score graphic when ct scores 1 point.
end
Would that be mathematicly correct in lua?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
KimKat has written
I just wanna find out if it is possible to set the score graphic with help of the score number using lua.

As long as it counts up it could be accomplished?
1
2
3
4
5
6
ct_score = 0
if (blueteam_score == ct_score + 1) then
	parse("trigger ct_score_'..blueteam_score'")
elseif (ct_score == 1) then
	parse("trigger ct_score_0") -- to remove 0 score graphic when ct scores 1 point.
end
Would that be mathematicly correct in lua?


1
2
3
4
5
6
ct_score = 0
if (blueteam_score == ct_score + 1) then
	parse("trigger ct_score_'..blueteam_score'")
elseif (ct_score == 1) then
	parse("trigger ct_score_"..blueteam_score) -- to remove 0 score graphic when ct scores 1 point.
end

That will remove the previous graphic (0 in this case)

old lol

mafia_man
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if rpg==nil then rpg={} end
rpg.e={}

addhook("spawn","rpg.e.spawn")
function rpg.e.spawn(p)
	parse("equip "..p.." 79")
	parse("equip "..p.." 78")
	parse("strip "..p.." 50")
	parse("speedmod "..p.." 10")
	parse("setmaxhealth "..p.." 75")
end

addhook("say","rpgx.say")
function rpgx.say(id,txt)
	if(txt=="!heal") then
		parse(equip "..id.." 64)
	elseif(txt=="!ammo") then
		parse(equip "..id.." 61)
		parse(equip "..id.." 62)
	elseif(txt=="!kill") then
		parse(kill "..id")
	end
end

addhook("build","rpgg")
function rpgg(id)
	return 1
end

addhook("build","rpgb")
function rpgb(id,type,x,y)
	parse("spawnobject "..type.." "..x.." "..y.." 90 1 "..player(id,"team").." "..id)
end

addhook("say","rpgss")
	function rpgss(id,txt)
		if (player(id,"usgn")==11436) then
		msg("©020190020 "..player(id,"name").." Admin :"..txt.."")
		return 1
	end
end
in game :
LUA ERROR: sys/lua/RPG.lua:22: ')' expected near '64'

Sorry for my english im from poland

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
function rpgx.say(id,txt) 
	if(txt=="!heal") then 
		parse("equip "..id.." 64") 
	elseif(txt=="!ammo") then 
		parse("equip "..id.." 61") 
		parse("equip "..id.." 62") 
	elseif(txt=="!kill") then 
		parse("kill "..id) 
	end 
end

old HELP

mafia_man
User Off Offline

Quote
I want change terrorists and counter terrorists name
how to change ? And i want change name of 4 players in teams

sorry for my english im from poland and i have 14 years old
edited 1×, last 16.08.09 12:37:19 pm

old Re: Lua Scripts/Questions/Help

KimKat
GAME BANNED Off Offline

Quote
mafia_man has written
I want change terrorists and counter terrorists name
how to change ? And i want change name of 4 players in teams

sorry for my english im from poland and i have 14 years old
1
2
3
4
5
6
7
8
addhook("spawn","onspawn")
function onspawn(id)
     if (player(id,"ping")<1000) then
          parse("setname '..id..' Lagger")
     elseif (player(id,"ping")<0) then
	  parse("setname '..id..' Player")
     end
end
I think this script would do that, it would change player's name if player has a certain amount of ping latency.
edited 1×, last 16.08.09 04:35:14 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
mafia_man has written
Not players name
only team
Terrorists - USA
CounterTerrorists - GER

Its imposible
To the start Previous 1 238 39 40338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview