Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 2219 220 221338 339 Next To the start

old Re: Lua Scripts/Questions/Help

martis67
User Off Offline

Quote
addhook("startround","sample.gg.start")
function sample.gg.start()
     -- Reset Values
     local i
     for i=1,32 do
          sample.gg.level[i]=1
          sample.gg.kills[i]=0
          -- Reset Weapon (Kill)
          if (player(i,"exists")) then
               -- Strip All Weapons (0)
               parse("strip "..i.." 0")
               -- Give first Weapon
               parse("equip "..i.." "..sample.gg.wpn[1])
               -- Strip Knife
               parse("strip "..i.." 50")
          end
     end
end

-----------------------
-- JOIN --
-----------------------
addhook("join","sample.gg.join")
function sample.gg.join(id)
     -- Reset
     sample.gg.level[id]=1
     sample.gg.kills[id]=0
end


-----------------------
-- SPAWN --
-----------------------
addhook("spawn","sample.gg.spawn")
function sample.gg.spawn(id)
     -- Minimum Level is 1
     if (sample.gg.level[id]<1) then
          sample.gg.level[id]=1
     end
     
     
     -- Equip with Weapon for current Level
     if (sample.gg.level[id]>0 and sample.gg.level[id]<=10) then
          return sample.gg.wpn[sample.gg.level[id]]
     end
end

-----------------------
-- KILL --
-----------------------
addhook("kill","sample.gg.kill")
function sample.gg.kill(id)
     -- Add Kill
     sample.gg.kills[id]=sample.gg.kills[id]+1
     -- Next Level?
     if (sample.gg.kills[id]>=3) then
          -- Reset Kills
          sample.gg.kills[id]=0
          -- Increase Level
          sample.gg.level[id]=sample.gg.level[id]+1
          -- Win?
          if (sample.gg.level[id]>=#sample.gg.wpn) then
               msg("©000255000"..player(id,"name").." has won the game!@C")
               parse("restart")
          else
               -- Give new Weapon
               parse("equip "..id.." "..sample.gg.wpn[sample.gg.level[id]])
               -- Remove last Weapon
               parse("strip "..id.." "..sample.gg.wpn[sample.gg.level[id]-1])
          end
     end
     -- Info
     if (sample.gg.level[id]<11) then
          msg2(id,"Level: "..sample.gg.level[id].." Kills: "..sample.gg.kills[id])
     end
end



hmm next i dont copyed bekuz then been no colecting and more and more

old Re: Lua Scripts/Questions/Help

martis67
User Off Offline

Quote
addhook("kill","sample.gg.kill")
function sample.gg.kill(id)
-- Add Kill
sample.gg.kills[id]=sample.gg.kills[id]+1
-- Next Level?
if (sample.gg.kills[id]>=3) then
-- Reset Kills
sample.gg.kills[id]=0
-- Increase Level
sample.gg.level[id]=sample.gg.level[id]+1
-- Win?
if (sample.gg.level[id]>=#sample.gg.wpn) then
msg("©000255000"..player(id,"name").." has won the game!@C")
parse("restart")
else
-- Give new Weapon
parse("equip "..id.." "..sample.gg.wpn[sample.gg.level[id]])
-- Remove last Weapon
parse("strip "..id.." "..sample.gg.wpn[sample.gg.level[id]-1])
end
end
-- Info
if (sample.gg.level[id]<11) then
msg2(id,"Level: "..sample.gg.level[id].." Kills: "..sample.gg.kills[id])
end
end

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
I need a script when you press like a button called hm1
then a menu shows up

and a script when you walk over X 1000 and Y 1000 you die

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
How to change pixel pos x and pixel pos y to tile pos x/y?
Edit nvm I found a way.
Edit:
My way is still a bit inaccurate could someone post a way?

old What's your name ?

BrunoRZ
User Off Offline

Quote
Well, I need a VERY simple thing...
In my town people can work in certains places, like a bank, but how can the NAME of a player appears when he start working instead of ID NUMBER ?

>parse("sv_msg "..id.." agora é bancário@C")

What should I put on "..id.." ?

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
1
parse("sv_msg "..player(id, "name"))
How to get a value of a player:
call function player()
with the core (i.e., the first) parameter the id of the player and the second being the value you wish to obtain it will return that value
so
1
hp = player(1, "health")
hp is a variable that contains the first players health
1
hp = hp - 1
will NOT alter the players health but change the value of the variable hp

1
parse("sethealth 1 " .. hp - 1)
does change the players health

if your wondering what .. is that is Lua for concatenation that is a fancy word for combine these things into one

so
1
2
3
4
a = "hel"
b = "lo, w"
c = a .. b .. "orld"
print ( c )
will write to the console
hello, world

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Dark Byte has written
How to change pixel pos x and pixel pos y to tile pos x/y?
Edit nvm I found a way.
Edit:
My way is still a bit inaccurate could someone post a way?


Divide by 32 and use math.floor or math.ceil
Or instead you can use your own math.round function.
1
2
3
function math.round(x)
	return math.floor(x+0.5)
end
Maybe that's more accurate

old Re: Lua Scripts/Questions/Help

BrunoRZ
User Off Offline

Quote
Dark Byte has written
1
parse("sv_msg "..player(id, "name"))
How to get a value of a player:
call function player()
with the core (i.e., the first) parameter the id of the player and the second being the value you wish to obtain it will return that value
so
1
hp = player(1, "health")
hp is a variable that contains the first players health
1
2
3
hp = hp - 1

I couldn't understand... can you write it in the final result please ?
will NOT alter the players health but change the value of the variable hp

1
parse("sethealth 1 " .. hp - 1)
does change the players health

if your wondering what .. is that is Lua for concatenation that is a fancy word for combine these things into one

so
1
2
3
4
a = "hel"
b = "lo, w"
c = a .. b .. "orld"
print ( c )
will write to the console
hello, world

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Dark Byte has written
Does anyone know how to convert decimal to binary in Lua I tried but failed hopelessly.


This is from any base to any base:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function log(x, b)
	return math.log(x)/math.log(b)
end

function toBaseN(x,n)
	local digits = {}
	for i=math.floor(log(x,n)), 0, -1 do
		table.insert(digits, math.floor(x/(n^i)))
		x=x%(n^i)
	end
	return digits
end

function baseAtoB(x,a,b)
	local base10 = 0
	for i=0,#x-1 do
		base10 = base10 + x[#x-i]*a^i
	end
	return toBaseN(base10,b)
end

See my reply to your PM for more details.

old Re: Lua Scripts/Questions/Help

TimeQuesT
User Off Offline

Quote
idk if this work , i did'n test it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook ("spawn","span")
addhook ("menu","meno")

function span(id)
menu(id,"how are you?,fine,baaadd")
end

function meno(id,menu,sel)

if menu=="how are you?" then

if sel==1 then
msg2 (id,"good to hear that!")
elseif sel==2 then
msg2 (id,"m... play a bit maybe you will feel better than.")
end

end
end

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
This has been discussed atleast a thousand times.
You can't change the labels for CTs and Ts, not even with Lua. Period.

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
I noticed several people that don't understand menus. The examples we make to show them will make a menu, but they don't understand it. Therefore can't create their own. So hear is a tutorial for menus.
----------------------
To create a menu you must use the function menu.
1
menu(id,"a menu,b1,b2,,b4")

Okay but now you want to know what id,b1,etc are. id is the player's id that you wish to show the menu to.
1
menu(1,"a menu,b1,b2,,b4")
That will show a menu to the player with the id of one. Note: this is the player id (ranges 1 to 32) not USGN.

Now to "a menu,b1,...." notice that they are separated by commas. The first "a menu" is the menus title or name. This will appear at the top of a menu.

"b1" is the first button that people can select from. "b2" the second button. Wait there is no "b3" leaving a name space complete blank will produce an empty button that can't be selected. A space by itself will return a button with no writing. "b4" is our last button. The current maximum of buttons is nine, and be sure to segregate them with a comma.

Now you know how to create a menu, but you still need to know how to make them functional. This is a bit more complicated.

first add a hook to menus.
1
addhook("menu", "menu_func")
menu_func can be replaced with most anything, but I suggest you leave it at that. Now all you need is a function for the hook.
1
2
3
function menu_hook (id,title,b)

end
That will do nothing at all. Before we add our functionality let me explain what id,title, and b are. id is the players id that is in the menu (the same as above in the menu function). title is the menu's name, and b is the button number not the name we gave it. In our case "b1" is the first button "b2" the second, b4 the fourth (remember we left b3 out).
Sidenote: a "--" double hyphen are comments in Lua and will not be executed look for these is the next code.
1
2
3
4
5
6
7
8
9
10
11
12
-- Create the menu
menu(1,"a menu,b1,b2,,b4")

-- Add the menu hook
addhook("menu", "menu_func")

-- Add functionality
function menu_func (id,title,b)
	if ( title == "a menu" ) then -- Is this our menu if so continue
		msg2(id, "You pressed b"..b) -- Give the player a message
	end -- end the if
end -- end the function

Hope that helped.

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
Msek i think something like this

1
2
3
4
5
6
7
8
9
10
11
addhook("team","name_team")
function name_team(id)
pname = (player(id,"name")
	if (player(id,"team") == 2) then
		parse("setname "..id.." [CT]"..pname)
	elseif (player(id,"team") == 1) then
		parse("setname "..id.." [TT]"..pname)
	elseif (player(id,"team") == 0) then
		parse("setname "..id.." [SPEC]"..pname)
	end
end


I think somthing like that but i dont know if this works
To the start Previous 1 2219 220 221338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview