Forum

> > CS2D > Scripts > Spawn items on player after getting x points
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spawn items on player after getting x points

6 replies
To the start Previous 1 Next To the start

old Spawn items on player after getting x points

Nori-chan
User Off Offline

Quote
Hello guys.
i'm trying to make a way to spawn items (in this case, a smoke grenade) on the player after getting 300 points.

Here is my script:
Spoiler >


I already added a way to show how many points do you have in that life (thanks Yates for helping me with that),
for example, if you kill an enemy, you get 100 points. or if you capture a flag in DOM gamemode, you get 100 points.

The "pon" is how many points do you have now.

Now the problem (line 10 to line 15):

I tried to create a way to spawn a Smoke grenade after getting 300 points. But I had no ideia on what addhook to use, I tried the ms100, since it's gonna check 10 times in 1 second, but there is no id parameter. So I'm using the "move".

The line 13 is the code that should spawn the item, but it's not working.
Also, there is an error on the console: LUA ERROR: sys/lua/autorun/ks.lua:13: ')' expected near '...'

So guys, please help me to fix that.
Thank you for helping me.

old Re: Spawn items on player after getting x points

Cure Pikachu
User Off Offline

Quote
1.
1
player(id,"pon")
Wrong usage. It should be
1
pon[id]
2.
1
parse("spawnitem 54 "...player(id,"x")..." "...player(id,"y")..." ")
It's not 3 dots, it's 2. Also, cs2d cmd spawnitem 's x and y parameters are in tiles. So it should be
1
parse("spawnitem 54 "..player(id,"tilex").." "..player(id,"tiley"))
3. Also you might want to make it such that it doesn't spawn smoke grenades every time you move while the points you have is at 300.

EDIT x2: I reverted back. Sorry for bump.
edited 4×, last 04.03.13 08:24:15 pm

old Re: Spawn items on player after getting x points

Nori-chan
User Off Offline

Quote
user Cure Pikachu has written
1.
1
player(id,"pon")
Wrong usage. It should be
1
pon[id]
2.
1
parse("spawnitem 54 "...player(id,"x")..." "...player(id,"y")..." ")
It's not 3 dots, it's 2. Also, cs2d cmd spawnitem 's x and y parameters are in tiles. So it should be
1
parse("spawnitem 54 "..player(id,"tilex").." "..player(id,"tiley"))
3. Also you might want to make it such that it doesn't spawn smoke grenades every time you move while the points you have is at 300.



Ok, tested and working. Thank you.


But as you said, If I have 300 points, I keepdroping many smoke grenades. Is there any way to spawn once?

Well, I'm gonna try by myself, but if you know the answer, please, post here.

old Re: Spawn items on player after getting x points

Avo
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function initArray(m,v)
	local array = {}
	for i = 1, m do
		array[i] = v
	end
	return array
end
pon=initArray(32,0)
          
function addPoints(id,amount)
	pon[id] = pon[id] + amount
	if pon[id] >= 300 then
		parse("spawnitem 54 "..player(id,"tilex").." "..player(id,"tiley"))
		addPoints(id,-300)
	end
	score_show(id)
end 

addhook("die","reset_points")
function reset_points(id)
     if (player(id,"exists")) then
		pon[id]=0
     end
end


addhook("kill","kill_points")
function kill_points(id)
	addPoints(id, 100)
end
     
addhook("hostagerescue","hostage_points")
function hostage_points(id)
    addPoints(id, 25)
end

addhook("dominate","dominate_points")
function dominate_points(id)
     addPoints(id, 100)
end

addhook("bombplant","bp_points")
function bp_points(id)
     addPoints(id, 50)
end

addhook("bombexplode","be_points")
function be_points(id)
    addPoints(id, 50)
end

addhook("bombdefuse","bd_points")
function bd_points(id)
    addPoints(id, 100)
end

     
addhook("spawn","score_show")
function score_show(id)
    parse('hudtxt2 '..id..' 49 "©255255255Support Action Points: '..pon[id]..'" 7 115 0')
end

old Re: Spawn items on player after getting x points

Nori-chan
User Off Offline

Quote
user Avo has written
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function initArray(m,v)
	local array = {}
	for i = 1, m do
		array[i] = v
	end
	return array
end
pon=initArray(32,0)
          
function addPoints(id,amount)
	pon[id] = pon[id] + amount
	if pon[id] >= 300 then
		parse("spawnitem 54 "..player(id,"tilex").." "..player(id,"tiley"))
		addPoints(id,-300)
	end
	score_show(id)
end 

addhook("die","reset_points")
function reset_points(id)
     if (player(id,"exists")) then
		pon[id]=0
     end
end


addhook("kill","kill_points")
function kill_points(id)
	addPoints(id, 100)
end
     
addhook("hostagerescue","hostage_points")
function hostage_points(id)
    addPoints(id, 25)
end

addhook("dominate","dominate_points")
function dominate_points(id)
     addPoints(id, 100)
end

addhook("bombplant","bp_points")
function bp_points(id)
     addPoints(id, 50)
end

addhook("bombexplode","be_points")
function be_points(id)
    addPoints(id, 50)
end

addhook("bombdefuse","bd_points")
function bd_points(id)
    addPoints(id, 100)
end

     
addhook("spawn","score_show")
function score_show(id)
    parse('hudtxt2 '..id..' 49 "©255255255Support Action Points: '..pon[id]..'" 7 115 0')
end



Hmm, I liked that code, but I created a way to get rid of those smokes (after earning 300 points, you automaticaly earn 25 points for getting a smoke grenade, lol)

But anyway, thanks for helping me

EDIT: Ok, before closing this thread, one question:

Well, now it's working as it should. After x points, you get something.

But, when I get an item (eg. the Smoke Grenade) It will spawn on me, but I can't collect it. I have to walk away a little, then come back to collect it (If you guys doesn't understandm I will upload a video, because I can't explain it very well).

So, any way to get the item automatically cllected by the player?
edited 1×, last 04.03.13 09:06:28 pm

old Re: Spawn items on player after getting x points

Nori-chan
User Off Offline

Quote
user Cure Pikachu has written
1
2
parse("equip "..id.." 54")
-- parse("setweapon "..id.." 54")
This automatically adds smoke grenades to their inventory. Remove the -- in line 2 to also make them select the smoke grenade as their weapon.


I already did that (I forgot to remove that on the code here)

But yeah, I still have the problem.

EDIT: Nevermind. I've fixed it.
edited 1×, last 05.03.13 12:38:32 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview