Forum

> > CS2D > Scripts > What is bad :)
Forums overviewCS2D overview Scripts overviewLog in to reply

English What is bad :)

9 replies
To the start Previous 1 Next To the start

old What is bad :)

Evool
User Off Offline

Quote
Hello, latest I learn LUA, and i have problem in my first easy script, please help - what is wrong?

1
2
3
4
5
function usebutton(id,x,y)
	if (x==17) and (y==19) then
		mapchange("de_dust2")
	end
end

Of course i want to change map from button, the position of button is OK, mapname - also. Zero errors.
edited 1×, last 02.01.11 03:46:11 am

old Re: What is bad :)

Klin
User Off Offline

Quote
Try this one:
1
2
3
4
5
function usebutton(id,x,y)
	if((x/32==17) and (y/32==19)) then
		mapchange("de_dust2")
	end
end

Klin

old Re: What is bad :)

DC
Admin Off Offline

Quote
mapchange is no Lua command. mapchange is no CS2D command at all!

the command you want to use is a CS2D console command and it is called cs2d cmd changemap

you have to use the Lua command cs2d lua cmd parse to execute CS2D console commands in Lua

1
parse('changemap "de_dust2"')

old Re: What is bad :)

Evool
User Off Offline

Quote
OK, thanks all, in particular you, DC, but i dont understand why in sys/lua/info.txt is:

1
2
3
4
LIST OF AVAILABLE HOOKS:
[...]
mapchange(newmap)			on map change
-newmap: name of new map

ps.
Kel9290 has written
why u use lua, map editor has Func_GameAction > Load Map X


You're right, i forgot this... But something to learn must have
edited 1×, last 02.01.11 01:39:12 pm

old Re: What is bad :)

ohaz
User Off Offline

Quote
yeah, that's a HOOK!
You can write:
1
2
3
4
addhook("mapchange", "whatsnewmap")
function whatsnewmap(newmap)
	msg("New map is: "..newmap)
end

old Re: What is bad :)

Evool
User Off Offline

Quote
Ohh... Probaly confuse me hook's with functions
I thought that hooks can be given instead of functions

old Re: What is bad :)

Patasuss
User Off Offline

Quote
Put this at the top at your .lua file:
1
2
3
function mapchange(map)
	parse("changemap "..map)
end

then you can use the function in your script
1
mapchange("de_dust2")

Spoiler >

old Re: What is bad :)

J4x
User Off Offline

Quote
so this is the correct one
1
2
3
4
5
function usebutton(id,x,y)
     if (x==17) and (y==19) then
        parse("changemap "..de_dust2")
     end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview