Page 1 of 2

Basic script help

Posted: Sun Aug 26, 2012 10:45 am
by Nomy
Hi guys,

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.

Posted: Sun Aug 26, 2012 11:58 am
by satoon101
Strange that you used PHP syntax highlighting instead of Python, but in SP, it would look like:

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!')
Satoon

Posted: Sun Aug 26, 2012 5:48 pm
by Nomy
Thanks Satoon :)

I'm sorry about the php bbcode. I couldn't find the python syntax bbcode icon on the bar, it would be awesome to have it show in quick reply box too :)

Posted: Sun Aug 26, 2012 6:04 pm
by satoon101
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

Posted: Sun Aug 26, 2012 6:05 pm
by Tuck
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


i just use syntax=py

Posted: Sun Aug 26, 2012 6:35 pm
by Nomy
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


Will do :)

Edit: I was not able to get the hello message. The script was loaded properly without any errors.

Posted: Mon Aug 27, 2012 8:48 pm
by Spiked
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



Confused by lines 9 and 10... you declare "player" and "index" but never use them... is there some magic here?

Posted: Mon Aug 27, 2012 8:55 pm
by satoon101
Ahh, oops, good catch. I do use "player" to get the index. I accidentally used "userid" in the Echo line, instead of the "index". Due to the fact that Recipient Filters use indexes, you need to pass either a player index, a list of player indexes, or a proper PlayerIter filter to the messaging system. 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.

Fixed code above.

Satoon

Posted: Tue Aug 28, 2012 6:22 am
by Nomy
Thanks it works now. :)
I think ESP was easier or is it only me? Maybe it will become easier as more stuff/libraries are added :)
I am liking this so far :)

Posted: Tue Aug 28, 2012 2:05 pm
by satoon101
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:
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.


Satoon

Posted: Tue Aug 28, 2012 3:43 pm
by Monday
Nomy wrote:Maybe it will become easier as more stuff/libraries are added :)

Somethings will become easier as libraries are added, however don't expect SP to be so easy a monkey could do it.

Posted: Tue Aug 28, 2012 7:50 pm
by Nomy
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

Aha! Thanks!

Posted: Wed Aug 29, 2012 9:13 pm
by tnarocks
is this the same Nomy thats part of Mani Admin?

Posted: Wed Aug 29, 2012 9:55 pm
by Mahi

Syntax: Select all

userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)
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.

Posted: Wed Aug 29, 2012 10:10 pm
by your-name-here
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.


Because GetIndex isn't inside IGameEvent as a function, nor would it be valid for all game events. We're providing a 1-1 translation of every C++ function to Python. It's 1-2 extra lines of code. We're not asking for the world from you, so I don't see why you are so stressed out over this.

Posted: Wed Aug 29, 2012 10:45 pm
by Omega_K2

Posted: Thu Aug 30, 2012 2:27 am
by satoon101
Mahi wrote:

Syntax: Select all

userid = GameEvent.GetInt('userid')
player = Player.EdictOfUserid(userid)
index = Engine.IndexOfEdict(player)
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.

GetIndexOfUserid will probably be included in future versions of SP. We are still very early in development, so some things that might seem "necessary" just haven't been implemented. We welcome all suggestions, but we will definitely give our opinions on whether we feel they are right/wrong for this plugin.

Satoon

Posted: Thu Aug 30, 2012 4:32 pm
by Spiked
satoon101 wrote:Indexes only go from 1 to max players, and get reused when players disconnect/join.


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?

Edit:
Wow, that's totally my bad. I read too fast and skipped a period in Satoon's post -.-
Leaving my post as-is in-case anyone does the same.

Posted: Thu Aug 30, 2012 5:12 pm
by Monday
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)


Here is a link where ashbash talks about Edict, to keep things simple... Think of it as a player entity class.

A player index is similar to a userid, its an identifying number for the player. indexes are not unique like userids though, if someone disconnects from the server another player can join and start using that index in their place. A simple way to think of it is a index is a reference to which slot the player is taking up while connected to the server. If you have a 12 slot server, except to work with 12 indexes.

Posted: Thu Aug 30, 2012 5:27 pm
by Spiked
Sweet, I nailed it.

Thanks for the clarification. Since you are also the one working on most of the documentation so far, can we expect to maybe see a reference page with a listing for where and when player is used vs index?

I'm assuming again... but it seems like both values are relevant to the engine?