Server Help

ASSS Questions - python region

Anonymous - Sat Apr 02, 2011 6:09 pm
Post subject: python region
Not sure exactly whats going and and why its not working.

The terminal is telling me;
TypeError: arg isn't a 'region'

But it have added the same region name in DCME.

Code: Show/Hide
def cr (arena, p, bid):
   if mapdata.RegionName (cr):
      chat.SendArenaSoundMessage (arena, 1, "%s Attempted to make a goal within the crease. Goal not counted. Faceoff!" % (p.name))
      balls.SpawnBall (arena, 0)
   return cr


I am not a programmer by any means and just trying to do some things.
Dr Brain - Sat Apr 02, 2011 9:46 pm
Post subject:
I'm no expert on ASSS python, but I think RegionName isn't the method you want. Your code doesn't actually check any coordinates.

Perhaps someone else can shed some light on the correct way to do this.
Hakaku - Sun Apr 03, 2011 12:26 am
Post subject:
One thing that strikes me as weird about your code is the following:
Quote:
def cr (arena, p, bid):
___if mapdata.RegionName (cr):
______chat.SendArenaSoundMessage (arena, 1, "%s Attempted to make a goal within the crease. Goal not counted. Faceoff!" % (p.name))
______balls.SpawnBall (arena, 0)
___return cr

Your argument 'cr' in mapdata.RegionName points right back to the entire function, and so it's invalid. Moreover, your return is also wrong as there's no element named 'cr' within your function to return (If you don't need to return anything, just leave 'return' on its own).

As Dr Brain pointed out, you're never actually comparing any coordinates. All that RegionName does is return the name of a given region. You'll want to use the mapdata function Contains(region,x,y) in conjunction with FindRegionByName(arena, name). The latter allows you to retrieve a region, while the former will search to see if the coordinates x and y are within that region. Thus, you could pair them like this:
Code: Show/Hide
rgn = mapdata.FindRegionByName(arena, "myfirstregionname")
if mapdata.Contains(rgn, 100, 600):
    chat.SendArenaMessage(arena, "Here is a message")

Since I assume you want to check to see whether the player is within the region, you'll have to get their coordinates using p.position[0] (x) and p.position[1] (y), and have them each divided by 16.
Code: Show/Hide
rgn = mapdata.FindRegionByName(arena, "myfirstregionname")
if mapdata.Contains(rgn, p.position[0] / 16, p.position[1] / 16):
    chat.SendArenaMessage(arena, "Here is a message")

All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group