i have a question guys.
i tried adding new object in CPlayer class by using new slot operator before instance is created(before onPlayerJoin function is called) but i can't change its value other then the value i used while creating it. so this is what i did
function ScriptLoad()
{
CPlayer.Kills<-0;
// same result with rawset
}
#now when the player joins the instance is created this object is auto added to the player instance but i can't change it ( some how its read-only):(.
function onPlayerJoin(player)
{
player.Kills = 10;
}
but if i use my command "kills" it still shows 0 kills
function onPlayerCommand(player,CMD,text)
{
local cmd = CMD.tolower();
if (cmd == "kills") PrivMessage(player,"Your Kills are "+player.Kills);
}
just wondering if there was any way to change their values.
Entity objects like Players are managed by an underlying binding library, Sqrat, which allows the creation of C++ objects that can be used in a Squirrel virtual machine. Between that and the fact that Players are essentially C++ classes bound to Squirrel, I would say that adding a slot to a Sqrat-bound class is undefined behavior, and I can't really support it.
I can try looking into it further once my computer is back up and running, but for now that's all I can really say.
ok thankx so i guess things don't work the way you plane.I thought of getting ride of that array.I will just wait then until you further investigate.
til then topic locked and solved
First of all, let's create a custom 'CPlayer':
class customClass
{
Player = null;
Kills = 0;
Deaths = 0;
constructor( player )
{
Player = player;
}
}
onScriptLoad callback:
customClassArray <- array( GetMaxPlayers(), null );
onPlayerJoin callback:
customClassArray[ player.ID ] = customClass( player );
onPlayerPart callback:
customClassArray[ player.ID ] = null;
then let's add a function to the existing CPlayer class that returns an instance:
function CPlayer::MyStuff()
{
return ::customClassArray[ ID ];
}
When you finally added them all to your script, you can use player.MyStuff().Kills variable etc. :)
It's a safe workaround imho.
Thankx Gudio this worked the way i wanted it to work.
Brilliant Solution i must say :).
Topic Locked ;D