diff --git a/python/CFReputation/__init__.py b/python/CFReputation/__init__.py index da55b9fc9..c0f94ffdb 100644 --- a/python/CFReputation/__init__.py +++ b/python/CFReputation/__init__.py @@ -40,14 +40,26 @@ def _get_db(): _init_db() return d[_dict_name] -def reputation(player): +def reputation(player, faction=None): + """ + Return tuple with the name and reputation of the player with the given + faction. If faction is None, return all known reputations. + """ con = _get_db() - query=""" + if faction is None: + query=""" SELECT faction, CAST(ROUND(reputation*100) as integer) as rep FROM reputations WHERE name=? AND ABS(rep) > 0; - """ - result = con.execute(query, (player,)).fetchall() + """ + result = con.execute(query, (player,)).fetchall() + else: + query=""" +SELECT faction, CAST(ROUND(reputation*100) as integer) as rep +FROM reputations +WHERE name=? AND faction=? AND ABS(rep) > 0; + """ + result = con.execute(query, (player, faction)).fetchall() return result def record_kill(race, region, player, fraction=0.0001, limit=0.4): diff --git a/python/misc/reputation_trigger_connect.py b/python/misc/reputation_trigger_connect.py new file mode 100644 index 000000000..2795f6697 --- /dev/null +++ b/python/misc/reputation_trigger_connect.py @@ -0,0 +1,37 @@ +""" +reputation_trigger_connect.py -- trigger connections based on reputation + +Use in a check_inv trigger with a event_trigger. + +Arguments: + faction - name of faction to check against + threshold - number between -100 and 100 + conn_geq - connection to trigger if reputation greater or equal than thresh + conn_lt - connection to trigger if reputation less than thresh + +If any connection is 0, the connection will not be used. +""" + +import CFReputation +import Crossfire + +def check(): + player = Crossfire.WhoIsActivator() + if player.Type != Crossfire.Type.PLAYER: + return + params = Crossfire.ScriptParameters() + args = params.split() + faction = args[0] + thresh = int(args[1]) + conn_geq = int(args[2]) + conn_lt = int(args[3]) + + rep = CFReputation.reputation(player.Name, faction) + if len(rep) > 0: + if rep[0][1] >= thresh: + if conn_geq != 0: + player.Map.TriggerConnected(conn_geq, 1, player) + elif conn_lt != 0: + player.Map.TriggerConnected(conn_lt, 1, player) + +check()