Page 1 of 2

Retreiving 'CBasePlayer.m_iFOV' ?

Posted: Thu Aug 23, 2012 5:32 pm
by Tuck
Could some one show me an example of how to retrieve a players 'CBasePlayer.m_iFOV', 'CBasePlayer.localdata.m_Local.m_bDucked' and CBasePlayer.m_fFlags

Thanks, in advance

Posted: Thu Aug 23, 2012 7:34 pm
by Tuck
Basicly what i want to retrieve about a player is, is he zoomed in on sniper, is he crouching or is he in the air

on css i used these to retrieve it :/

Posted: Fri Aug 24, 2012 12:18 am
by BackRaw
Tuck wrote:Basicly what i want to retrieve about a player is, is he zoomed in on sniper, is he crouching or is he in the air

on css i used these to retrieve it :/


I guess your-name-here or some other C++ writer teamed up with him will be creating a playerlib-like library when all the other, more neccessary things are done. So, be patient =)

Posted: Fri Aug 24, 2012 3:19 am
by Tuck
I don't want to retrieve it from the player class i want it to retrieve it from the player entity ?

Posted: Fri Aug 24, 2012 5:57 am
by Omega_K2
The player entitiy is an instance of the player class (which inherits from other classes such as CBaseEntitiy).
But that functionality is not in SP yet afaik.

Posted: Sat Aug 25, 2012 5:47 am
by Monday
Omega_K2 wrote:The player entitiy is an instance of the player class (which inherits from other classes such as CBaseEntitiy).
But that functionality is not in SP yet afaik.


Its high up on our list of things to work on, but you are correct. We do not currently have this functionality yet!

Posted: Sun Aug 26, 2012 3:30 pm
by ashbash1987
Getting entity props is now in the latest code commit for SP. I don't know when the next full build will be available (or you could build it yourself if you are able to do so), but when it is available you'll be able to do something like this:

Syntax: Select all

from Source import Entity
from Source import Player
from events.decorator import Event

@Event
def round_start(GameEvent):
for player in Player.Players():
entity = Player.EdictOfPlayer(player)
entity.SetPropInt("CBasePlayer.m_iHealth", 1)

The example above will set all player's health values to 1 at the start of a round.

The methods that are available on the edict instance are are follows:

Get methods
  • GetPropInt(propName)
  • GetPropFloat(propName)
  • GetPropVector(propName)
  • GetPropVectorXY(propName)
  • GetPropString(propName)
  • GetPropLong(propName)

Set Methods
  • SetPropInt(propName, propValue)
  • SetPropFloat(propName, propValue)
  • SetPropVector(propName, propValue)
  • SetPropVectorXY(propName, propValue)
  • SetPropString(propName, propValue)
  • SetPropLong(propName, propValue)
The methods will check to ensure that you are getting/setting the correct type, so you shouldn't be able to do SetPropFloat("CBasePlayer.m_iHealth") for example

Posted: Sun Aug 26, 2012 4:16 pm
by Omega_K2
Awesome :D

I think that is one of the features I've been desperatly waiting for :P

Posted: Sun Aug 26, 2012 4:55 pm
by your-name-here
Omega_K2 wrote:Awesome :D

I think that is one of the features I've been desperatly waiting for :P


I am going to release a build with this very shortly.

Posted: Thu Aug 30, 2012 8:58 pm
by Mahi
Looks great, but just one question. Why don't you merge all (or most, atleast int, float and long) into one method, instead of multiple same methods with just different type? Since C++ does support function overloading, and Python doesn't even have to know anything about it.

Posted: Thu Aug 30, 2012 9:17 pm
by your-name-here
Mahi wrote:Looks great, but just one question. Why don't you merge all (or most, atleast int, float and long) into one method, instead of multiple same methods with just different type? Since C++ does support function overloading, and Python doesn't even have to know anything about it.


I flip the question onto you, why should we merge it all into one method? Having split methods makes it crystal clear what you're doing. Remember, this isn't Eventscripts. The goal of Source-Python is to provide one-to-one translation of C++ to Python. When you're this close to the engine, you're going to have to deal with type. Also, wrapping overloaded functions in boost (as far as I know) requires a fair amount of extra work.

Posted: Thu Aug 30, 2012 9:21 pm
by Monday
Mahi wrote:Looks great, but just one question. Why don't you merge all (or most, atleast int, float and long) into one method, instead of multiple same methods with just different type? Since C++ does support function overloading, and Python doesn't even have to know anything about it.


That is because of how we expose the engine with boost python. Its really not that big of a deal is it?

Posted: Fri Aug 31, 2012 4:19 am
by Mahi
Right, makes sense.
your-name-here wrote:The goal of Source-Python is to provide one-to-one translation of C++ to Python.

I should keep this in mind.

And it's not a big deal, was just asking out of curiosity :) I always hated es anyways.

Posted: Sun Sep 02, 2012 7:06 am
by Tuck
ES:

Syntax: Select all

(es.getplayerprop(a['id'], 'CBasePlayer.m_fFlags') & 1) == 0


What would be the equilivent ?

SP??:

Syntax: Select all

entity = Player.EdictOfPlayer(<PLAYER>)
onground = ((entity.GetPropLong('CBasePlayer.m_fFlags') & 1) == 0)

Posted: Sun Sep 02, 2012 7:12 am
by Monday
using EasyPlayer it would be:

Syntax: Select all

SomeGuy = EasyPlayer(userid=a['id'])
SomeGuy.GetPropInt('CBasePlayer.m_fFlags')

Posted: Sun Sep 02, 2012 8:01 am
by Tuck
i dont see the difference of using "EasyPlayer or EdictofPlayer" ?

i was asking if it would return the same as it would in es since idk if es gets it as a string to then look into the flags and see if player is in the air or on ground ? :)

Posted: Sun Sep 02, 2012 8:15 am
by Monday
Tuck wrote:i dont see the difference of using "EasyPlayer or EdictofPlayer" ?

i was asking if it would return the same as it would in es since idk if es gets it as a string to then look into the flags and see if player is in the air or on ground ? :)


Have you tried testing?

Posted: Sun Sep 02, 2012 8:25 am
by Tuck
I'm not really that much into the player flags why i was asking, I haven't messed around with python's & but the code example i wrote should work ?

Posted: Sun Sep 02, 2012 8:44 am
by Monday
Tuck wrote:I'm not really that much into the player flags why i was asking, I haven't messed around with python's & but the code example i wrote should work ?


I am not going to test your code for you. Please test your own code before posting here. Forum Rules

If your code has a problem, then come back... But please stop asking if your code will work or not.

Posted: Sun Sep 02, 2012 9:18 am
by Tuck
Monday wrote:I am not going to test your code for you. Please test your own code before posting here. Forum Rules

If your code has a problem, then come back... But please stop asking if your code will work or not.


was simply asking if es returned string, long or int but fine if u dont know it i'll have to install es and check... (sorry to bother you..)