Casting
Some object types support casting, some require manual, and some is done automatically.
As of writing only IPostal3Script@
and CBaseEntity@
are capable of some sort of casting.
Manual Casting
Example(s)
// From CBaseEntity@ to CP3Weapon@
CBaseEntity@ pointer;
CP3Weapon@ pWpn = cast<CP3Weapon@>(pointer);
// From IPostal3Script@ to MyClass@
class MyClass : IPostal3Script
{
// Content here...
...
}
MyClass@ ToMyClass(CP3SObj@ ptr)
{
IPostal3Script@ class = GetScriptObj("MyClass", ptr);
if (@class == null)
return null;
return cast<MyClass@>(class);
}
// Rough example of how this would look like...
void SomeFunction()
{
CP3SObj@ self;
if (@self == null)
return;
MyClass@ class = ToMyClass(self);
if (@class == null)
return;
...
}
From | To | Note(s) |
---|---|---|
IPostal3Script@ | [class]@ | Script module, class |
CBaseEntity@ | CParticleSystem@ | n/a |
CBaseEntity@ | CP3SObj@ | n/a |
CBaseEntity@ | CP3Weapon@ | n/a |
CBaseEntity@ | CP3Player@ | n/a |
CBaseEntity@ | CAI_Hint@ | n/a |
Auto/Implicit Casting
The objects below also support manual casting, but normally unnecessary.
Example(s)
// CBaseEntity@ to EHANDLE and vice versa
EHANDLE handle;
CBaseEntity@ pointer = handle;
EHANDLE newHandle = pointer;
// CP3Player@ to CBaseEntity@
CP3Player@ pPlayer;
CBaseEntity@ pEnt = pPlayer;
// CP3Weapon@ to CBaseEntity@
CP3Weapon@ wep;
CBaseEntity@ ent = wep;
From | To | Note(s) |
---|---|---|
string_t | string | n/a |
string | string_t | n/a |
EHANDLE | CBaseEntity@ | n/a |
CBaseEntity@ | EHANDLE | n/a |
CParticleSystem@ | CBaseEntity@ | n/a |
CP3Weapon@ | CBaseEntity@ | n/a |
CP3Player@ | CBaseEntity@ | n/a |
CAI_Hint@ | CBaseEntity@ | n/a |