English Molotov Cocktail as buyable item

14 replies
Goto Page
To the start Previous 1 Next To the start
Up
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)
CS2D Global - cs2dglobal.tk
17.05.19 09:30:14 am
Up
Gaios
Security Supporter
Offline Off
I don't see team support for cs2d cmd mp_buymenu, so:

> Custom menu + cs2d lua hook buy
return 1
17.05.19 03:43:42 pm
Up
Bowlinghead
User
Offline Off
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.
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
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
edited 5×, last 17.05.19 04:22:27 pm
Share time limited free games here
17.05.19 04:48:23 pm
Up
Thanks, I'll test. And yea, for buyzone I will use Lua map specific.
CS2D Global - cs2dglobal.tk
17.05.19 04:57:27 pm
Up
Gaios
Security Supporter
Offline Off
@user Bowlinghead: You did it F3.. bad idea.
@user mrc: Anyway you don't need Lua map specific to get buyzones. You can get info from cs2d lua cmd entity. Probably in
int0
-
int9
or
str0
-
str9
17.05.19 05:03:47 pm
Up
Bowlinghead
User
Offline Off
@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
Code:
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 has written:
5. It must be buyable pressing F3 (hook serveraction with action == 2)
Share time limited free games here
17.05.19 06:37:02 pm
Up
Is better to use F3 than tipying "buy molotov" in the chat.
CS2D Global - cs2dglobal.tk
17.05.19 08:06:27 pm
Up
Gaios
Security Supporter
Offline Off
@user mrc: I didn't mean chat. I meant new buy menu.
17.05.19 09:24:18 pm
Up
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.
edited 8×, last 17.05.19 11:59:54 pm
CS2D Global - cs2dglobal.tk
18.05.19 12:12:25 am
Up
TrialAndError
User
Offline Off
Easy to torget that freehook takes 2 parameters

Code:
1
2
freehook("serveraction", "mc.serveraction")
freehook("second", "mc.second")
18.05.19 12:21:35 am
Up
Ty, and about the:

if (inentityzone(player(id,"x"), player(id,"y"), team) == true) then

Any idea to make it work?
CS2D Global - cs2dglobal.tk
18.05.19 12:59:51 am
Up
Bowlinghead
User
Offline Off
try if (inentityzone(player(id,"tilex"), player(id,"tiley"), team) == true) then
Share time limited free games here
18.05.19 01:54:41 am
Up
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:

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
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
edited 3×, last 18.05.19 02:43:24 am
CS2D Global - cs2dglobal.tk
18.05.19 10:20:26 am
Up
Bowlinghead
User
Offline Off
What have you done...



Anyway heres the way to go:
Code:
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)
Share time limited free games here
18.05.19 04:43:12 pm
Up
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.
edited 1×, last 18.05.19 04:53:26 pm
CS2D Global - cs2dglobal.tk
To the start Previous 1 Next To the start