Basic script help

Please post any questions about developing your plugin here. Please use the search function before posting!
Nomy
Junior Member
Posts: 18
Joined: Fri Aug 24, 2012 8:00 pm
Location: United Kingdom

Basic script help

Postby Nomy » Sun Aug 26, 2012 10:45 am

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 26, 2012 11:58 am

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
Nomy
Junior Member
Posts: 18
Joined: Fri Aug 24, 2012 8:00 pm
Location: United Kingdom

Postby Nomy » Sun Aug 26, 2012 5:48 pm

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 :)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 26, 2012 6:04 pm

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
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 26, 2012 6:05 pm

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
-Tuck
Nomy
Junior Member
Posts: 18
Joined: Fri Aug 24, 2012 8:00 pm
Location: United Kingdom

Postby Nomy » Sun Aug 26, 2012 6:35 pm

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.
User avatar
Spiked
Junior Member
Posts: 15
Joined: Mon Aug 27, 2012 8:00 pm
Location: Texas

Postby Spiked » Mon Aug 27, 2012 8:48 pm

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?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Aug 27, 2012 8:55 pm

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
Nomy
Junior Member
Posts: 18
Joined: Fri Aug 24, 2012 8:00 pm
Location: United Kingdom

Postby Nomy » Tue Aug 28, 2012 6:22 am

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 :)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 28, 2012 2:05 pm

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
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Tue Aug 28, 2012 3:43 pm

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.
Nomy
Junior Member
Posts: 18
Joined: Fri Aug 24, 2012 8:00 pm
Location: United Kingdom

Postby Nomy » Tue Aug 28, 2012 7:50 pm

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!
tnarocks
Member
Posts: 56
Joined: Fri Aug 03, 2012 1:35 am

Postby tnarocks » Wed Aug 29, 2012 9:13 pm

is this the same Nomy thats part of Mani Admin?
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Wed Aug 29, 2012 9:55 pm

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.
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Wed Aug 29, 2012 10:10 pm

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.
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Wed Aug 29, 2012 10:45 pm

User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Aug 30, 2012 2:27 am

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
User avatar
Spiked
Junior Member
Posts: 15
Joined: Mon Aug 27, 2012 8:00 pm
Location: Texas

Postby Spiked » Thu Aug 30, 2012 4:32 pm

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.
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Thu Aug 30, 2012 5:12 pm

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.
User avatar
Spiked
Junior Member
Posts: 15
Joined: Mon Aug 27, 2012 8:00 pm
Location: Texas

Postby Spiked » Thu Aug 30, 2012 5:27 pm

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?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 23 guests