NOTICE: usage of this script will require some scripting of your own
So in the spirit of sharing I decided to slice a piece of functionality from my game and post it for the community, its a GTA style 5 star wanted system, I've made the script modular so it can just be dropped in and used
how it works, wanted points and level start at 0, call 'wanted_addpoints(value)' where value is the amount of points to add to the current level, the level threshold is set inside the script function 'wanted_load()' (read script notes)
when the current points meets the threshold for the current level the wanted level increases and resets points to zero until wanted level 5 is reached, after a 10 second delay after the last time 'wanted_addpoints' was called the points will start to go down by the amount set in 'g_wanted_ticker_subtract'
so typically, you would call 'wanted_addpoints' when the player commits a crime of some sort, shoots someone or steals something in view of people, for instance, place 'wanted_addpoints(50)' in the 'deathani' section of ai_soldier.lua, then whenever you shoot an enemy you will be wanted or gain wanted points, I have this setup with a custom civilian ai script but that broke with the last update
so I cant share it just yet till I figure out whats going wrong
first of all, load the script
dofile("scriptbank\\wanted\\wanted.lua")
and a rather crude example, it simply adds 50 points to the current level when the player fires the gun and starts a small delay to prevent the script looping
-- example
function example_init(e)
wanted_load() -- load the wanted system
end
can_add=true
function example_main(e)
wanted_update() -- update the wanted system
if g_PlayerGunFired == 1 and can_add then
can_add=false
wanted_addpoints(50)
StartTimer(e)
end
if GetTimer(e) > 1000 then
can_add=true
end
end
and here's the nuts and bolts of the script
g_wanted_message="All Gravy" -- the text to show when no wanted stars are active
g_wanted_level=0 -- the current wanted level
g_wanted_points=0 -- current wanted points
g_wanted_last_crime=10000 -- time since last crime to start the ticker (default 10 seconds)
g_wanted_last_crime_tick=0 -- time since last crime
g_wanted_ticker=0 -- current cooldown ticker value
g_wanted_ticker_delay = 2000 -- ticker period (default 2 seconds)
g_wanted_ticker_subtract = 5 -- points to subtract each ticker cycle (default 5 points)
-- enter path to star images
g_wanted_star_path="scriptbank\\wanted\\star.png"
g_wanted_nostar_path="scriptbank\\wanted\\nostar.png"
-- text color (TODO) move to star table for diff color per level
g_wanted_r=255
g_wanted_g=255
g_wanted_b=255
-- private wanted star table
g_wanted_star={}
g_wanted_star[1]={}
g_wanted_star[2]={}
g_wanted_star[3]={}
g_wanted_star[4]={}
g_wanted_star[5]={}
--############################
-- public functions
--############################
-- loads images and creates star tables (call from _init)
function wanted_load()
-- load images
g_wanted_star_img=LoadImage(g_wanted_star_path)
g_wanted_nostar_img=LoadImage(g_wanted_nostar_path)
-- this is where the stars are created
-- change 'msg' to the message you want to show for each star
-- the last param 'limit' sets the point limit for this star
-- when the limit the star level is increased and points level is reset to 0
--wanted_create_star(index, x, y, msg, limit)
wanted_create_star(1, 88.5, 5, "Distrubance1", 75)
wanted_create_star(2, 90.5, 5, "Distrubance2", 100)
wanted_create_star(3, 92.5, 5, "Distrubance3", 150)
wanted_create_star(4, 94.5, 5, "Distrubance4", 200)
wanted_create_star(5, 96.5, 5, "Distrubance5", 300)
end
-- updates the wanted panel, call from _main loop
function wanted_update()
Panel(88, 1, 99.1, 10)
if g_wanted_level == 0 then
TextCenterOnXColor(93.5, 3.5, 3, g_wanted_message, g_wanted_r, g_wanted_g, g_wanted_b)
else
TextCenterOnXColor(93.5, 3.5, 3, g_wanted_star[g_wanted_level]['msg'], g_wanted_r, g_wanted_g, g_wanted_b)
end
if g_wanted_level >= 1 then
wanted_set_star(1, true)
else
wanted_set_star(1, false)
end
if g_wanted_level >= 2 then
wanted_set_star(2, true)
else
wanted_set_star(2, false)
end
if g_wanted_level >= 3 then
wanted_set_star(3, true)
else
wanted_set_star(3, false)
end
if g_wanted_level >= 4 then
wanted_set_star(4, true)
else
wanted_set_star(4, false)
end
if g_wanted_level == 5 then
wanted_set_star(5, true)
else
wanted_set_star(5, false)
end
if g_wanted_level > 0 then
if math.abs(g_wanted_last_crime_tick-g_Time) > g_wanted_last_crime then
if math.abs(g_wanted_ticker-g_Time) > g_wanted_ticker_delay then
g_wanted_points=g_wanted_points-g_wanted_ticker_subtract
g_wanted_ticker=g_Time
if g_wanted_points<=0 then
g_wanted_level=g_wanted_level-1
g_wanted_points=0
end
end
end
end
end
-- adds 'points' to the current star level
function wanted_addpoints(points)
if g_wanted_level < 5 then
g_wanted_points=g_wanted_points+points
local c_limit=0
if g_wanted_level==0 then
c_limit=g_wanted_star[1]['limit']
else
c_limit=g_wanted_star[g_wanted_level]['limit']
end
if g_wanted_points>=c_limit then
g_wanted_level=g_wanted_level+1
g_wanted_last_crime_tick=g_Time
g_wanted_ticker=g_Time
g_wanted_points=0
end
else
g_wanted_last_crime_tick=g_Time
end
end
--############################
-- internal functions
--############################
-- set wanted star state
function wanted_set_star(index, isactive)
if isactive then
SetSpritePosition(g_wanted_star[index]['spr_off'], 150, 150)
SetSpritePosition(g_wanted_star[index]['spr_on'], g_wanted_star[index]['x'], g_wanted_star[index]['y'])
else
SetSpritePosition(g_wanted_star[index]['spr_on'], 150, 150)
SetSpritePosition(g_wanted_star[index]['spr_off'], g_wanted_star[index]['x'], g_wanted_star[index]['y'])
end
end
-- create a wanted star
function wanted_create_star(index, x, y, msg, limit)
-- create star sprite
g_wanted_star_spr=CreateSprite(g_wanted_star_img)
g_wanted_nostar_spr=CreateSprite(g_wanted_nostar_img)
-- set sprite size
SetSpriteSize(g_wanted_star_spr, 2, -1)
SetSpriteSize(g_wanted_nostar_spr, 2, -1)
-- assign data table
g_wanted_star[index]['spr_on']=g_wanted_star_spr
g_wanted_star[index]['spr_off']=g_wanted_nostar_spr
g_wanted_star[index]['x']=x
g_wanted_star[index]['y']=y
g_wanted_star[index]['msg']=msg
g_wanted_star[index]['limit']=limit
-- set sprite positions
SetSpritePosition(g_wanted_star[index]['spr_on'], 150, 150)
SetSpritePosition(g_wanted_star[index]['spr_off'], g_wanted_star[index]['x'], g_wanted_star[index]['y'])
end
and attached full script, images and example
no video example sorry I ripped this out of my game so only a screenie