Cokemonkey11
Spell Reviewer
- Joined
- May 9, 2006
- Messages
- 3,575
Hello,
I've made this system which repairs a player's character when they select a repair structure (on some conditions). It works correctly for all players in single player mode, but in multiplayer it does not (It doesn't seem to desync though, so that's nice)
Here's the script:
I would appreciate any suggestions or advice.
Edit: To be clear, "Doesn't work" means it doesn't seem to do anything at all - selecting a repair structure doesn't even deselect it.
I've made this system which repairs a player's character when they select a repair structure (on some conditions). It works correctly for all players in single player mode, but in multiplayer it does not (It doesn't seem to desync though, so that's nice)
Here's the script:
JASS:
scope Repair initializer i
globals
private constant real MAX_DISTANCE = 400.
private constant real REPAIR_TIMEOUT = 30.
private constant real FRAC = 1./2.
private constant string TOO_OFTEN_ERROR = "You can't heal yourself again so soon!"
private constant string MAX_HEALTH_ERROR = "Your ship is already at maximum health!"
private constant string DISTANCE_ERROR = "Your ship is too far away!"
private constant string ALLIANCE_ERROR = "You can't use the opposition's Repair Port!"
private constant string HEAL_MODEL = "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl"
private real array lastRepair[12]
endglobals
private function c takes nothing returns boolean
local player p
local unit tU=GetTriggerUnit()
local integer id
local real max
local real life
local integer index=0
if not Game_ended then
loop
exitwhen index>11
if IsUnitSelected(tU,Game_players[index]) then
set id=index
exitwhen true
endif
set index=index+1
endloop
set p = Player(id)
if Game_localPlayer==p then
call SelectUnit(tU,false)
call SelectUnit(Ships_ships[id],true)
endif
if IsUnitAlly(tU,p) then
if IsUnitInRange(tU,Ships_ships[id],MAX_DISTANCE) then
set life = GetWidgetLife(Ships_ships[id])
set max = GetUnitState(Ships_ships[id],UNIT_STATE_MAX_LIFE)
if life<max then
if Game_seconds - lastRepair[id] > REPAIR_TIMEOUT then
set lastRepair[id] = Game_seconds
call SetWidgetLife(Ships_ships[id],life + (max-life)*FRAC)
call DestroyEffect(AddSpecialEffectTarget(HEAL_MODEL,Ships_ships[id],"origin"))
else
call SimError(p,TOO_OFTEN_ERROR)
endif
else
call SimError(p,MAX_HEALTH_ERROR)
endif
else
call SimError(p,DISTANCE_ERROR)
endif
else
call SimError(p,ALLIANCE_ERROR)
endif
endif
set tU=null
return false
endfunction
private function i takes nothing returns nothing
local trigger t = CreateTrigger()
local integer index=0
loop
exitwhen index>11
set lastRepair[index] = -1.*REPAIR_TIMEOUT
set index=index+1
endloop
call TriggerRegisterUnitEvent(t,Game_westRepair,EVENT_UNIT_SELECTED)
call TriggerRegisterUnitEvent(t,Game_eastRepair,EVENT_UNIT_SELECTED)
call TriggerAddCondition(t,Condition(function c))
set t=null
endfunction
endscope
I would appreciate any suggestions or advice.
Edit: To be clear, "Doesn't work" means it doesn't seem to do anything at all - selecting a repair structure doesn't even deselect it.