Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dualnames on Wed 06/03/2019 03:30:36

Title: Character.GetAtScreenXY via plugin (SOLVED)
Post by: Dualnames on Wed 06/03/2019 03:30:36
I want to access this specific code inside a plugin code

Character.GetAtScreenXY(xx, yy)==cEgo

I've looked it up and I'm clueless on how to do that
Title: Re: Character.GetAtScreenXY via plugin
Post by: Dualnames on Wed 06/03/2019 06:46:29
Code (AGS) Select


int (*sfGetAtXY)(int,int);
sfGetAtXY = ((int(*)(int,int)) engine->GetScriptFunctionAddress("GetCharacterAt"));
int getID=sfGetAtXY(xx,yy);


Title: Re: Character.GetAtScreenXY via plugin (SOLVED)
Post by: Snarky on Wed 06/03/2019 07:06:04
Nice to know! Thanks for posting your solution. (lol at this topic being in Beginners'.)
Title: Re: Character.GetAtScreenXY via plugin (SOLVED)
Post by: Crimson Wizard on Wed 06/03/2019 08:37:03
"GetCharacterAt" is a deprecated function that may be removed from future versions of the engine.
"Character::GetAtScreenXY" returns a pointer to character object which you may use to access its properties either
1) directly by casting it to AGSCharacter from plugin api and reading its variables (not recommended because it's honestly unsafe and will be deprecated in ags4 also)
2) by using property getter "Character::get_ID" and passing previously received character pointer there.

There's another thing, GetScriptFunctionAddress is in truth "GetSymbolAddress", meaning you can get not only functions. Thus you may do engine->GetScriptFunctionAddress("player"), because "player" is a builtin global variable, and get player character's pointer, and then compare directly to the one you received from "Character::GetAtScreenXY".
If you already know player's ID somehow you may get player's pointer also by engine->GetCharacter(n).