Forum

> > CS2D > Scripts > spawn hook
Forums overviewCS2D overview Scripts overviewLog in to reply

English spawn hook

11 replies
To the start Previous 1 Next To the start

old spawn hook

kalis
User Off Offline

Quote
hey all
who can help me ?
i create new script
but i have problem
ex :
when play i get portal and m4a1
when die i'm lost it
and i use hook spawn
i want that, when spawn lua give all item i got(portal,m4a1)!
1
2
3
4
5
6
7
8
addhook("spawn","sp")
function sp(id)
i_tem[id] = playerweapons(id)
if level[id] >= 1 then 
parse("equip "..id.." "..i_tem[id])
return 1
end
end
added array of item , level
help pls

old Re: spawn hook

EnderCrypt
User Off Offline

Quote
hm i dont se what your trying to do, but have you initzialized the array

i_item= {}

you gotta do that with all tables first

and can you show the error?
edited 1×, last 23.06.11 03:13:51 pm

old Re: spawn hook

kalis
User Off Offline

Quote
wait i testing your code darkcrypt
who can give me right lua =.=

old Re: spawn hook

EnderCrypt
User Off Offline

Quote
oh wait now i se a problem, you put

i_tem[id] = playerweapons(id)
here you put a table if weapns on the table using id as index¨

if level[id] >= 1 then
now you check if level[id] > or = as 1, however level[id] contains a table, not a number

old Re: spawn hook

kalis
User Off Offline

Quote
level[id] worked =.=
it give me error item 0 does exists (ERROR : CANT EQUIP)

old Re: spawn hook

EnderCrypt
User Off Offline

Quote
ok listen now
i_tem[id] = playerweapons(id)
this puts all weapobs player got (a table), into the table

parse("equip "..id.." "..i_tem[id])
here you try equip id with the TABLE,

so player needs to be equiped with a weapon id, not a table comtaining weapon id

old Re: spawn hook

Infinite Rain
Reviewer Off Offline

Quote
loool
1
2
3
4
5
6
7
8
9
10
11
addhook('die', 'die_hook')
function die_hook(v, k)
	i_item[v] = playerweapons(v)
end

addhook('spawn', 'spawn_hook')
function spawn_hook(id)
	for n, w in ipairs(i_item[id]) do
		parse('equip '.. id ..' '..w)
	end
end

If I understands you right

old Re: spawn hook

DC
Admin Off Offline

Quote
general common mistake: NEVER EVER use the equip command during a spawn hook!

spawn itself will equip stuff so it's a really bad idea. instead use the return command within the spawn hook to define the items that you want to equip!

see
cs2d lua hook spawn

old Re: spawn hook

Infinite Rain
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
addhook('die', 'die_hook')
function die_hook(v, k)
     i_item[v] = playerweapons(v)
end

addhook('spawn', 'spawn_hook')
function spawn_hook(id)
	parse('strip '.. id ..' 0')
     for n, w in ipairs(i_item[id]) do
          parse('equip '.. id ..' '..w)
     end
end

old Re: spawn hook

kalis
User Off Offline

Quote
thank all
@factis699
it work but have error
1
bad argument #1 to 'ipairs' (taqble expected, got number)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview