Author Topic: Player/Vehicle Classes  (Read 3261 times)

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-74
    • View Profile
Player/Vehicle Classes
« on: April 05, 2012, 09:30:04 pm »
Hey, not sure how this works, but so far I think that its not possible.

I have a little knowledge of how classes work in Squirrel. I was wondering, because after reading over the section in the Squirrel 2 and 3 manual's, I am under the assumption that I won't be able to add more methods to a LU built class when running the server. I have a little example of how I was wanting to do it:

Lets say a player connects. His instance is created (for things like player.Pos). I was wondering, can I add more stuff to this instance? Like, if I wanted to preserve their password, use things like player.Password, and be able to read/write the string to it?

Also, I was wondering if it would be possible to add extra functions to it, like for a player instance to have like, player.SaveToDatabase(); or something.

Any support on this would be appreciated, thanks!
[GLT]WtF

SugarD

  • Asshat Gaming Founder
  • Tester
  • Sr. Member
  • ****
  • Posts: 820
  • Karma: +37/-75
  • STOP IN THE NAME OF THE COLESLAW!
    • View Profile
    • Clan Xperience
Re: Player/Vehicle Classes
« Reply #1 on: April 06, 2012, 02:00:55 am »
For the latter, I believe you could use one of the database plugins and save their information there to be referenced, but I'm not really a scripter, so don't rely on my statement too much for that. D:

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-74
    • View Profile
Re: Player/Vehicle Classes
« Reply #2 on: April 06, 2012, 02:13:05 am »
I use a database to store everything, however for database overload prevention purposes, I am using a temporary table solution at runtime to keep data, and saving it every so often or on certain events. I was just wondering if it were possible to use the player instances for this.

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Player/Vehicle Classes
« Reply #3 on: April 06, 2012, 01:54:11 pm »
Don't think you can. But not sure.

stormeus

  • No-Lifer
  • Developer
  • Full Member
  • *****
  • Posts: 112
  • Karma: +13/-2
    • View Profile
Re: Player/Vehicle Classes
« Reply #4 on: April 06, 2012, 03:03:14 pm »
Unlike a normal Squirrel class, the Player and Vehicle classes are not traditionally extensible (class herp extends derp) due to the way they are implemented. However, upon loading the scripts, you CAN create new slot instances in either class, and they will be accessible through any instance.

Code: (Squirrel) [Select]
function onPlayerJoin( pPlayerInst )
{
Player.Herp <- function() // Inserts into base class
{
::print( "LOLOLO" );
}

pPlayerInst.Herp(); // Player instance changed dynamically, function works
}

EDIT: Should probably add that you should be extending the classes in onScriptLoad (or onServerStart). Doing Player.NewSlot <- in onPlayerJoin isn't healthy.

EDIT 2: This is more kosher.
Code: (Squirrel) [Select]
function hook_Herp()             { ::print( "LOLOLO" );      }
function onScriptLoad()          { Player.Herp <- hook_Herp; }
function onPlayerJoin( pPlayer ) { pPlayer.Herp();           }
« Last Edit: April 06, 2012, 11:44:12 pm by stormeus »
Quote
Morphine says:
    them LU devs ranting about how LU doesn't have client pickups
    while us VC:MPers don't have client anything
    ;_;

Stormeus Argo says:
    we have client crashes though
    ohohohohoho

Morphine says:
    LU DOESN'T HAVE THAT

Stormeus Argo says:
    LU - 0
    VC:MP - 1

 

© Liberty Unleashed Team.