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 2328 329 330338 339 Next To the start

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
@Dark Byte Ideally you could, but you would need to use c++ interface to work with .DLL in Lua.
C++ Code ~= work with Lua.

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
Thanks. Now I need to know how to create global variables using the C API. I have this
1
2
3
4
5
6
7
void LUA_setglobalval(lua_State* L, const char* var, int val)
{
	lua_getglobal(L, var);
	if ( !lua_isnumber(L, -1) )
		lua_setfield(L, LUA_GLOBALSINDEX, var);
	lua_pushnumber(L, val);
}
Would that work properly?

old Re: Lua Scripts/Questions/Help

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
addhook("minute","addcredits")
function addcredits()
     for i=1,32 do
          if (player(i,"exists")) and (hacker[i]==1) then
               credits[i]=credits[i]+15
          end
     end
end
how do i make instead "if player exists" to "if player lvl[id] 5 or bigger ?

-------------------------------------------------------

can anybody make something like
admins = {15476,1,and so on}
and only admins can acess

1
2
3
4
5
6
7
8
9
10
if button==6 then--WTF? Admin Commands = buy credits?
menu(id,"Admin Panel,5 Credits|1000$,10 Credits|2000$,15 Credits|2750$,20 Credits|3500$,50 Credits|9000$,100 Credits|15000$,200 Credits|1 Mega Point")
end

if button==7 then--WTF? Music = buy credits?
menu(id,"Songs,Under Development (picking songs),10 Credits|2000$,15 Credits|2750$,20 Credits|3500$,50 Credits|9000$,100 Credits|15000$,200 Credits|1 Mega Point")
end
end

end

dont mind this credit thingy cause so far me and my clan leader are picking what should be in. I just need that only if player USGN = that and that, then he can enter menu with that button, else it will say "sorry you are not Admin". Thank you for your help.

old Re: Lua Scripts/Questions/Help

Yasday
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
adminList = {16138,16138}

function isAdmin(id,tbl)
if not tbl then tbl = adminList end
for i,v in ipairs(tbl) do
if player(id,"usgn") == v then
return true
end
end
return false
end

--use

if isAdmin(id) then
--code
end

old Question

sixpack
User Off Offline

Quote
Hello everyone!
Can someone help me on how to use IO to create/read/write and everything else I can do with files.
Give me the way to do it, explain it and some sample code to look.

old Re: Lua Scripts/Questions/Help

Jake-rus
User Off Offline

Quote
WHAT IS THAT ???

1
2
3
4
5
6
7
LUA ERROR (ai_update_living): bots/includes/collect.lua:16: attempt to call glob
al 'item' (a table value)
Freezing bots to stop Lua error msg flood! Use 'bot_freeze 0' to unfreeze bots!

LUA ERROR (ai_update_living): bots/includes/general.lua:63: attempt to perform a
rithmetic on field '?' (a nil value)
Freezing bots to stop Lua error msg flood! Use 'bot_freeze 0' to unfreeze bots!

old Re: Lua Scripts/Questions/Help

Vetle
BANNED Off Offline

Quote
Can someone make for me when player only has mercedes.png picture he can buy
mercedes_spoiler.png
thank u

heres the script

Quote
addhook("use","c1")
function c1(id,event,data,x,y)
if(x==77) and (y==19) then
menu(id,"Mercedes shop,Mercedes|100$")
end
end

addhook ("menu","buycar1")
function buycar1(id,menu,sel)

if (menu=="Mercedes shop") then
if (sel==1 and player(id,"money")>99) then
parse ("setmoney "..id.." "..(player(id,"money")-100))
parse("speedmod "..id.." 20")
freeimage(id)
id1=image("gfx/nfsmodu2/mercedes.png",1,1,200+id)
imagescale(id1,1,1)
imageblend(id1,0)
imagealpha(id1,1.0)
if (player(id,"team") == 2) then
imagecolor(id1,255,255,255)

elseif (player(id,"team") == 1) then
imagecolor(id1,0,0,0)
end
     end
end
end

old Re: Lua Scripts/Questions/Help

sixpack
User Off Offline

Quote
Cena has written
Can someone make for me when player only has mercedes.png picture he can buy
mercedes_spoiler.png
thank u

heres the script

Quote
hasmerc = {}
addhook("use","c1")
function c1(id,event,data,x,y)
if(x==77) and (y==19) then
menu(id,"Mercedes shop,Mercedes|100$")
end
end
addhook("join", "joe")
function joe(id)
hasmerc[id] = 0
end
addhook ("menu","buycar1")
function buycar1(id,menu,sel)

if (menu=="Mercedes shop") then
if (sel==1 and player(id,"money")>99) then
parse ("setmoney "..id.." "..(player(id,"money")-100))
parse("speedmod "..id.." 20")
hasmerc[id] = 1
freeimage(id)
id1=image("gfx/nfsmodu2/mercedes.png",1,1,200+id)
imagescale(id1,1,1)
imageblend(id1,0)
imagealpha(id1,1.0)
if (player(id,"team") == 2) then
imagecolor(id1,255,255,255)

elseif (player(id,"team") == 1) then
imagecolor(id1,0,0,0)
end
     end
end
end

Add the script above (I modified yours) and then if you want to check if someone has a mercendes, use:
if(hasmerc[id]==1) then
--code
end

old Tibia

Alex_Aaa789
User Off Offline

Quote
can make tibia status bar shows MP, but can't make MP perform arithmetic (+-MP)

1
PLAYERS[id].tmp.mp = PLAYERS[id].tmp.mp+mp




Dantes Inferno has written
Can someone help me im trying to make the bullets to explode when the hit something


Example: USP
1
2
3
4
5
6
7
8
9
addhook("hit","gun")
function gun(id, source, weapon, hpdmg, apdmg)
if (weapon == 1) then
local x, y
x = player(id, "x")
y = player(id, "y")
      parse("explosion "..x.." "..y.." <size> <dmg> "..id)
end
end

old Re: Lua Scripts/Questions/Help

JONY
User Off Offline

Quote
RyceR has written
how to make it?:
When i shoot from five-seven (to wall or to player) there is explosion, example:


Dantes Inferno has written
Can someone help me im trying to make the bullets to explode when the hit something


hm... that's how to make explosions on the walls. For the players it's harder, if you want, you can PM me and we'll talk about it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("attack","makeexplosion",2)
function makeexplosion(id)
	if (player(id,"weapontype")==6) then
		local k=1
		local x=false
		while not (tile(math.cos(math.rad(player(id,"rot")-90))*k + (player(id,"x"))/32,math.sin(math.rad(player(id,"rot")-90))*k + (player(id,"y"))/32,"wall")) and (not x) do
			k=k+1
		
			--[[for i=1, #player(0,"table") do
				if ((player(i,"x")) == ((math.cos(math.rad(player(id,"rot")-90))*32*k+(player(id,"x"))))) or ((player(i,"y")) == ((math.sin(math.rad(player(id,"rot")-90))*32*k + (player(id,"y")))))   then
					x = true
				end
			end]]
					
			if (k>500) then --just in case check
				break
			end
		end
		parse("explosion "..(math.cos(math.rad(player(id,"rot")-90))*32*k+(player(id,"x"))).." "..(math.sin(math.rad(player(id,"rot")-90))*32*k + (player(id,"y"))).." 30 1000 "..id)
		
		--msg(k)
	end
end
==========================================
Jake-rus has written
WHAT IS THAT ???

1
2
3
4
5
6
7
LUA ERROR (ai_update_living): bots/includes/collect.lua:16: attempt to call glob
al 'item' (a table value)
Freezing bots to stop Lua error msg flood! Use 'bot_freeze 0' to unfreeze bots!

LUA ERROR (ai_update_living): bots/includes/general.lua:63: attempt to perform a
rithmetic on field '?' (a nil value)
Freezing bots to stop Lua error msg flood! Use 'bot_freeze 0' to unfreeze bots!


These are errors show the code...

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
@Jony and Jake-Rus,
Those errors are completely normal.
The problem lies in the "primitive" bots (they use lua).
When you use cs2d cmd luareset they generate an error:
the one you described.(It cancels out the bot's lua scripts) Let's see if DC decides to make cs2d cmd luareset not affect the bots scripts.

old Re: Lua Scripts/Questions/Help

JONY
User Off Offline

Quote
Cena has written
Someone make for me when i goto tile x11 y33
i get 16000$

1
2
3
4
5
6
addhook("movetile","get16000")
function get16000(id,x,y)
	if x==11 and y==33 then
		parse("setmoney "..id.." 16000")
	end
end

old Re: Lua Scripts/Questions/Help

Jynxxx
User Off Offline

Quote
it has an error can some one help me

attempt to call global 'rp_ct' (a table value)

1
2
3
4
5
6
addhook("hit","_hit")
function _hit()
       if (rp_ct()==true) then
	return 1
	end
end

old Re: Lua Scripts/Questions/Help

DannyDeth
User Off Offline

Quote
Hi all, I just wantd to ask a small question:
What is the appropriate command to draw an image to the screen at certain coordinates?
Thanks ~DannyDeth.
To the start Previous 1 2328 329 330338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview