Forum

> > CS2D > General > Molotov Cocktail as buyable item
ForenübersichtCS2D-ÜbersichtGeneral-ÜbersichtEinloggen, um zu antworten

Englisch Molotov Cocktail as buyable item

14 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Molotov Cocktail as buyable item

mrc
User Spielt CS2D

Zitieren
I need a script that allows a player to buy Molotov Cocktail, and no, mp_buymenu doesn't work for what I need because it creates a single menu for both teams. If I use it I have to allow T and CT to use and buy the same weapons (AK+M4) and I don't want that.

So...

1. It must be buyable on CT spawn for CT and on T spawn for T only (probably with the move hook and have to set X and Y of the area of each team base)
2. It must be buyable while mp_buytime allows to buy (maybe with if(tonumber(game("mp_buytime")) > 0)
3. It must be buyable only once in the round for each player (probably using value 1 after buying to not allow buy more and value 0 on startround to allow if the player isn't carrying one already)
4. It must remove -300$ from the player (probably player(id,"money") - 300, idk lol)
5. It must be buyable pressing F3 (hook serveraction with action == 2)

alt Re: Molotov Cocktail as buyable item

Bowlinghead
User Off Offline

Zitieren
There is no command to see wether a player is inside a buyzone or not.
cs2d lua cmd tile , cs2d lua cmd map , cs2d lua cmd player , cs2d lua cmd game
So you have to make the Lua map specific.

Edit: Nevermind I didnt read the docs careful.
You gotta declare your mp_buytime per script as you cant get this value per Lua.
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
--untested
-- http://www.cs2d.com/entities.php
mc = {}
mc.costs = 300
mc.molotovId = 73
mc.buyTime = 30 	-- buytime in seconds
mc.timerBuy = 0 	-- counter from startround
mc.player = {}  	-- [id] = true/false ; did player buy molotov already?


-- BUY TIMER
parse("mp_buytime "..mc.buyTime)
addhook("startround", "mc.startround")
function mc.startround()
	addhook("serveraction","mc.serveraction")
	addhook("second","mc.second")
	parse("mp_buytime "..mc.buyTime/60)
	mc.timerBuy = 0

	mc.player = {} -- delete old buy status
end

function mc.second()
	mc.timerBuy = mc.timerBuy + 1
	if (mc.timerBuy >= mc.buyTime) then
		freehook("mc.serveraction")
		freehook("mc.second")
	end
end


-- MOLOTOV BUY 
function mc.serveraction(id, b)
	if (b==2) then
		if player(id,"team") == 1 then
			mc.doStuff(id, 0) -- entity 0 = tt spawn
		else
			mc.doStuff(id, 1) -- entity 1 = ct spawn
		end
	end
end

function mc.doStuff(id, team)
	if (player(id,"money") >= mc.costs) then
		if (mc.player[id] ~= true) then
			if (inentityzone(player(id,"x"), player(id,"y"), team) == true) then
				parse("setmoney "..id.." "..player(id,"money") - mc.costs)
				parse("equip "..id.." "..mc.molotovId)
				mc.player[id] = true
			end
		end
	end
end
5× editiert, zuletzt 17.05.19 16:22:27

alt Re: Molotov Cocktail as buyable item

Bowlinghead
User Off Offline

Zitieren
@user Gaios:
No I first thought you have to save the position of the buyzones in Lua. But you can read it from the game (see script). Lua CANT read the buy time so that is what you have to define in my script! (line 6!)

cs2d lua cmd inentityzone
http://www.cs2d.com/entities.php
1
2
3
4
x = player(id,"x")
y = player(id,"y")
if (inentityzone(x, y, 0)) then -- in TT spawn therefore in TT buy zone
if (inentityzone(x, y, 1)) then -- in CT spawn therefore in CT buy zone


@user Gaios:
user mrc hat geschrieben
5. It must be buyable pressing F3 (hook serveraction with action == 2)

alt Re: Molotov Cocktail as buyable item

mrc
User Spielt CS2D

Zitieren
Oh right, maybe DC could improve the mp_buymenu to what we've discussed in here. Btw Tactical Shield and Night Vision are useless anyway. We could have Zeus x27 (or Decoy) and Molotov instead. Also would be awesome to have new weapons from CSGO.

@user Bowlinghead: script didn't work.

-> [C]: in function 'freehook'
-> sys/lua/autorun/molotov.lua:27: in function <sys/lua/autorun/molotov.lua:23>
LUA ERROR: sys/lua/autorun/molotov.lua:27: bad argument #2 to 'freehook' (string expected, got no value)

I removed the "if (inentityzone(player(id,"x"), player(id,"y"), team) == true) then" and I was able to buy anywhere at least. But the error above still persist.
8× editiert, zuletzt 17.05.19 23:59:54

alt Re: Molotov Cocktail as buyable item

mrc
User Spielt CS2D

Zitieren
I would like to add the message "Buytime passed - you can't buy anymore" but it will require to change the script and I don't want to do that, btw it's just a detail. The script is working now with sound on buying, costing 400 for T and 600 for CT (like CSGO). Ty guys, enjoy:

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--tested
-- http://www.cs2d.com/entities.php
mc = {}
mc.costsT = 400
mc.costsCT = 600
mc.molotovId = 73
mc.buyTime = 510      -- buytime in seconds (510 = 15 sec. in-game [for 30 sec. change to 1020 and so on])
mc.timerBuy = 0      -- counter from startround
mc.player = {}       -- [id] = true/false ; did player buy molotov already?

-- BUY TIMER
parse("mp_buytime "..mc.buyTime)
addhook("startround", "mc.startround")
function mc.startround()
     addhook("serveraction","mc.serveraction")
     addhook("second","mc.second")
     parse("mp_buytime "..mc.buyTime/60)
     mc.timerBuy = 0

     mc.player = {} -- delete old buy status
end

function mc.second()
	 for id = 1,32 do
		 mc.timerBuy = mc.timerBuy + 1
		 if (mc.timerBuy >= mc.buyTime) then
		 freehook("serveraction", "mc.serveraction")
		 freehook("second", "mc.second")
		 end
	 end
end

-- MOLOTOV BUY 
function mc.serveraction(id, b)
	if (b==2) then
		if player(id,"team") == 1 then
		mc.doStuff(id, 0) -- entity 0 = tt spawn
		else
		mc.doStuff(id, 1) -- entity 1 = ct spawn
		end
	end
end

function mc.doStuff(id, team)
	if player(id,"team") == 1 then
		if (player(id,"money") >= mc.costsT) then
			if (mc.player[id] ~= true) then
				if (inentityzone(player(id,"tilex"), player(id,"tiley"), team) == true) then
					parse("setmoney "..id.." "..player(id,"money") - mc.costsT)
					parse("equip "..id.." "..mc.molotovId)
					parse("setweapon "..id.." "..mc.molotovId)
					parse('sv_soundpos "/items/pickup.wav" '..player(id,'x')..' '..player(id,'y')..'')
					mc.player[id] = true
				else
				msg2(id,"\169255000000You are not in a buyzone@C")
				end
			else
			msg2(id,"\169255000000Grenade rebuying is not allowed on this server@C")	
			end
		else
		msg2(id,"\169255000000You have insufficient funds@C")
		end
	else
		if (player(id,"money") >= mc.costsCT) then
			if (mc.player[id] ~= true) then
				if (inentityzone(player(id,"tilex"), player(id,"tiley"), team) == true) then
				parse("setmoney "..id.." "..player(id,"money") - mc.costsCT)
				parse("equip "..id.." "..mc.molotovId)
				parse("setweapon "..id.." "..mc.molotovId)
				parse('sv_soundpos "/items/pickup.wav" '..player(id,'x')..' '..player(id,'y')..'')
				mc.player[id] = true
				else
				msg2(id,"\169255000000You are not in a buyzone@C")
				end
			else
			msg2(id,"\169255000000Grenade rebuying is not allowed on this server@C")	
			end
		else
		msg2(id,"\169255000000You have insufficient funds@C")
		end
	end
end
3× editiert, zuletzt 18.05.19 02:43:24

alt Re: Molotov Cocktail as buyable item

Bowlinghead
User Off Offline

Zitieren
What have you done...



Anyway heres the way to go:
1
2
3
4
5
6
7
8
function mc.second()
           mc.timerBuy = mc.timerBuy + 1
           if (mc.timerBuy >= mc.buyTime) then
	   msg("BUY TIME PASSED ZUCKER BLÖD") -- HERE 
           freehook("serveraction", "mc.serveraction")
           freehook("second", "mc.second")
           end
end

If I write "in secs": mc.buyTime = 510 -- buytime in seconds
Then I mean in SECONDS ...
parse("mp_buytime "..mc.buyTime/60)

alt Re: Molotov Cocktail as buyable item

mrc
User Spielt CS2D

Zitieren
Well didnt work this way ingame, thats why I had to increase the value. After some tests I found the value for 15 seconds. And about the buytime passed, I don't want the message automatically when the time passed, it should appear when the buy button (f3) is pressed. I tried and for some reason it didnt work.
1× editiert, zuletzt 18.05.19 16:53:26
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenGeneral-ÜbersichtCS2D-ÜbersichtForenübersicht