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 2250 251 252338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Starkkz
Moderator Off Offline

Quote
FaStDiE has written
I TESTED THIS! dont edit hooks and functions name cuz it result ERROR attempt to call nil value DONT EDIT


Quote
addhook("attack","hamthrow")
function hamthrow(id)
if (player(id,"weapontype") == 86) then
parse("sethealth "..id.." "..player(id,"health")+math.random(10,20))
msg2(source,"You have eaten a hamburger!")
return 1
end
end

addhook("drop","hamdrop")
function hamdrop(id,iid,type,ain,a,mode,x,y)
if type==86 then
return 1
end
return 0
end

addhook("say","getham")
function getham(p,txt,weapon)
     if (txt=="!give_ham") then
          parse("equip "..p.." 86")
          return 1
     end
end


There i show your errors

old Re: Lua Scripts/Questions/Help

murilog
User Off Offline

Quote
hi all i want one script like this : cts say !infoct <id> , and player go to jail and spawn on jail , if txt !free <id> the player is free thx , the jail Y : 100 X :100

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
Thanks Flacko you are great at Lua.

edit
I am using Dev and it won't work
Here is my source
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
#include <windows.h>
#include <dirent.h>
#include <Lua.hpp>
using namespace std;
#define loadjunk (fld)      \
{                           \
        if(!readdir(folder))\
        {                   \
                close(folder)\
                return 0;    \
        }                      \
}
#define LUA_INT lua_tointger
#define LUA_BOOL lua_toboolean
#define LUA_STR lua_tostring
int my_lua_readfolder(lua_State* L)
{
        const char* path = luaL_checkstring(L,1);
        DIR* folder = opendir(path);
        if(!folder){return 0;}
        
        strct dirent* cfile;
        //Junk
        loadjunk(folder); //. (Current dir)
        loadjunk(folder); //.. (Parent dir)
        
        lua_newtable(L);//This is the table (t)
        for (int indx = 1; cfile = readdir(folder); indx++)
        {
                lua_pushnumber(L,indx); //This is below the top (k)
                lua_pushstring(L,cfile->d_name);//This is at the top of the stack (v)
                lua_settable(L, -3); // t[k]=v
        }
        
        closedir(folder);
        return 1;
}

__declspec(dllexport) int init(lua_State* L)
{
        lua_register(L, 'read_dir', my_lua_readfolder);
        return 0;
}

Info
lua.h + the other three files -> C:\Dev-Cpp\include\Lua\
lua51.dll -> C:\Dev-Cpp\bin\ ; C:\Windows\System32
edited 3×, last 04.09.10 05:03:57 am

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Make sure you've placed liblua.a in Dev/lib.
Also, modify the lua.hpp file you've created in Dev/include to match Lua's headers in your Dev/include/lua folder if needed.
What error is the compiler throwing at you?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
It seems like it's a problem with the compiler itself. Try to reinstall wxDev-C++ with MingW or use the old Dev-C++ which works fine too.

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
The error list has decreased. The errors are mostly about undefined identifiers because it says lib.h does not exist. Where can I find lib.h?

edit
hm sorry it is supposed to be lualib.h.

[b]
could you help me fix this 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
#include <windows.h>
#include <dirent.h>
#include <Lua.hpp>
using namespace std;
#define loadjunk (fld)      \
{                           \
        if(!readdir(folder))\
        {                   \
                close(folder)\
                return 0;    \
        }                      \
}
#define LUA_INT lua_tointger
#define LUA_BOOL lua_toboolean
#define LUA_STR lua_tostring
int my_lua_readfolder(lua_State* L)
{
        const char* path = luaL_checkstring(L,1);
        DIR* folder = opendir(path);
        if(!folder){return 0;}
        
        strct dirent* cfile;
        //Junk
        loadjunk(folder); //. (Current dir)
        loadjunk(folder); //.. (Parent dir)
        
        lua_newtable(L);//This is the table (t)
        for (int indx = 1; cfile = readdir(folder); indx++)
        {
                lua_pushnumber(L,indx); //This is below the top (k)
                lua_pushstring(L,cfile->d_name);//This is at the top of the stack (v)
                lua_settable(L, -3); // t[k]=v
        }
        
        closedir(folder);
        return 1;
}

__declspec(dllexport) int init(lua_State* L)
{
        lua_register(L, 'read_dir', my_lua_readfolder);
        return 0;
}

Here is a screen with the errors
http://a.imageshack.us/img832/1686/capturelj.png

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
I wanted to do something simpler so I wanted to dofile a file.
My errors:
[Linker error] undifined reference to 'luaL_loadfile'
[Linker error] undefined reference to 'lua_pcall'
ld returned 1 exit status

Source:
1
2
3
4
5
6
7
8
#include <Lua.hpp>
using namespace std;

int main() {
    lua_State* L;
    luaL_dofile(L, "test.lua");
    return 0;
}

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Prob #1: This could be your error
IMG:https://img833.imageshack.us/img833/7028/asdap.png


@Prob #2: Go to the project options menu and in the parameters tab write -llua in the linker parameters

old Re: Lua Scripts/Questions/Help

FASTDIE
User Off Offline

Quote
hey its me again i need help with this it have error "1 bad argument" whats wrong ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
team = (player(id,"team"))

name = (player(id,"name"))

addhook("say","adminsay")
function adminsay(id,txt)
     if player(id,"usgn")==15587 then
          if t=="rank" then
               return 0
          else
               parse("msg ©110110255["..team.."]"..name.."(V.I.P): "..txt)
               return 1
          end

     if player(id,"usgn")==16304 then
          if t=="rank" then
               return 0
          else
               parse("msg ©110110255["..team.."]"..name.."(Admin): "..txt)
               return 1
          end
     end
end
end

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
change
1
2
3
team = (player(id,"team"))

name = (player(id,"name"))

to

1
2
3
team = player(id,"team")

name = player(id,"name")

old Re: Lua Scripts/Questions/Help

Snake_Eater
User Off Offline

Quote
FaStDie has written
hey its me again i need help with this it have error "1 bad argument" whats wrong ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
team = (player(id,"team"))

name = (player(id,"name"))

addhook("say","adminsay")
function adminsay(id,txt)
if player(id,"usgn")==15587 then
if t=="rank" then
return 0
else
parse("msg ©110110255["..team.."]"..name.."(V.I.P): "..txt)
return 1
end

if player(id,"usgn")==16304 then
if t=="rank" then
return 0
else
parse("msg ©110110255["..team.."]"..name.."(Admin): "..txt)
return 1
end
end
end
end


@HaRe I think that isn't the problem.....
try this.......
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
addhook("say","adminsay")
function adminsay(id,txt)
if player(id,"usgn")==15587 then
if t=="rank" then
return 0
else
team = (player(id,"team"))
name = (player(id,"name"))
msg ("©110110255["..team.."]"..name.."(V.I.P): "..txt)--compare it with your version of script
return 1
end

if player(id,"usgn")==16304 then
if t=="rank" then
return 0
else
team = (player(id,"team"))
name = (player(id,"name"))
msg ("©110110255["..team.."]"..name.."(Admin): "..txt)--compare it with your version of script
return 1
end
end
end
end

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
Flacko has written
@Prob #2: Go to the project options menu and in the parameters tab write -llua in the linker parameters

Well just my luck. I can't open project options.

edit
I started a new project and I can.

edit
It still won't work. Could you just give me the compiled source? Also do you know where I could learn how to implement Lua in C++? I added the source files to includes/Lua and it won't work.
edited 1×, last 04.09.10 07:12:26 pm

old Re: Lua Scripts/Questions/Help

TDShuft
User Off Offline

Quote
Spoiler >


help ?
To the start Previous 1 2250 251 252338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview