Coding Tip #8
The final coding tip from Jands and Lude. Hope you enjoy it.
Creating an Objective and an Item Drop
Editor issues as in Coding Tip #7
In the script you will need to call the routine for the first time, set the objective, and set an attribute to keep track of thugs ko’d:
def OnPostInit():
Mission_SetAttr('thugs_fallen',0)
regTimer('random_spawn', 30)
Objective_Add('Secondary1', 'Knock out six thugs', 1, 500)
Then you will need to create the spawning routine with some additions:
def random_spawn(event):
thugs = ('thug_001', 'thug_002', 'thug_003', 'thug_004', 'thug_005', 'thug_006')
for thug in thugs:
xvar = randint(extentX(box1)-100,extentX(box2)-100)
yvar = randint(extentY(box1)-100,extentY(box2)-100)
Object_SpawnAt('thug_with_gun', (xvar,yvar,0), thug)
regDeath(thug, 'thug_down')
regAlmostDead('thug_001', 'drop_money', health=1)
Next you’ll add the routine called when the thugs are ko’d:
def thug_down(event):
count= Mission_GetAttr('thugs_fallen') + 1.0
if count > 5:
Objective_Complete('Secondary1')
Mission_SetAttr('thugs_fallen',count)
This routine will change the attribute each time a thug is ko’d and if it is six complete the objective. I also added a special check for thug_001, this routine will have him drop some money.
def drop_money(event):
cpos= Get_ObjectPos('thug_001')
Object_SpawnAt('money_bag', cpos, 'money_bag')
kill('thug_001')
This routine will check for thug_001 to reach 1 health, drop a money bag at his position and then ko him. The regDeath is still in effect and will be called, if he is the sixth one, the objective is still complete.