EZSP - Libary to easily access SP modules & functions

Release your plugins here!
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

EZSP - Libary to easily access SP modules & functions

Postby stonedegg » Sat Sep 13, 2014 7:22 pm

This library provides "easy-to-access" functions that are quite similar to what we know from the eventscripts functions.
It's just a wrapper around some SP modules and their functions. I'm still discovering what SP lets us do at the current state, so I will keep updating this.

Functions:


Syntax: Select all

import ezsp as ez

ez.getindex(userid)
# returns the player's index by userid

##
# Functions that need <index> as argument
##

ez.getuserid(index)
# returns the player's userid

ez.getplayername(index)
# returns the player's name

ez.getplayersteamid(index)
# returns the player's steamid

ez.getplayerpointer(index)
# returns the player's pointer instance

ez.getplayerinfo(index)
# returns the player's playerinfo instance

ez.getplayerhandle(index)
# returns the player's handle

ez.getplayerlocation(index)
# returns the player's location as a mathlib.Vector instance

ez.getplayerteam(index)
# returns the player's team (0,1,2,3)

ez.gethealth(index)
# returns the player's health

ez.getarmor(index)
# returns the player's armor

ez.getmodel(index)
# returns the player's model name

ez.getcolor(index)
# returns the player's model color in RGBA format

ez.getlanguage(index)
# returns the player's cl_language variable

ez.isdead(index)
# returns True if the player is dead, else False

ez.iscrouched(index)
# returns True if the player is crouching, else False

ez.getviewcoordinated(index)
# returns the player's view coordinates

ez.geteyelocation(index)
# returns the player's eye location

ez.getviewvector(index)
# returns the payer's view vector

ez.getcvarvalue(index, cvar)
# returns a player's cvar value (e.g. cl_cmdrate)

ez.getvelocity(index)
# returns the player's velocity

ez.getspeed(index)
# returns the player's speed multiplier

ez.getnoclip(index)
# returns True if player in noclip, else False

ez.getnoblock(index)
# returns True if player has noblock, else False

ez.getjetpack(index)
# returns True if player has jetpack, else False

ez.getfreeze(index)
# returns True if player is frozen, else Flase

ez.getgodmode(index)
# returns True if player is in godmode, else False

ez.gethelmet(index)
# returns True if player has a helmet, else False

ez.getnearplayers(index, distance):
# returns a list of indexes of players that are within the given distance

ez.getclosestplayer(index)
# returns the distance and index of the closest player, will return (None,None) if there is none

ez.getweaponindex(index, weapon)
# returns the weapon index that is held by the player, will return 0 if the player doesn't have that weapon

ez.getweaponindexes(index)
# returns a list with all weapon indexes that are held by the player

ez.changeteam(index, team)
# changes the team (player will die if alive)

ez.sethealth(index, value)
# sets the health the player

ez.setspeed(index, value)
# sets the speed multiplier

ez.setmodel(index, model)
# precaches & sets the model

ez.setcolor(index, r, g, b, a=None)
# sets the model color (alpha does not work in csgo)

ez.setnoclip(index, value)
# set value parameter to 1 to turn noclip on, 0 to turn off

ez.setnoblock(index, value)
# set value parameter to 1 to turn noblock on, 0 to turn off

ez.setjetpack(index, value)
# set value parameter to 1 to turn jetpack on, 0 to turn off

ez.setfreeze(index, value)
# set value parameter to 1 to freeze, 0 to unfreeze

ez.setgodmode(index, value)
# set value parameter to 1 to turn godmode on, 0 to turn off

ez.flash(index, alpha, duration)
# blind a player like a flashbang --- does not work in csgo???

ez.sethelmet(index, value)
# set value parameter to 1 to give helmet, 0 to remove

ez.clientcommand(index, command)
# forces a player to execute a client command

##
# Other functions
##

ez.getplayercount()
# returns the number of players and bots

ez.gethumancount()
# returns the number of players

ez.getbotcount()
# returns the number of bots

ez.getalivecount()
# returns the number of alive players and bots

ez.getdeadcount()
# returns the number of dead players and bots

ez.precachemodel(model)
# precaches a model and returns its index

ez.precachedecal(decal)
# precaches a decal and returns its index

ez.createbot(name)
# creates a fake client with the given name

ez.drawline(start, end, model="sprites/laserbeam.vmt", halo="sprites/halo.vmt", startframe=0, framerate=1, life=1, width=5, endwidth=5, fadelength=5, amplitude=0, red=255, green=0, blue=0, alpha=255, speed=0)
# draws a line for every player --- start & end parameters must be mathlib.Vector() instances!
# model & halo will be precached

ez.drawcircle(center, start_radius=0, end_radius=250, model="sprites/laserbeam.vmt", halo="sprites/halo.vmt", startframe=0, framerate=255, life=1, width=5, spread=0, amplitude=0, red=255, green=0, blue=0, alpha=255, speed=1, flags=0)
# draws a circle for every player --- center parameter must be a mathlib.Vector() instance!
# model & halo will be precached

##
# Messages
##

ez.tell(index, message)
# print a SayText2 message to the player

ez.msg(message)
# print a SayText2 message to everyone

ez.hudhint(message)
# show a HintText message to everyone




I've tested the functions currently only in CS:GO.
Please provide any feedback, bugs or requests!


Download:
Attachments
ezsp.zip
(4.43 KiB) Downloaded 510 times
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Sep 13, 2014 8:02 pm

Let me tell you a nice trick. :p

Syntax: Select all

def getplayercount():
# Returns number of players and bots

x = 0
for index in PlayerIter():
x += 1

return x

Syntax: Select all

def getplayercount():
# Returns number of players and bots
return len(PlayerIter())
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Sat Sep 13, 2014 8:10 pm

I tried that, it doesn't work:

Syntax: Select all

print(len(PlayerIter()))

TypeError: object of type 'PlayerIter' has no len()
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Sep 13, 2014 8:14 pm

Ahh, okay. Then try this:

Syntax: Select all

def getplayercount():
# Returns number of players and bots
return len(tuple(PlayerIter()))
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Sat Sep 13, 2014 8:18 pm

Yea, that works :D I will update it soon.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Sep 15, 2014 1:02 am

This might sound like a silly question, but are you posting this here to be included in Source.Python? This forum is specifically for custom packages to be posted for discussion to be included in the plugin itself. If this isn't what you want, I will move it to the Addon Releases forum. Unfortunately, we do not currently have a place for custom packages to be posted, so the Addon Releases forum will have to suffice. Our plans for our ESAM (SPAM :p ) do include a separate section for custom packages which plugins can add as requirements.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Sep 17, 2014 12:48 am

You still haven't answered my question. I would like an answer on this so I know how to proceed.

I do have a few points about the code, though. First, we just updated PlayerIter to allow len(PlayerIter()) to work correctly.

Also, a few simplifications:

Syntax: Select all

def getuserid(index):
return userid_from_index(userid)


def getplayerpointer(index):
return pointer_from_index(index)


def getplayerinfo(index):
return playerinfo_from_index(index)


def getplayerhandle(index):
return inthandle_from_index(index)


def getcolor(index):
return PlayerEntity(index).color


def getspeed(index):
return PlayerEntity(index).speed


def getnoclip(index):
return PlayerEntity(index).noclip


def getnoblock(index):
return PlayerEntity(index).noblock


def getjetpack(index):
return PlayerEntity(index).jetpack


def getfreeze(index):
return PlayerEntity(index).freeze


def getgodmode(index):
return PlayerEntity(index).godmode

# Though, currently, cstrike has it set to "god" not "godmode",
# but that will be changed very soon.


def gethelmet(index):
return PlayerEntity(index).has_helmet


def getweaponindex(index, weapon):
return PlayerEntity(index).get_weapon_index(weapon)


def getweaponindexes(index):
return PlayerEntity(index).get_weapon_index_list()


def changeteam(index, team):
PlayerEntity(index).team = team


def sethealth(index, value):
PlayerEntity(index).health = value


def setspeed(index, value):
PlayerEntity(index).speed = value


def setcolor(index, r, g, b, a=None):
# This works for all entities
BaseEntity(index).color = (r, g, b) if a is None else (r, g, b, a)


def setnoclip(index, value):
PlayerEntity(index).noclip = value


def setnoblock(index, value):
PlayerEntity(index).noblock = value


def setjetpack(index, value):
PlayerEntity(index).jetpack = value


def setfreeze(index, value):
PlayerEntity(index).freeze = value


def godmode(index, value):
PlayerEntity(index).godmode = value

# Same as above, where currently cstrike uses "god" not "godmode",
# but it will soon be changing.


def sethelmet(index, value):
PlayerEntity(index).has_helmet = value



Notice that most of the stuff your script does is available directly from BaseEntity/PlayerEntity. I personally would much rather that everyone get used to using those objects properly instead of relying on wrapper functions. EventScripts instilled a lot of bad habits in people, at least in part due to the fact it had a 1-to-1 implementation of all of its ESS commands in ESP. Part of the ideology of this plugin is to help break people of those bad habits and help new programmers get started off without creating those same bad habits. I don't say this to discourage you, but to hopefully push you and others in the direction of better coding practices.
Image
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Wed Sep 17, 2014 2:13 am

I agree with the above reply, I really don't like when people attempt to re-introduce bad (old) habits/ideas, just to avoid having to learn a new thing, it doesn't even save you time in the long run, I find SP's structure and logic way more logical and useful than ES's, this therefore saves me time after I get used to the changes (which isn't really hard, as SP mostly does it the way it's done rationally and Pythonicly)!

I'll never use this. And people new from ES to SP should learn how the actual plugin now works, not rely on an extra abstraction which limits flexibility more and increases the chance of an incompatibility where it really isn't needed.

I actually REALLY like where SP is headed, please don't change that! But happily I don't think it will.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Wed Sep 17, 2014 3:32 pm

Hey, I didn't have time to reply earlier, sorry for that.
First of all, no it wasn't my intention to be included to SP, I just didn't know that this forum was made just for that. To the simplifactions you made, I can't confirm that they all work. I have tried earlier methods like PlayerEntity().health and I always got AttributeErrors, same with other methods I tried, so I actually read up the PlayerEntity and BaseEntity classes in the packages, and they don't provide those methods. I guess I'm just missing something, as always..
But anyways, ofcourse there isn't anything against the structure of SP, and I really like it, but I also don't see anything against using such a wrapper. Why recoding everything in every plugin and having hundreds of imports, while a library can just do that for us?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Sep 17, 2014 3:45 pm

Most of those have always worked for me. I think "color" might have an issue, currently, but I haven't tested it in quite a while. Most of those are included via the data:
https://github.com/Source-Python-Dev-Team/Source.Python/tree/master/addons/source-python/data/source-python/entities
https://github.com/Source-Python-Dev-Team/Source.Python/tree/master/addons/source-python/data/source-python/entities/properties
https://github.com/Source-Python-Dev-Team/Source.Python/tree/master/addons/source-python/data/source-python/entities/properties/player
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/properties/player/cstrike.ini

That structure is going to change in the near future with the BaseEntity updates that are being worked on in the entities_changes branch:
https://github.com/Source-Python-Dev-Team/Source.Python/tree/entities_changes



As for the wrapper, it doesn't "add" anything to the functionality. If your only point is less imports, all I can say is that is not neither good coding practice nor a good reason to do anything.


*Edit: moved thread to the Addon Releases forum.
Image
kuro112
Junior Member
Posts: 2
Joined: Wed May 20, 2015 5:48 pm

Postby kuro112 » Wed May 20, 2015 5:52 pm

alright, so i made an account literally just to chime in on this thread... this really pissed me off.

i realize this post is more than a year old, but regardless im certain im not the only one to feel this way.

so ive been a python dev for 10 years now, i work in the crypto-community and i loved to dev with eventscripts, because everything about it made my life easier.

so i noticed this guy tried to put forth an honest contribution, and instead of thanking him for a library that not only accelerates dev progress but makes SP far less intimidating,

you berate the user for being lazy and encouraging other users to be lazy, you tell him the goal of the project is to do the exact opposite and that everything about this wrapper just hurts a dev.


that attitude right there is why no one contributes here, because instead of getting honest feedback, suggestions on how to improve it, etc... all the user who made this got for his trouble was called bad.


i love this wrapper, and it may be the only reason i ever tough source python.

if the author is still out there, bravo mate, i hope you keep working on it.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu May 21, 2015 3:00 pm

I have re-read this thread and I don't have the impression that this conversation was impolite. Suggestions on how to improve his wrapper have been made, but it was also said that it might not be a good coding practice.

Wrapper usually simplify complex functions/classes, but writing wrappers, which just access an attribute of a class are not useful. However, it was never said that all of the wrappers are unnecessary. E.g. it makes sense to write wrappers for effects, because our plugin currently doesn't provide any default arguments.

I'm sorry if we or the plugin is "intimidating". That's obviously not our intention and we are happy about every contribution, question or feedback! I receive many questions, ideas and bug reports on Steam and I'm happy about all these responses, but I would be much more happier if all the questions were asked on the forums, because they could have helped many people and not just single persons. :)

Return to “Plugin Releases”

Who is online

Users browsing this forum: No registered users and 32 guests