I was wondering how would this look if converted into SP script.
Syntax: Select all
import usermsg
def player_activate(event_var):
usermsg.echo(event_var['userid'], "Hello!")
Thanks.
Syntax: Select all
import usermsg
def player_activate(event_var):
usermsg.echo(event_var['userid'], "Hello!")
Syntax: Select all
from Source import Player
from Source import Engine
from events.decorator import Event
from messages import Echo
@Event
def player_activate(GameEvent):
userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)
Echo(index, 'Hello!')
satoon101 wrote:Yes, agreed, we do need to add a syntax button. There are other issues with the syntax blocks that need investigated as well. For now, though, to use Python syntax blocks, just use [python][/python]
Satoon
satoon101 wrote:Strange that you used PHP syntax highlighting instead of Python, but in SP, it would look like:[python]from Source import Player
from Source import Engine
from events.decorator import Event
from messages import Echo
@Event
def player_activate(GameEvent):
userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)
Echo(userid, 'Hello!')[/python]Satoon
satoon101 wrote:Pretty much "nothing" in the engine actually uses a player's userid, so the API will be designed as such to utilize the proper input.
satoon101 wrote:This plugin will not be designed to do ultra hand-holding like ES did. Some things will become easier, others will be a little harder, plus we plan to add extended functionality that was never available in ES.
The only thing "harder" about the above script than the ES version is that you have to get the player's index instead of simply passing the userid. And, as I said, the reason for this is:
Satoon
Syntax: Select all
userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)
Mahi wrote:[python] userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)[/python]This part really stresses me, if we're actually never going to use userid or player, why not just have a single function GetIndex('userid')? Even if it was stupid and unlogical to have such, and even if SP is not meant to be "easy to use", that would just make things so much easier for everyone, and it would already be stupid NOT TO do it like that? Ofc. anyone could define it by themselves, to do all those 3 lines in one function, but it'd be simply easier if it was built-in.
You can definitely use "player" for lots of things. It is just the "userid" that you would never "use". They use the userid to make sure there is a totally unique identifier to each player that joins the server. Indexes only go from 1 to max players, and get reused when players disconnect/join. So, the userid is good for something, but is never truly used by the engine itself.Mahi wrote:This part really stresses me, if we're actually never going to use userid or player, why not just have a single function GetIndex('userid')? Even if it was stupid and unlogical to have such, and even if SP is not meant to be "easy to use", that would just make things so much easier for everyone, and it would already be stupid NOT TO do it like that? Ofc. anyone could define it by themselves, to do all those 3 lines in one function, but it'd be simply easier if it was built-in.Syntax: Select all
userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)
satoon101 wrote:Indexes only go from 1 to max players, and get reused when players disconnect/join.
Spiked wrote:Unless that changed after OB, the server actually counts userids well into the hundreds and apparently never reused them. So userid was unique to the player join event. Again, pretty useless other than a faster 'unique' id than asking the client for the steamid (I'm assuming the server doesn't hold onto that)
Could someone please expand on exactly what is returned by each of the 3 commands above?
Obviously, we're all familiar with the userid.
Is the player edict a pointer to the instance of the player class?
Index of Edict sounds like something very similar to userid, or more similar to what satoon described (reused ids between 1 and max players). I'm guessing an array of player instances is stored by the server and the index refers to the order in that array?
Syntax: Select all
@Event
player_spawn(GameEvent):
# Returns a userid from the game event (player spawn in this case)
userid = GameEvent.GetInt('userid')
# Returns the Edict
player = Player.EdictOfUserid(userid)
# Returns the player's index from the Edict
index = Engine.IndexOfEdict(player)
Return to “Plugin Development Support”
Users browsing this forum: No registered users and 62 guests