player_spawn event, does it fire more than once?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

player_spawn event, does it fire more than once?

Postby BackRaw » Thu Oct 10, 2013 10:57 am

Hi,

in EventScripts (CSS), we had to check if the team index was above 1 on player_spawn because it fired even before player_activate fired (or something like that, can't exactly remember).

Code: Select all

import es

def player_spawn(ev):
    if int(ev["es_userteam"]) > 1:
        # only after this if, the player actually spawned "physically", so to speak
Do we still need this check?

Btw: why doesn't [syntax="python"] .... [/syntax] work any more? Or is it just on my machine? lol
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Oct 10, 2013 5:10 pm

Yep, but remember that es_userteam is a variable defined by EventScripts. This might be more effective:

Code: Select all

from events import Event

players = set()

@Event
def player_spawn(ev):
    userid = ev.get_int('userid')
    if userid not in players:
        players.add(userid)
        return
       
    # Your code here...

@Event
def player_disconnect(ev):
    players.discard(ev.get_int('userid'))


The syntax higlighter is broken and unfortunately La Muerte does not have the required permissions to fix that.
sicman_adrian
Junior Member
Posts: 3
Joined: Tue Oct 08, 2013 10:03 am

Postby sicman_adrian » Fri Oct 11, 2013 3:48 am

Can also check life state to see if there physically alive
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Sat Oct 12, 2013 10:16 am

sicman_adrian wrote:Can also check life state to see if there physically alive


Good point, thanks!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Tue Oct 15, 2013 10:13 am

Ayuto wrote:Yep, but remember that es_userteam is a variable defined by EventScripts. This might be more effective:

Code: Select all

from events import Event

players = set()

@Event
def player_spawn(ev):
    userid = ev.get_int('userid')
    if userid not in players:
        players.add(userid)
        return
       
    # Your code here...

@Event
def player_disconnect(ev):
    players.discard(ev.get_int('userid'))


The syntax higlighter is broken and unfortunately La Muerte does not have the required permissions to fix that.


That does the half lol, I want to execute code when the player phisically spawns (the last time player_spawn fires for that player) you know? I guess the alive or team index check are the two best.
Thanks for the info on the syntax highlighter =)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Oct 15, 2013 3:29 pm

It actually does that. The first time a player spawns he isn't in our set. So, we add him to the set and return. After that everything after "# Your code here..." will be executed.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Oct 17, 2013 8:22 am

Yes but what if player_spawn fires 3 times? the first time the index gets added to the set, the second time (maybe player_activate hasn't fired yet) the code gets executed which is what I don't want lol :)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Oct 17, 2013 5:32 pm

I have never seen player_spawn firing 3 times.
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Thu Oct 17, 2013 8:02 pm

Ayuto wrote:I have never seen player_spawn firing 3 times.


Might be a bug with the engine/game (or caused by other mods that force spawn people..)
Libraries: k2tools
Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)
Plugins (game-specific): None atm

If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Sat Oct 19, 2013 7:20 pm

lol, help me on this: how many times does player_spawn fire?? twice? :D
XKillerBoy
Junior Member
Posts: 1
Joined: Sat Aug 24, 2013 10:30 am

Postby XKillerBoy » Sun Oct 27, 2013 10:43 am

Depends on how many rounds, and if you respawn players.
But just do a check if player_activate has been run first.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 46 guests