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 227 28 29338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Zune5
COMMUNITY BANNED Off Offline

Quote
Can anyone create a script so that when you build something, it instantly builds? As in, no "Construction Sites?"

old Re: Lua Scripts/Questions/Help

Proah
User Off Offline

Quote
How can I get the item ID from the hook "attack"


So, someone attacks and it changes variable "wpn" to the ID of the weapon they used...

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Quote
How can I get the item ID from the hook "attack"


So, someone attacks and it changes variable "wpn" to the ID of the weapon they used...


you can't the only workaround to this is if you add the following

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
local _weapon_addhook = addhook
local _weapon_hooks = {}

addhook("attack", "hk_attack")

function _g(t)
	if _G[t] then return _G[t] end
	local fn = loadstring("return "..t)
	if fn then return fn() end
end

function addhook(a, b)
	if a == "attack" then
		table.insert(_weapon_hooks, b)
	else
		_weapon_addhook(a, b)
	end
end

function hk_attack(id)
	local ret = nil
	for i, v in ipairs(_weapon_hooks) do
		local fn = _g(v)
		if not fn then break end
		if type(fn) ~= "function" then break end
		ret = fn(id, player(id, "weapontype"))
	end

	return ret
end

This is a bit advanced so if you need me to explain this to you then you'll have to actually say that you want to know how this works, but it should work. Note, if you use attack on any type of grenades, this will return either Knife or your Primary weapon.

NOTE: Put This at the VERY top of your script.

Also, for performance issues, avoid putting your attack functions inside of tables since it'll be a bit slower.

And then you can use hook attack(id, weaponid)

1
2
3
4
5
6
7
addhook("attack", "healer")

function healer(p, w)
	if w == 50 then
		parse("sethealth "..p.." "..player(p, "health")+5)
	end
end
edited 2×, last 13.07.09 07:33:00 am

old Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
Why do it so hard leegao?

1
2
3
4
addhook("attack","attack1")
function attack1(p)
	msg(player(p,"name").." Used the "..itemtype(player(p,"weapontype"),"name"))
end


Impossible to get the values of this?

Like 'mp_building_limit "Wall III"'

mp_building_health
mp_building_limit
mp_building_price

Should be nice to check the price, limit and health for the construction items.
That is changed by the owner.
edited 1×, last 13.07.09 12:13:45 pm

old Re: Lua Scripts/Questions/Help

mortyr22
User Off Offline

Quote
i create my big script!please help.
1)if you pick up armor then sound ...
1)if you health with this armor 10 then sound ...
(once!)

old Re: Lua Scripts/Questions/Help

wups
User Off Offline

Quote
@mortyr

Look for walkover and sv_sound

Can you stop thinking that you can get all on a gold-plate.
You only wants whole codes, you have never testing to coding by your self.
edited 2×, last 13.07.09 02:54:29 pm

old Re: Lua Scripts/Questions/Help

Zune5
COMMUNITY BANNED Off Offline

Quote
Zune5 has written
Can anyone create a script so that when you build something, it instantly builds? As in, no "Construction Sites?"


No one?

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
wups has written
Why do it so hard leegao?

1
2
3
4
addhook("attack","attack1")
function attack1(p)
	msg(player(p,"name").." Used the "..itemtype(player(p,"weapontype"),"name"))
end


DRY - Don't repeat yourself, aka refactor when you can. I'm used to working on big projects so if I know I'll have multiple uses of attack hook then I make sure that I don't have to retype the same thing all over again. This way, if I want to change something, I only update one part of my code, not a dozen.

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
mortyr22 has written
i need:
1:if you pick up item ... then sound ...(once)

1
2
3
4
addhook("walkover","walkovers")
function walkovers(id,iid,type)
	parse("sv_sound \"fun/prepare.wav\"")
end
2: I dont get what you want. (Then you want sound once?)
edited 1×, last 13.07.09 09:49:20 pm

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Quote
2:if you have ... hp and this item then sound ... (once)


Here's the cases where your HP will change, and I'm also assuming that

hit
parse "sethealth..."

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
lookforHP = {50, 25}
wpns = {[50]=true, [30]=true}

function inhp(i_hp, hp)
	for i, l_hp in ipairs(lookforHP) do
		if l_hp <= i_hp and l_hp >=hp then return true end
	end
end

function inwpn(wpn)
	if wpns[wpn] then return true end
end

function dosomething(p)
	msg2(p, "You should hear the prepare sound.")
	parse("sv_sound \"fun/prepare.wav\"")
end

addhook("hit", "hpsound")
function hpsound(p, s, w, _hp, ap)
	local hp = player(p, "health")
	local i_hp = hp + _hp
	if inhp(i_hp, hp) and inwpn(player(p, "weapontype")) then
		dosomething(p)
	end
end

addhook("parse", "psound")
function psound(t)
	local cmd = {}

	for word in string.gmatch(t, "[^%s]+") do
		table.insert(cmd, word)
	end

	if cmd[1] == "sethealth" then
		local p = tonumber(cmd[2])
		local hp = tonumber(cmd[3])

	if inhp(hp, hp) and inwpn(player(p, "weapontype")) then
			dosomething(p)
		end
	end
end

Edit lookforHP table to add more hps to the list. The default wpns table will activate this command for Knife and AK47. Change the dosomething(p) function to do what you need to have done when the health gets to those levels.

old Completely unrelated stuff...

KaiserWilhelm
User Off Offline

Quote
Hi i'm unwilling to start a new thread over something this stupid so here it goes...
I'm looking for a way to block the building of all buildings EXCEPT the barricades (or barbwire or turrets, etc.). I've tried and failed, miserably. Now I'm looking for help from the pros. Could you please offer a hand, Its the final touch on this custom map.

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
I need some help here,
now I'm making lua script named Rank Mod, I already half done with it. but, the problem is, whenever he die. he lost his speed and weapon and respawn with nothing. how to make it if die and it will stay?
To the start Previous 1 227 28 29338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview