Forum

> > CS2D > Scripts > Strange thing,if you combine the scripts with the
Forums overviewCS2D overview Scripts overviewLog in to reply

English Strange thing,if you combine the scripts with the

4 replies
To the start Previous 1 Next To the start

old Strange thing,if you combine the scripts with the

0oa
User Off Offline

Quote
I wanted to make a shop,and I noticed a strange feature.

If you use the function in the map,then there is,
Put trigger - if,and care a there 'buy(<x>,<y>)', then will magic

In some strange way, the menu display will not display buttons!

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
function buy(x,y)

 local v_menu = Menu.Add("Buy")

 	v_menu:DoClick(" : Primary ammo :| 200p ",function(ply) 
 		if ply:GetMoney() > 200 then 
 			ply:SetMoney(ply:GetMoney() - 200)
 			parse("spawnitem 61 " .. x .. " " .. y )
 		end
 	end)

 	v_menu:DoClick(" : Secendory ammo :| 150p ",function(ply) 
 		if ply:GetMoney() > 150 then 
 			ply:SetMoney(ply:GetMoney() - 150)
 			parse("spawnitem 62 " .. x .. " " .. y )
 		end
 	end)

 for i,id in pairs(closeplayers(( x * 32 ) + 16,( y * 32 ) + 16,16)) do
  local ply = Player.GetPlayerID(id) 
 	ply:Menu("Buy")
 	-- menu(1,"hello,hi,he") - is not working
 end


if type(closeplayers(( x * 32 ) + 16,( y * 32 ) + 16,16)) ~= "table" then return false else return true end
end

That's what I did on the map.
IMG:https://www.dropbox.com/s/m6vz6koiaf0su89/1.PNG?dl=1


IMG:https://www.dropbox.com/s/7uk9kaak3tkq2pz/2.PNG?dl=1


Help me please.


Problem solved.,
When you press use menu appeared with the name 'search'.
Well inattentive in
edited 1×, last 30.07.19 10:19:17 am

old Re: Strange thing,if you combine the scripts with the

DC
Admin Off Offline

Quote
by the way:
1
if type(closeplayers(( x * 32 ) + 16,( y * 32 ) + 16,16)) ~= "table" then return false else return true end

This is bad code style.
Whenever you do a
return true else return false
or the other way around your code is too complicated and can be simplified.

Do this instead:
1
return type(closeplayers(( x * 32 ) + 16,( y * 32 ) + 16,16)) == "table"

actually... isn't that always true? cs2d lua cmd closeplayers should always return a table according to the documentation.

old Re: Strange thing,if you combine the scripts with the

Gaios
Reviewer Off Offline

Quote
user DC has written
by the way:
1
if type(closeplayers(( x * 32 ) + 16,( y * 32 ) + 16,16)) ~= "table" then return false else return true end

This is bad code style.
Whenever you do a
return true else return false
or the other way around your code is too complicated and can be simplified.

Do this instead:
1
return type(closeplayers(( x * 32 ) + 16,( y * 32 ) + 16,16)) == "table"

actually... isn't that always true? cs2d lua cmd closeplayers should always return a table according to the documentation.

cs2d lua cmd hascloseplayers
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview