Add reputation-based trigger

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@20654 282e977c-c81d-0410-88c4-b93c2d0d6712
master
partmedia 2018-12-30 05:15:57 +00:00
parent f02c281cb0
commit 2b68d11846
2 changed files with 53 additions and 4 deletions

View File

@ -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()
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()
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):

View File

@ -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()