Does anyone know how to get the Player object passed to the intitial spawn hook in binary module?
I have hooked the hook with
[code]
ILuaObject* hookModule =Lua()->GetGlobal("hook");
ILuaObject* addFunction = hookModule->GetMember("Add");
addFunction->Push();
Lua()->Push("PlayerSpawn");
Lua()->Push("DeRP:PlayerInitialSpawn");
Lua()->Push(DeRP_Player_FirstSpawn);
Lua()->Call(3);
addFunction->UnReference();
hookModule->UnReference();
[/code]
but this does not seem to work
[code]
LUA_FUNCTION(DeRP_Player_FirstSpawn)
{
isr=new DeRPPlayerInitSpawnRequest(GetDatabase(),Lua(),finishedspawn);
ILuaObject* ply=Lua()->GetObject(1);
ILuaObject* SteamID=ply->GetMember("SteamID");
Lua()->Push(SteamID);
Lua()->Call(0,1);
const char* steam_id=Lua()->GetReturn(0)->GetString();
Lua()->Msg("[DeRP]Checking that this is steam ID: %s",steam_id);
finishedspawn();
return 0;
}
[/code]
It errors out saying calling a nill value, then the message says [DeRP]Checking that this is steam ID: nill
You need to convert it to a CBaseHandle and push it to Lua. All you need to know to do that is right here: [URL]http://code.google.com/p/chrisaster/source/browse/trunk/gmsv_luamd5/gmsv_luamd5/gmsv_luamd5.cpp[/URL] . Remember to include that sigscan for IEntityList else you will error.
[QUOTE=Gbps;25198000]You need to convert it to a CBaseHandle and push it to Lua. All you need to know to do that is right here: [URL]http://code.google.com/p/chrisaster/source/browse/trunk/gmsv_luamd5/gmsv_luamd5/gmsv_luamd5.cpp[/URL] . Remember to include that sigscan for IEntityList else you will error.[/QUOTE]
This reminds me why I sometimes hate C++, I can not see how the two things match.
[editline]04:56PM[/editline]
Oh wait, now I think I see it, greeeeeeat, why can;t this be simple?
[editline]05:02PM[/editline]
Whats with the sig scanning for entity list? it is not used anywhere else even o.o
That's because your module wasn't compiled with Garry's Mod at the start. You don't have direct access to the entity list unless you use some other method to find it.
But the module you show does not even use the entity list once it has found it
It's used indirectly in the SDK.
well that failed ,
[code]
Warning 1 warning C4800: 'CBaseHandle *' : forcing value to bool 'true' or 'false' (performance warning) C:\DeRP\gmsv_DeRP\gmsv_DeRP\DeRPPlayer.cpp 21 1 gmsv_DeRP
[/code]
A warning doesn't mean a failure, it just points out a possible flaw. In this case you should compare the handle to 0 or NULL instead of forcing it into a boolean.
also when I run the thing? I get this error :
[code]
kat.swales suicided!
bad argument #1 to '?' (Entity expected, got boolean)
[DeRP]Checking that this is steam ID: (null)
[/code]
the line it warned about?
[code]
Lua()->Push(ply);
[/code]
[editline]06:52PM[/editline]
the function is currently now:
[code]
LUA_FUNCTION(DeRP_Player_FirstSpawn)
{
//Lua()->CheckType(1,GLua::TYPE_TABLE);
isr=new DeRPPlayerInitSpawnRequest(GetDatabase(),Lua(),finishedspawn);
CBaseHandle* ply=(CBaseHandle *)Lua()->GetObject(1);
if(!ply)
Lua()->Error("This did not worl");
ILuaObject* SteamIDIndex=Lua()->GetMetaTable("Player", GLua::TYPE_ENTITY)->GetMember("SteamID");
Lua()->Push(SteamIDIndex);
Lua()->Push(ply);
Lua()->Call(1,1);
const char* steam_id=Lua()->GetReturn(0)->GetString();
Lua()->Msg("[DeRP]Checking that this is steam ID: %s",steam_id);
finishedspawn();
return 0;
}
[/code]
You cant push entities, i havent found a way to properly do it yet atleast, its forcing it to a bolean becuse thats the only overload that works
Yeah I can see that, just wondering why Gbps said to do that then.as looking at the code, no way it would work
seems this however, DOES work :
[code]
LUA_FUNCTION(DeRP_Player_FirstSpawn)
{
//Lua()->CheckType(1,GLua::TYPE_TABLE);
isr=new DeRPPlayerInitSpawnRequest(GetDatabase(),Lua(),finishedspawn);
ILuaObject* ply=Lua()->GetObject(1);
if(!ply)
Lua()->Error("This did not work");
ILuaObject* SteamIDIndex=Lua()->GetMetaTable("Player", GLua::TYPE_ENTITY)->GetMember("SteamID");
Lua()->Push(SteamIDIndex);
Lua()->Push(ply);
Lua()->Call(1,1);
const char* steam_id=Lua()->GetReturn(0)->GetString();
Lua()->Msg("[DeRP]Checking that this is steam ID: %s",steam_id);
finishedspawn();
return 0;
}
[/code]
without all that sigscanning nonsence.
Pass the entity index rather than the SteamID. More efficient.
Edit: nevermind, read the code wrong.
It does, but it's not "correct" I guess.
And sigscanning is?:raise:
[QUOTE=Gbps;25206222]It does, but it's not "correct" I guess.[/QUOTE]
not correct in what way? rather then what you told me, that does not even come close to working thanks to the fact you can NOT push a CBaseHandle onto Lua.
[editline]10:47PM[/editline]
[QUOTE=ralle105;25206512]And sigscanning is?:raise:[/QUOTE]
Gbps was claiming would need to use some sigscanning, which is basically searching memory for the address of a function.
[QUOTE=nekosune;25206526]
Gbps was claiming would need to use some sigscanning, which is basically searching memory for the address of a function.[/QUOTE]
Let me rephrase that:
And sigscanning is the "correct" way?
[QUOTE=nekosune;25206526]not correct in what way? rather then what you told me, that does not even come close to working thanks to the fact you can NOT push a CBaseHandle onto Lua.
[editline]10:47PM[/editline]
Gbps was claiming would need to use some sigscanning, which is basically searching memory for the address of a function.[/QUOTE]
You push CBaseHandle* to Lua with the metatable GLua::TYPE_ENTITY. That's what an entity is.
[editline]04:57PM[/editline]
[QUOTE=ralle105;25206862]Let me rephrase that:
And sigscanning is the "correct" way?[/QUOTE]
The "correct" way is using the IBaseEntityList to use and give CBaseHandle to/from Lua.
the most convoluted way possible is not the correct way, note that this does it without any fuss, and bother with that, and I have found it in several releases in the release section, whereas I have not found the use of CBaseHandle, which none of the lua functions even accept at all (I can say that after just double checking by searching through the headers).
CBaseHandle is used to get CBaseEntity which is the most useful entity class in the Source engine.
And a fork is the most useful piece of cutlery, doesn't mean I would use it to drink soup with, in this instance, it is useless unless you are willing to go the long way round for what turned out to be a perfectly simple case of having to pass the received object to a function. No sig scanning or extra stuff needed, which brings down my dll down from 150kb back to 30kb.
[editline]12:40AM[/editline]
Turns out I had forgotten Lua treats objects as a self variable that is automatically (when using lua) passed in, pass it in manually using C++, and it all works fine
Signature scanning isn't necessary, it was more of an experiment/example. Technically it's the proper way, but considering you need to use hacky methods to achieve it, it's not really worth it.
Sorry, you need to Log In to post a reply to this thread.