HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

creating and destroying special effects for local player.

07-26-2006, 09:26 PM#1
Linera
How can i correctly create special effect and still be able to destory them each one?

currently i have:
Collapse JASS:
function Quest_Status takes unit u, integer i, integer a returns effect
local string path=""
if ConvertedPlayer(i) == GetLocalPlayer() then
   if a == 0 then
   set path = "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl"
   elseif a == 1 then
   set path = "Objects\\RandomObject\\RandomObject.mdl"
   elseif a == 2 then
   set path= "Objects\\RandomObject\\RandomObject.mdl"

   endif
endif
return AddSpecialEffectTargetUnitBJ( "overhead", u,  path)
endfunction

to create i use:
Trigger:
Custom script: set udg_QuestEffect[1] = Quest_Status(udg_TempQuestSetupUnit, 1, 0)
destory with:
Trigger:
Special Effect - Destroy QuestEffect[tempnumber]
07-26-2006, 10:02 PM#2
vile
I've done this in a spell on my map, to prevent other players from seeing you casting the trap. Simply, use a unit and use the model of the unit as the special effect, give it a permanent invisibility ability and create it for the owner of the certain player. That will play its effect. You can then add a timed life to it, depending on the length of the effect, usually 3 seconds is the most proper, it just depends on the animation length of the effect.
07-26-2006, 10:05 PM#3
Linera
its not a unit, its a special effect to be place above a unit
07-26-2006, 10:10 PM#4
Anitarf
What you have so far seems correct. What's the problem?
07-26-2006, 10:12 PM#5
Linera
well, it seems to desync. but then my system has more problems then i can find. plus i suck at jass, but need it to make this system
07-27-2006, 10:02 AM#6
The)TideHunter(
If you really needed this, you could use my CF functions, as thats mainly for effects, it allows the hiding/showing of a effect for a player n stuff.

Collapse JASS:
function CF_CreateGroundEffect takes real X, real Y, real Z, real facing, real sizeFactor, string modelPath, integer red, integer green, integer blue, integer alpha returns effect
function CF_GetLastCreatedEffect takes nothing returns effect

function CF_GetEffectCarryingUnit takes effect whichEffect returns unit
function CF_GetEffectX takes effect whichEffect returns real
function CF_GetEffectY takes effect whichEffect returns real
function CF_GetEffectZ takes effect whichEffect returns real
function CF_GetEffectFacing takes effect whichEffect returns real
function CF_GetEffectSize takes effect whichEffect returns real
function CF_GetEffectModelPath takes effect whichEffect returns string
function CF_GetEffectRedColour takes effect whichEffect returns integer
function CF_GetEffectGreenColour takes effect whichEffect returns integer
function CF_GetEffectBlueColour takes effect whichEffect returns integer
function CF_GetEffectAlphaColour takes effect whichEffect returns integer

function CF_IsEffectLocked takes effect whichEffect returns boolean
function CF_IsEffectInRect takes effect whichEffect, real minX, real minY, real maxX, real maxY returns boolean
function CF_IsEffectInRectEx takes effect whichEffect, rect whichRect returns boolean
function CF_IsEffectInRange takes effect whichEffect, real X, real Y, real radius returns boolean
function CF_IsEffectInRangeEx takes effect whichEffect, location whichLocation, real radius returns boolean

function CF_SetEffectX takes effect whichEffect, real X returns nothing
function CF_SetEffectY takes effect whichEffect, real Y returns nothing
function CF_SetEffectLoc takes effect whichEffect, real X, real Y returns nothing
function CF_SetEffectLocEx takes effect whichEffect, location whichLocation returns nothing
function CF_SetEffectZ takes effect whichEffect, real newZ returns nothing
function CF_SetEffectFacing takes effect whichEffect, real facing returns nothing
function CF_SetEffectSize takes effect whichEffect, real sizeFactor returns nothing

function CF_EffectAddExpirationTime_Destroy takes nothing returns nothing
function CF_EffectAddExpirationTime takes effect whichEffect, real time returns nothing
function CF_SetEffectColour takes effect whichEffect, integer red, integer green, integer blue, integer alpha returns nothing
function CF_SetEffectRedColour takes effect whichEffect, integer red returns nothing
function CF_SetEffectGreenColour takes effect whichEffect, integer green returns nothing
function CF_SetEffectBlueColour takes effect whichEffect, integer blue returns nothing
function CF_SetEffectAlphaColour takes effect whichEffect, integer alpha returns nothing
    
function CF_CopyEffect takes effect whichEffect returns effect
function CF_CopyEffectLoc takes effect whichEffect, real X, real Y returns effect
function CF_CopyEffectLocEx takes effect whichEffect, location whichLocation returns effect

function CF_LockEffect takes effect whichEffect returns nothing
function CF_UnlockEffect takes effect whichEffect returns nothing
function CF_LockEffectEdit takes effect whichEffect, boolean lock returns nothing

function CF_ShowEffectForPlayer takes effect whichEffect, player whichPlayer returns nothing
function CF_HideEffectForPlayer takes effect whichEffect, player whichPlayer returns nothing
function CF_DisplayEffectForPlayer takes effect whichEffect, player whichPlayer, boolean show returns nothing

The bottom 3 functions are what you want.
But if you want to use ANY of the CF functions for effects, they have to be created with the CF_CreateGroundEffect, otherwise they wont work.
Its complicated how it works, it does actually attach the effect to a unit, but you cant notice, and will never tell.

If you do want to use them, the CF functions are below (some are bugged and uneffecient).

Note: Fill in the constants.

Collapse JASS:
// Casual Functions Engine
// Created and Updated by The)TideHunter(
// Creation Began: 28/05/06
// Last Updated: 25/07/06

// Global, the gamecache is needed for CS Functions to work
globals
    gamecache udg_GC = null
endglobals

// This is the GameCache return function
function CF_GC takes nothing returns gamecache
    if(udg_GC == null) then
        call FlushGameCache(InitGameCache("GC"))
        set udg_GC = InitGameCache("GC")
    endif
    return udg_GC
endfunction

// Constants, you may edit these to fit what you want.
constant function CF_Constant_CollisionDetectionRange takes nothing returns real
    return 25. // This is the value used in functions that use a collision method.
               // When the functions collision comes in this range, the function
               // will do whats its meant to do.
endfunction

constant function CF_Constant_MinTimerUpdate takes nothing returns real
    return 0.04 // This looks convincing, and isent lag friendly.
                // Credit: Vexorian
                // This was the value I used from his Caster System.
endfunction

constant function CF_Constant_DummyUnitRawcode takes nothing returns integer
    return '????' // Dummy rawcode or your dummy.
                  // This 'MUST' be Vexorian's custom created dummy model.
                  // ~It has the correct attachment points.
endfunction

constant function CF_Constant_MorphUnitFlyAbilityRawcode takes nothing returns integer
    return '????' // Rawcode of the Morph ability in your map.
endfunction

// Variable Switches
function CF_B2I takes boolean B returns integer
    if(B) then
        return 1
    endif
    return 0
endfunction

function CF_I2B takes integer I returns boolean
    if(I == 1) then
        return true
    endif
    return false
endfunction

function CF_B2S takes boolean B returns string
    return I2S(CF_B2I(B))
endfunction

function CF_S2B takes string S returns boolean
    return CF_I2B(S2I(S))
endfunction

// Return Bug
function CF_H2I takes handle H returns integer
    return H
    return 0
endfunction
function CF_H2S takes handle H returns string
    return I2S(CF_H2I(H))
endfunction

function CF_I2Ability takes integer I returns ability
    return I
    return null
endfunction
function CF_I2AIDifficulty takes integer I returns aidifficulty
    return I
    return null
endfunction
function CF_I2AillianceType takes integer I returns alliancetype
    return I
    return null
endfunction
function CF_I2AttackType takes integer I returns attacktype
    return I
    return null
endfunction
function CF_I2Blendmode takes integer I returns blendmode
    return I
    return null
endfunction
function CF_I2BooleanExpression takes integer I returns boolexpr
    return I
    return null
endfunction
function CF_I2Buff takes integer I returns buff
    return I
    return null
endfunction
function CF_I2Button takes integer I returns button
    return I
    return null
endfunction
function CF_I2Camerafield takes integer I returns camerafield
    return I
    return null
endfunction
function CF_I2CameraSetup takes integer I returns camerasetup
    return I
    return null
endfunction
function CF_I2ConditionFunction takes integer I returns conditionfunc
    return I
    return null
endfunction
function CF_I2DamageType takes integer I returns damagetype
    return I
    return null
endfunction
function CF_I2DefeatCondition takes integer I returns defeatcondition
    return I
    return null
endfunction
function CF_I2SDestructable takes integer I returns destructable
    return I
    return null
endfunction
function CF_I2Dialog takes integer I returns dialog
    return I
    return null
endfunction
function CF_I2DialogEvent takes integer I returns dialogevent
    return I
    return null
endfunction
function CF_I2Effect takes integer I returns effect
    return I
    return null
endfunction
function CF_I2EffectType takes integer I returns effecttype
    return I
    return null
endfunction
function CF_I2Event takes integer I returns event
    return I
    return null
endfunction
function CF_I2EffectID takes integer I returns eventid
    return I
    return null
endfunction
function CF_I2FGameState takes integer I returns fgamestate
    return I
    return null
endfunction
function CF_I2FilterFunction takes integer I returns filterfunc
    return I
    return null
endfunction
function CF_I2FogModifier takes integer I returns fogmodifier
    return I
    return null
endfunction
function CF_I2FogState takes integer I returns fogstate
    return I
    return null
endfunction
function CF_I2Force takes integer I returns force
    return I
    return null
endfunction
function CF_I2GameCache takes integer I returns gamecache
    return I
    return null
endfunction
function CF_I2GameDifficulty takes integer I returns gamedifficulty
    return I
    return null
endfunction
function CF_I2GameEvent takes integer I returns gameevent
    return I
    return null
endfunction
function CF_I2GameSpeed takes integer I returns gamespeed
    return I
    return null
endfunction
function CF_I2GameState takes integer I returns gamestate
    return I
    return null
endfunction
function CF_I2GameType takes integer I returns gametype
    return I
    return null
endfunction
function CF_I2Group takes integer I returns group
    return I
    return null
endfunction
function CF_I2IGameState takes integer I returns igamestate
    return I
    return null
endfunction
function CF_I2Image takes integer I returns image
    return I
    return null
endfunction
function CF_I2Item takes integer I returns item
    return I
    return null
endfunction
function CF_I2ItemPool takes integer I returns itempool
    return I
    return null
endfunction
function CF_I2ItemType takes integer I returns itemtype
    return I
    return null
endfunction
function CF_I2Leaderboard takes integer I returns leaderboard
    return I
    return null
endfunction
function CF_I2Lightning takes integer I returns lightning
    return I
    return null
endfunction
function CF_I2Limitop takes integer I returns limitop
    return I
    return null
endfunction
function CF_I2Location takes integer I returns location
    return I
    return null
endfunction
function CF_I2MapControl takes integer I returns mapcontrol
    return I
    return null
endfunction
function CF_I2MapDensity takes integer I returns mapdensity
    return I
    return null
endfunction
function CF_I2MapFlag takes integer I returns mapflag
    return I
    return null
endfunction
function CF_I2MapSetting takes integer I returns mapsetting
    return I
    return null
endfunction
function CF_I2MapVisability takes integer I returns mapvisibility
    return I
    return null
endfunction
function CF_I2Multiboard takes integer I returns multiboard
    return I
    return null
endfunction
function CF_I2MultiboardItem takes integer I returns multiboarditem
    return I
    return null
endfunction
function CF_I2PathingType takes integer I returns pathingtype
    return I
    return null
endfunction
function CF_I2Placement takes integer I returns placement
    return I
    return null
endfunction
function CF_I2Player takes integer I returns player
    return I
    return null
endfunction
function CF_I2PlayerColor takes integer I returns playercolor
    return I
    return null
endfunction
function CF_I2PlayerEvent takes integer I returns playerevent
    return I
    return null
endfunction
function CF_I2PlayerGameResult takes integer I returns playergameresult
    return I
    return null
endfunction
function CF_I2PlayerScore takes integer I returns playerscore
    return I
    return null
endfunction
function CF_I2PlayerSlotState takes integer I returns playerslotstate
    return I
    return null
endfunction
function CF_I2PlayerState takes integer I returns playerstate
    return I
    return null
endfunction
function CF_I2PlayerUnitEvent takes integer I returns playerunitevent
    return I
    return null
endfunction
function CF_I2Quest takes integer I returns quest
    return I
    return null
endfunction
function CF_I2QuestItem takes integer I returns questitem
    return I
    return null
endfunction
function CF_I2Race takes integer I returns race
    return I
    return null
endfunction
function CF_I2RacePreference takes integer I returns racepreference
    return I
    return null
endfunction
function CF_I2RarityControl takes integer I returns raritycontrol
    return I
    return null
endfunction
function CF_I2Rect takes integer I returns rect
    return I
    return null
endfunction
function CF_I2Region takes integer I returns region
    return I
    return null
endfunction
function CF_I2Sound takes integer I returns sound
    return I
    return null
endfunction
function CF_I2SoundType takes integer I returns soundtype
    return I
    return null
endfunction
function CF_I2StartLocPrio takes integer I returns startlocprio
    return I
    return null
endfunction
function CF_I2TerrainDeformation takes integer I returns terraindeformation
    return I
    return null
endfunction
function CF_I2TexMapFlags takes integer I returns texmapflags
    return I
    return null
endfunction
function CF_I2TextTag takes integer I returns texttag
    return I
    return null
endfunction
function CF_I2Timer takes integer I returns timer
    return I
    return null
endfunction
function CF_I2TimerDialog takes integer I returns timerdialog
    return I
    return null
endfunction
function CF_I2Trackable takes integer I returns trackable
    return I
    return null
endfunction
function CF_I2Trigger takes integer I returns trigger
    return I
    return null
endfunction
function CF_I2TriggerAction takes integer I returns triggeraction
    return I
    return null
endfunction
function CF_I2TriggerCondition takes integer I returns triggercondition
    return I
    return null
endfunction
function CF_I2Ubersplat takes integer I returns ubersplat
    return I
    return null
endfunction
function CF_I2Unit takes integer I returns unit
    return I
    return null
endfunction
function CF_I2UnitEvent takes integer I returns unitevent
    return I
    return null
endfunction
function CF_I2UnitPool takes integer I returns unitpool
    return I
    return null
endfunction
function CF_I2UnitState takes integer I returns unitstate
    return I
    return null
endfunction
function CF_I2UnitType takes integer I returns unittype
    return I
    return null
endfunction
function CF_I2Version takes integer I returns version
    return I
    return null
endfunction
function CF_I2VolumeGroup takes integer I returns volumegroup
    return I
    return null
endfunction
function CF_I2WeaponType takes integer I returns weapontype
    return I
    return null
endfunction
function CF_I2WeatherEffect takes integer I returns weathereffect
    return I
    return null
endfunction
function CF_I2Widget takes integer I returns widget
    return I
    return null
endfunction
function CF_I2WidgetEvent takes integer I returns widgetevent
    return I
    return null
endfunction

// Attach and Store Variables
function CF_StoreInteger takes integer whichInteger, string label returns nothing
    if(whichInteger != 0) then
        call StoreInteger(CF_GC(), label, "Integer", whichInteger)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_StoreReal takes real whichReal, string label returns nothing
    if(whichReal != 0.) then
        call StoreReal(CF_GC(), label, "Real", whichReal)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_StoreString takes string whichString, string label returns nothing
    if(whichString != "") then
        call StoreString(CF_GC(), label, "String", whichString)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_StoreBoolean takes boolean whichBoolean, string label returns nothing
    local integer i = CF_B2I(whichBoolean)
    if(i == 1) then
        call StoreInteger(CF_GC(), label, "Boolean", i)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_StoreHandle takes handle whichHandle, string label, string HandleType returns nothing
    local integer i = CF_H2I(whichHandle)
    if(i != 0) then
        call StoreInteger(CF_GC(), label, HandleType, i)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction

function CF_LoadInteger takes string label returns integer
    return GetStoredInteger(CF_GC(), label, "Integer")
endfunction
function CF_LoadReal takes string label returns real
    return GetStoredReal(CF_GC(), label, "Real")
endfunction
function CF_LoadString takes string label returns string
    return GetStoredString(CF_GC(), label, "String")
endfunction
function CF_LoadBoolean takes string label returns boolean
    return CF_I2B(GetStoredInteger(CF_GC(), label, "Boolean"))
endfunction

function CF_LoadUnit takes string label returns unit
    return CF_I2Unit(GetStoredInteger(CF_GC(), label, "Unit"))
endfunction
function CF_LoadEffect takes string label returns effect
    return CF_I2Effect(GetStoredInteger(CF_GC(), label, "Effect"))
endfunction
function CF_LoadPlayer takes string label returns player
    return CF_I2Player(GetStoredInteger(CF_GC(), label, "Player"))
endfunction
function CF_LoadTrigger takes string label returns trigger
    return CF_I2Trigger(GetStoredInteger(CF_GC(), label, "Trigger"))
endfunction
function CF_LoadTimer takes string label returns timer
    return CF_I2Timer(GetStoredInteger(CF_GC(), label, "Timer"))
endfunction
function CF_LoadDialog takes string label returns dialog
    return CF_I2Dialog(GetStoredInteger(CF_GC(), label, "Dialog"))
endfunction
function CF_LoadButton takes string label returns button
    return CF_I2Button(GetStoredInteger(CF_GC(), label, "Dialog"))
endfunction

function CF_AttachInteger takes integer whichInteger, string label, handle KeyHandle returns nothing
    local integer i = CF_H2I(KeyHandle)
    if(i != 0) then
        call StoreInteger(CF_GC(), label, I2S(i), whichInteger)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_AttachReal takes real whichReal, string label, handle KeyHandle returns nothing
    local integer i = CF_H2I(KeyHandle)
    if(i != 0) then
        call StoreReal(CF_GC(), label, I2S(i), whichReal)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_AttachString takes string whichString, string label, handle KeyHandle returns nothing
    local integer i = CF_H2I(KeyHandle)
    if(i != 0) then
        call StoreString(CF_GC(), label, I2S(i), whichString)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_AttachBoolean takes boolean whichBoolean, string label, handle KeyHandle returns nothing
    local integer b = CF_B2I(whichBoolean)
    local integer i = CF_H2I(KeyHandle)
    if(i != 0) then
        call StoreInteger(CF_GC(), label, I2S(i), b)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction
function CF_AttachHandle takes handle whichHandle, string label, handle KeyHandle returns nothing
    local integer h = CF_H2I(whichHandle)
    local integer i = CF_H2I(KeyHandle)
    if(i+h != 0) then
        call StoreInteger(CF_GC(), label, I2S(i), h)
    else
        call FlushStoredMission(CF_GC(), label)
    endif
endfunction

function CF_GetAttachedInteger takes handle KeyHandle, string label returns integer
    return GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle))
endfunction
function CF_GetAttachedReal takes handle KeyHandle, string label returns real
    return GetStoredReal(CF_GC(), label, CF_H2S(KeyHandle))
endfunction
function CF_GetAttachedString takes handle KeyHandle, string label returns string
    return GetStoredString(CF_GC(), label, CF_H2S(KeyHandle))
endfunction
function CF_GetAttachedBoolean takes handle KeyHandle, string label returns boolean
    return CF_I2B(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction

function CF_GetAttachedUnit takes handle KeyHandle, string label returns unit
    return CF_I2Unit(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction
function CF_GetAttachedEffect takes handle KeyHandle, string label returns effect
    return CF_I2Effect(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction
function CF_GetAttachedPlayer takes handle KeyHandle, string label returns player
    return CF_I2Player(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction
function CF_GetAttachedTrigger takes handle KeyHandle, string label returns trigger
    return CF_I2Trigger(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction
function CF_GetAttachedTimer takes handle KeyHandle, string label returns timer
    return CF_I2Timer(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction
function CF_GetAttachedDialog takes handle KeyHandle, string label returns dialog
    return CF_I2Dialog(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction
function CF_GetAttachedButton takes handle KeyHandle, string label returns button
    return CF_I2Button(GetStoredInteger(CF_GC(), label, CF_H2S(KeyHandle)))
endfunction


// Simple Functions
// Check Co-ordinates
function CF_IsXSafe takes real X returns boolean
    return (X > GetRectMinX(bj_mapInitialPlayableArea)) and (X < GetRectMaxX(bj_mapInitialPlayableArea))
endfunction

function CF_IsYSafe takes real Y returns boolean
    return (Y > GetRectMinY(bj_mapInitialPlayableArea)) and (Y < GetRectMaxY(bj_mapInitialPlayableArea))
endfunction

function CF_IsLocSafe takes real X, real Y returns boolean
    if(CF_IsXSafe(X) and CF_IsYSafe(Y)) then
        return true
    endif
    return false
endfunction

function CF_IsLocSafeEx takes location whichLocation returns boolean
    return CF_IsLocSafe(GetLocationX(whichLocation), GetLocationY(whichLocation))
endfunction

// Remove Attachments
function CF_RemoveAttachments takes handle KeyHandle returns nothing
    call FlushStoredMission(CF_GC(), CF_H2S(KeyHandle))
endfunction

function CF_RemoveStoredData takes string label returns nothing
    call FlushStoredMission(CF_GC(), label)
endfunction

// Remove Handles
function CF_DestroyTimer takes timer whichTimer returns nothing
    call PauseTimer(whichTimer)
    call CF_RemoveAttachments(whichTimer)
    call DestroyTimer(whichTimer)
endfunction

function CF_RemoveUnit takes unit whichUnit returns nothing
    call CF_RemoveAttachments(whichUnit)
    call RemoveUnit(whichUnit)
endfunction

function CF_DestroyEffect takes effect whichEffect returns nothing
    local unit CarryingUnit = CF_GetAttachedUnit(whichEffect, "Effect_CarryingUnit")
    call CF_RemoveAttachments(whichEffect)
    call DestroyEffect(whichEffect)
    call CF_RemoveAttachments(CarryingUnit)
    call RemoveUnit(CarryingUnit)
    set CarryingUnit = null
endfunction

function CF_DestroyTrigger takes trigger whichTrigger returns nothing
    call CF_RemoveAttachments(whichTrigger)
    call DestroyTrigger(whichTrigger)
endfunction

// Get a Dummy Unit, ready for anything
function CF_GetADummy takes real X, real Y returns unit
    local unit u
    if(CF_IsLocSafe(X, Y)) then
        set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), CF_Constant_DummyUnitRawcode(), X, Y, 90.)
        call UnitAddAbility(u, CF_Constant_MorphUnitFlyAbilityRawcode())
        call UnitRemoveAbility(u, CF_Constant_MorphUnitFlyAbilityRawcode())
        call UnitAddAbility(u, 'Avul')
        call UnitAddAbility(u, 'Aloc')
        call SetUnitMoveSpeed(u, 522)
    endif
    return u
endfunction

// Change a colour value into a percent and vis-versa
function CF_PercentTo255 takes real percent returns real
    local real r = (percent / 100) * 255
    if(r > 255.) then
        set r = 255.
    elseif(r < 0.) then
        set r = 0.
    endif
    return r
endfunction

function CF_255ToPercent takes real amount returns real
    local real r = (amount / 255) * 100
    if(r > 100.) then
        set r = 100.
    elseif(r < 0.) then
        set r = 0.
    endif
    return r
endfunction

// Hide or Show a Multiboard for a single player.
function CF_HideMultiboardForPlayer takes multiboard whichMultiboard, player whichPlayer returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call MultiboardDisplay(whichMultiboard, false)
    endif
endfunction

function CF_ShowMultiboardForPlayer takes multiboard whichMultiboard, player whichPlayer returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call MultiboardDisplay(whichMultiboard, true)
    endif
endfunction

function CF_MultiboardDisplayForPlayer takes multiboard whichMultiboard, player whichPlayer, boolean show returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call MultiboardDisplay(whichMultiboard, show)
    endif
endfunction

// Damage function thats uses index's instead of attack and damage type.
function CF_DamageWidget takes unit Credit, widget Target, real Damage, integer AttackIndex, integer DamageIndex returns nothing
    call UnitDamageTarget(Credit, Target, Damage, true, false, ConvertAttackType(AttackIndex), ConvertDamageType(DamageIndex), WEAPON_TYPE_WHOKNOWS)
endfunction

// Hide or Show a unit for a player
function CF_ShowUnitForPlayer takes unit whichUnit, player whichPlayer returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call ShowUnit(whichUnit, true)
    endif
endfunction

function CF_HideUnitForPlayer takes unit whichUnit, player whichPlayer returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call ShowUnit(whichUnit, false)
    endif
endfunction

function CF_UnitDisplayForPlayer takes unit whichUnit, player whichPlayer, boolean show returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call ShowUnit(whichUnit, show)
    endif
endfunction

// Run a function after a certain amount of time in a new thread.
function CF_RunFunctionTimed_Run takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local trigger run = CF_GetAttachedTrigger(t, "RunFunctionTimer_Code")
    call TriggerExecute(run)
    call CF_DestroyTimer(t)
    call CF_DestroyTrigger(run)
    set t = null
    set run = null
endfunction

function CF_RunFunctionTimed takes code Function, real Wait returns nothing // This function runs a different
                                                                            // function after a certain amount of
                                                                            // time, it will also open a new
                                                                            // thread.
    local timer t = CreateTimer()
    local trigger run = CreateTrigger()
    call TriggerAddAction(run, Function)
    call TimerStart(t, Wait, false, function CF_RunFunctionTimed_Run)
endfunction

// Say Functions
function CF_SayMessage takes string Message, real Duration returns nothing
    call DisplayTimedTextFromPlayer(GetLocalPlayer(), 0., 0., Duration, Message)
endfunction

function CF_SayMessageLoc takes string Message, real Duration, real X, real Y returns nothing
    call DisplayTimedTextFromPlayer(GetLocalPlayer(), X, Y, Duration, Message)
endfunction    

function CF_WisperMessage takes string Message, player whichPlayer, real Duration returns nothing
    call DisplayTimedTextFromPlayer(whichPlayer, 0., 0., Duration, Message)
endfunction

function CF_WisperMessageLoc takes string Message, player whichPlayer, real Duration, real X, real Y returns nothing
    call DisplayTimedTextFromPlayer(whichPlayer, X, Y, Duration, Message)
endfunction

function CF_AnnounceMessage takes string Message, force whichForce, real Duration returns nothing
    if(IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        call DisplayTimedTextFromPlayer(GetLocalPlayer(), 0., 0., Duration, Message)
    endif
endfunction

function CF_AnnounceMessageLoc takes string Message, force whichForce, real Duration, real X, real Y returns nothing
    if(IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        call DisplayTimedTextFromPlayer(GetLocalPlayer(), X, Y, Duration, Message)
    endif
endfunction

// Move a item from 1 slot to another

function CF_MoveItemSlot takes unit MovingUnit, integer CurrentItemSlot, integer NewItemSlot returns nothing
    call IssueTargetOrderById(MovingUnit, 852001+NewItemSlot, UnitItemInSlot(MovingUnit, CurrentItemSlot)) 
endfunction

// Move unit Functions
function CF_SetUnitX takes unit whichUnit, real X returns nothing
    if(CF_IsXSafe(X)) then
        call SetUnitX(whichUnit, X)
    endif
endfunction

function CF_SetUnitY takes unit whichUnit, real Y returns nothing
    if(CF_IsYSafe(Y)) then
        call SetUnitY(whichUnit, Y)
    endif
endfunction

function CF_SetUnitLoc takes unit whichUnit, real X, real Y returns nothing
    if(CF_IsLocSafe(X, Y)) then
        call SetUnitX(whichUnit, X)
        call SetUnitY(whichUnit, Y)
    endif
endfunction

function CF_SetUnitLocEx takes unit whichUnit, location whichLocation returns nothing
    if(CF_IsLocSafeEx(whichLocation)) then
        call SetUnitX(whichUnit, GetLocationX(whichLocation))
        call SetUnitY(whichUnit, GetLocationY(whichLocation))
    endif
endfunction

// Get Casted Ability level
function CF_GetSpellLevel takes nothing returns integer
    return GetUnitAbilityLevel(GetSpellAbilityUnit(), GetSpellAbilityId())
endfunction

// Order Immediate stop
function CF_Stop takes unit whichUnit returns nothing
    call PauseUnit(whichUnit, true)
    call IssueImmediateOrder(whichUnit, "stop")
    call PauseUnit(whichUnit, false)
endfunction

// Get the Host of a game
function CF_GetHost takes nothing returns player
    local player Host = Player(CF_LoadInteger("Player_HostID"))
    if(Host == null) then
        call StoreInteger(CF_GC(), "missionKey", "key", GetPlayerId(GetLocalPlayer()) + 1)
        call TriggerSyncStart()
        call SyncStoredInteger(CF_GC(), "missionKey", "key")
        call TriggerSyncReady()
        set Host = Player(GetStoredInteger(CF_GC(), "missionKey", "key") - 1)
        call CF_StoreInteger(GetPlayerId(Host), "Player_HostID")
    endif
    return Host
endfunction

// Defeat Player Properly
function CF_DefeatPlayer_Trig_Actions takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local dialog d = CF_GetAttachedDialog(t, "CF_DefeatPlayer_Dialog")
    local boolean SS = CF_GetAttachedBoolean(t, "CF_DefeatPlayer_SS")
    local player p = Player(CF_GetAttachedInteger(t, "CF_DefeatPlayer_Id")) 
    call CustomVictoryBJ(p, false, SS)
    call CF_DestroyTrigger(t)
    call DialogDestroy(d)
    set t = null
    set d =  null
    set p = null
endfunction           

function CF_DefeatPlayer takes player whichPlayer, string Msg, string ButtonMsg, boolean ShowScores returns nothing
    local dialog d = DialogCreate()
    local button b = DialogAddButton(d, ButtonMsg, 0)
    local trigger t = CreateTrigger()
    call DialogSetMessage(d, Msg)
    if(GetLocalPlayer() != whichPlayer) then
        call DialogDisplay(whichPlayer, d, false)
    endif
    call DialogDisplay(whichPlayer, d, true)
    call CF_AttachHandle(d, "CF_DefeatPlayer_Dialog", t)
    call CF_AttachHandle(b, "CF_DefeatPlayer_Button", t)
    call CF_AttachBoolean(ShowScores, "CF_DefeatPlayer_SS", t)
    call CF_AttachInteger(GetPlayerId(whichPlayer), "CF_DefeatPlayer_Id", t)
    call TriggerRegisterDialogButtonEvent(t, b)
    call TriggerAddAction(t, function CF_DefeatPlayer_Trig_Actions)
endfunction

// Checks if a unit has a buff/ability
function CF_UnitHasAbility takes unit whichUnit, integer AbilRawcode returns boolean
    return (GetUnitAbilityLevel(whichUnit, AbilRawcode) > 0)
endfunction

// Add a ability to a unit with a level
function CF_UnitAddAbilityLevel takes unit whichUnit, integer AbilRawcode, integer level returns nothing
    if(not CF_UnitHasAbility(whichUnit, AbilRawcode)) then
        call UnitAddAbility(whichUnit, AbilRawcode)
    endif
    call SetUnitAbilityLevel(whichUnit, AbilRawcode, level)
endfunction

// Special Functions:-
//                    Consists of things that the standard W/E dosent not let you do.
//                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
// Effect
function CF_CreateGroundEffect takes real X, real Y, real Z, real facing, real sizeFactor, string modelPath, integer red, integer green, integer blue, integer alpha returns effect
    local effect NewEffect
    local unit CarryingUnit
    if(CF_IsLocSafe(X, Y)) then
        set CarryingUnit = CF_GetADummy(X, Y)
        set NewEffect = AddSpecialEffectTarget(modelPath, CarryingUnit, "origin")
        call SetUnitFlyHeight(CarryingUnit, Z, 0.)
        call SetUnitFacing(CarryingUnit, facing)
        call SetUnitScalePercent(CarryingUnit, sizeFactor, sizeFactor, sizeFactor) // This uses scaling factor.
                                                                                   // 1. would be the same size.
                                                                                   // 1.1 would be 10% bigger than
                                                                                   // usual.
                                                                                   // 2. would be 100% bigger than
                                                                                   // usual.
        call SetUnitVertexColor(CarryingUnit, red, green, blue, alpha)
        call CF_AttachHandle(CarryingUnit, "Effect_CarryingUnit", NewEffect)
        call CF_AttachReal(X, "Effect_XCoord", NewEffect)
        call CF_AttachReal(Y, "Effect_YCoord", NewEffect)
        call CF_AttachReal(Z, "Effect_ZCoord", NewEffect)
        call CF_AttachReal(facing, "Effect_FacingDegrees", NewEffect)
        call CF_AttachReal(sizeFactor, "Effect_Size", NewEffect)
        call CF_AttachInteger(red, "Effect_RedColour", NewEffect)
        call CF_AttachInteger(green, "Effect_GreenColour", NewEffect)
        call CF_AttachInteger(blue, "Effect_BlueColour", NewEffect)
        call CF_AttachInteger(alpha, "Effect_AlphaColour", NewEffect)
        call CF_AttachString(modelPath, "Effect_ModelPath", NewEffect)
        call CF_StoreHandle(NewEffect, "CF_MEMORY_LASTCREATED_EFFECT", "Effect")
        return NewEffect
    endif
    set NewEffect = null
    set CarryingUnit = null
    return null
endfunction

function CF_GetLastCreatedEffect takes nothing returns effect
    return CF_LoadEffect("CF_MEMORY_LASTCREATED_EFFECT")
endfunction

function CF_GetEffectCarryingUnit takes effect whichEffect returns unit
    return CF_GetAttachedUnit(whichEffect, "Effect_CarryingUnit")
endfunction

function CF_GetEffectX takes effect whichEffect returns real
    return CF_GetAttachedReal(whichEffect, "Effect_XCoord")
endfunction

function CF_GetEffectY takes effect whichEffect returns real
    return CF_GetAttachedReal(whichEffect, "Effect_YCoord")
endfunction

function CF_GetEffectZ takes effect whichEffect returns real
    return CF_GetAttachedReal(whichEffect, "Effect_ZCoord")
endfunction

function CF_GetEffectFacing takes effect whichEffect returns real
    return CF_GetAttachedReal(whichEffect, "Effect_FacingDegrees")
endfunction

function CF_GetEffectSize takes effect whichEffect returns real
    return CF_GetAttachedReal(whichEffect, "Effect_Size")
endfunction

function CF_GetEffectModelPath takes effect whichEffect returns string
    return CF_GetAttachedString(whichEffect, "Effect_ModelPath")
endfunction

function CF_GetEffectRedColour takes effect whichEffect returns integer
    return CF_GetAttachedInteger(whichEffect, "Effect_RedColour")
endfunction

function CF_GetEffectGreenColour takes effect whichEffect returns integer
    return CF_GetAttachedInteger(whichEffect, "Effect_GreenColour")
endfunction

function CF_GetEffectBlueColour takes effect whichEffect returns integer
    return CF_GetAttachedInteger(whichEffect, "Effect_BlueColour")
endfunction

function CF_GetEffectAlphaColour takes effect whichEffect returns integer
    return CF_GetAttachedInteger(whichEffect, "Effect_AlphaColour")
endfunction

function CF_IsEffectLocked takes effect whichEffect returns boolean
    if(CF_GetAttachedBoolean(whichEffect, "Effect_Locked")) then
        return true
    endif
    return false
endfunction

function CF_IsEffectInRect takes effect whichEffect, real minX, real minY, real maxX, real maxY returns boolean
    local real X = CF_GetEffectX(whichEffect)
    local real Y = CF_GetEffectY(whichEffect)
    if(X > minX) and (X < maxX) and (Y > minY) and (Y < maxY) then
        return true
    endif
    return false
endfunction

function CF_IsEffectInRectEx takes effect whichEffect, rect whichRect returns boolean
    local real X
    local real Y
    if(X > GetRectMinX(whichRect)) and (X < GetRectMaxX(whichRect)) and (Y > GetRectMinY(whichRect)) and (Y < GetRectMaxY(whichRect)) then
        return true
    endif
    return false
endfunction

function CF_IsEffectInRange takes effect whichEffect, real X, real Y, real radius returns boolean
    return IsUnitInRangeXY(CF_GetEffectCarryingUnit(whichEffect), X, Y, radius)
endfunction

function CF_IsEffectInRangeEx takes effect whichEffect, location whichLocation, real radius returns boolean
    return IsUnitInRangeXY(CF_GetEffectCarryingUnit(whichEffect), GetLocationX(whichLocation), GetLocationY(whichLocation), radius)
endfunction 

function CF_SetEffectX takes effect whichEffect, real X returns nothing
    if(CF_IsXSafe(X) and (CF_IsEffectLocked(whichEffect) == false)) then
        call SetUnitX(CF_GetEffectCarryingUnit(whichEffect), X)
        call CF_AttachReal(X, "Effect_XCoord", whichEffect)
    endif
endfunction

function CF_SetEffectY takes effect whichEffect, real Y returns nothing
    if(CF_IsYSafe(Y) and (CF_IsEffectLocked(whichEffect) == false)) then
        call SetUnitY(CF_GetEffectCarryingUnit(whichEffect), Y)
        call CF_AttachReal(Y, "Effect_YCoord", whichEffect)
    endif
endfunction

function CF_SetEffectLoc takes effect whichEffect, real X, real Y returns nothing
    local unit CarryingUnit = CF_GetEffectCarryingUnit(whichEffect)
    if(CF_IsLocSafe(X, Y) and (CF_IsEffectLocked(whichEffect) == false)) then
        call SetUnitX(CarryingUnit, X)
        call SetUnitY(CarryingUnit, Y)
        call CF_AttachReal(X, "Effect_XCoord", whichEffect)
        call CF_AttachReal(Y, "Effect_YCoord", whichEffect)
    endif
    set CarryingUnit = null
endfunction

function CF_SetEffectLocEx takes effect whichEffect, location whichLocation returns nothing
    call CF_SetEffectLoc(whichEffect, GetLocationX(whichLocation), GetLocationY(whichLocation))
endfunction

function CF_SetEffectZ takes effect whichEffect, real newZ returns nothing
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitFlyHeight(CF_GetEffectCarryingUnit(whichEffect), newZ, 0.)
        call CF_AttachReal(newZ, "Effect_ZCoord", whichEffect)
    endif
endfunction

function CF_SetEffectFacing takes effect whichEffect, real facing returns nothing
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitFacing(CF_GetEffectCarryingUnit(whichEffect), facing)
        call CF_AttachReal(facing, "Effect_FacingDegrees", whichEffect)
    endif
endfunction

function CF_SetEffectSize takes effect whichEffect, real sizeFactor returns nothing
    local real oldFactor = CF_GetEffectSize(whichEffect)
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitScalePercent(CF_GetEffectCarryingUnit(whichEffect), sizeFactor, sizeFactor, sizeFactor)
        call CF_AttachReal(oldFactor + sizeFactor - 1., "Effect_Size", whichEffect)
    endif
endfunction

function CF_EffectAddExpirationTime_Destroy takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local effect e = CF_GetAttachedEffect(t, "Timer_Expiration_Effect")
    call CF_DestroyTimer(t)
    call CF_DestroyEffect(e)
    set t = null
    set e = null
endfunction

function CF_EffectAddExpirationTime takes effect whichEffect, real time returns nothing
    local timer t = CreateTimer()
    if(CF_IsEffectLocked(whichEffect) == false) then
        call CF_AttachHandle(whichEffect, "Timer_Expiration_Effect", t)
        call TimerStart(t, time, false, function CF_EffectAddExpirationTime_Destroy)
    endif
endfunction

function CF_SetEffectColour takes effect whichEffect, integer red, integer green, integer blue, integer alpha returns nothing
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitVertexColor(CF_GetEffectCarryingUnit(whichEffect), red, green, blue, alpha)
    endif
endfunction

function CF_SetEffectRedColour takes effect whichEffect, integer red returns nothing
    local integer green = CF_GetEffectGreenColour(whichEffect)
    local integer blue = CF_GetEffectBlueColour(whichEffect)
    local integer alpha = CF_GetEffectAlphaColour(whichEffect)
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitVertexColor(CF_GetEffectCarryingUnit(whichEffect), red, green, blue, alpha)
    endif
endfunction

function CF_SetEffectGreenColour takes effect whichEffect, integer green returns nothing
    local integer red = CF_GetEffectRedColour(whichEffect)
    local integer blue = CF_GetEffectBlueColour(whichEffect)
    local integer alpha = CF_GetEffectAlphaColour(whichEffect)
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitVertexColor(CF_GetEffectCarryingUnit(whichEffect), red, green, blue, alpha)
    endif
endfunction

function CF_SetEffectBlueColour takes effect whichEffect, integer blue returns nothing
    local integer red = CF_GetEffectRedColour(whichEffect)
    local integer green = CF_GetEffectGreenColour(whichEffect)
    local integer alpha = CF_GetEffectAlphaColour(whichEffect)
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitVertexColor(CF_GetEffectCarryingUnit(whichEffect), red, green, blue, alpha)
    endif
endfunction

function CF_SetEffectAlphaColour takes effect whichEffect, integer alpha returns nothing
    local integer red = CF_GetEffectRedColour(whichEffect)
    local integer green = CF_GetEffectGreenColour(whichEffect)
    local integer blue = CF_GetEffectBlueColour(whichEffect)
    if(CF_IsEffectLocked(whichEffect) == false) then
        call SetUnitVertexColor(CF_GetEffectCarryingUnit(whichEffect), red, green, blue, alpha)
    endif
endfunction

function CF_CopyEffect takes effect whichEffect returns effect
    return CF_CreateGroundEffect(CF_GetEffectX(whichEffect), CF_GetEffectY(whichEffect), CF_GetEffectZ(whichEffect), CF_GetEffectFacing(whichEffect), CF_GetEffectSize(whichEffect), CF_GetEffectModelPath(whichEffect), CF_GetEffectRedColour(whichEffect), CF_GetEffectGreenColour(whichEffect), CF_GetEffectBlueColour(whichEffect), CF_GetEffectAlphaColour(whichEffect))
endfunction

function CF_CopyEffectLoc takes effect whichEffect, real X, real Y returns effect
    local effect e = CF_CopyEffect(whichEffect)
    local integer Ie = CF_H2I(e)
    call CF_SetEffectLoc(e, X, Y)
    set e = null
    return Ie
    return null
endfunction

function CF_CopyEffectLocEx takes effect whichEffect, location whichLocation returns effect
    return CF_CopyEffectLoc(whichEffect, GetLocationX(whichLocation), GetLocationY(whichLocation))
endfunction

function CF_LockEffect takes effect whichEffect returns nothing
    call CF_AttachBoolean(true, "Effect_Locked", whichEffect) // If a effect is locked, nothing can be changed,
                                                              // Only things like copy and getting values is
                                                              // possible.
endfunction

function CF_UnlockEffect takes effect whichEffect returns nothing
    call CF_AttachBoolean(false, "Effect_Locked", whichEffect) // Allows the effect to be changed again
endfunction

function CF_LockEffectEdit takes effect whichEffect, boolean lock returns nothing
    call CF_AttachBoolean(lock, "Effect_Locked", whichEffect)
endfunction

function CF_ShowEffectForPlayer takes effect whichEffect, player whichPlayer returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call ShowUnit(CF_GetEffectCarryingUnit(whichEffect), true)
    endif
endfunction

function CF_HideEffectForPlayer takes effect whichEffect, player whichPlayer returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call ShowUnit(CF_GetEffectCarryingUnit(whichEffect), false)
    endif
endfunction

function CF_DisplayEffectForPlayer takes effect whichEffect, player whichPlayer, boolean show returns nothing
    if(GetLocalPlayer() == whichPlayer) then
        call ShowUnit(CF_GetEffectCarryingUnit(whichEffect), show)
    endif
endfunction
    
// Lightning
function CF_CreateLightningGroundEffect takes real X1, real Y1, real Z1, real X2, real Y2, real Z2, string codeName, integer red, integer green, integer blue, integer alpha returns lightning
    local lightning NewLightning
    if(CF_IsLocSafe(X1, Y1) and CF_IsLocSafe(X2, Y2)) then
       set NewLightning = AddLightningEx(codeName, true, X1, Y1, Z2, X2, Y2, Z2)
       call SetLightningColor(NewLightning, red, green, blue, alpha)
       call CF_AttachReal(X1, "Lightning_CoordX1", NewLightning)
       call CF_AttachReal(Y1, "Lightning_CoordY1", NewLightning)
       call CF_AttachReal(Z1, "Lightning_CoordZ1", NewLightning)
       call CF_AttachReal(X2, "Lightning_CoordX2", NewLightning)
       call CF_AttachReal(Y2, "Lightning_CoordY2", NewLightning)
       call CF_AttachReal(Z2, "Lightning_CoordZ2", NewLightning)
       call CF_AttachString(codeName, "Lightning_CodeName", NewLightning)
       call CF_AttachInteger(red, "Lightning_RedColour", NewLightning)
       call CF_AttachInteger(green, "Lightning_GreenColour", NewLightning)
       call CF_AttachInteger(blue, "Lightning_BlueColour", NewLightning)
       call CF_AttachInteger(alpha, "Lightning_AlphaColour", NewLightning)
       return NewLightning
    endif
    set NewLightning = null
    return null
endfunction

function CF_GetLightningX1 takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_CoordX1")
endfunction

function CF_GetLightningY1 takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_CoordY1")
endfunction

function CF_GetLightningZ1 takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_CoordZ1")
endfunction

function CF_GetLightningX2 takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_CoordX2")
endfunction

function CF_GetLightningY2 takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_CoordY2")
endfunction

function CF_GetLightningZ2 takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_CoordZ2")
endfunction

function CF_GetLightningLoc1 takes lightning whichLightning returns location
    return Location(CF_GetLightningX1(whichLightning), CF_GetLightningY1(whichLightning))
endfunction

function CF_GetLightningLoc2 takes lightning whichLightning returns location
    return Location(CF_GetLightningX2(whichLightning), CF_GetLightningY2(whichLightning))
endfunction

function CF_GetLightningCenter takes lightning whichLightning returns location
    local location Loc1 = CF_GetLightningLoc1(whichLightning)
    local real X1 = CF_GetLightningX1(whichLightning)
    local real Y1 = CF_GetLightningY1(whichLightning)
    local real X2 = CF_GetLightningX2(whichLightning)
    local real Y2 = CF_GetLightningY2(whichLightning)
    local real angle = bj_RADTODEG * Atan2(Y2 - Y1, X2 - X1)
    local real distance = SquareRoot(X2 - X1 * X2 - X1 + Y2 - Y1 * Y2 - Y1)
    local real HDistance = distance / 2
    local real DestX = GetLocationX(Loc1) + HDistance * Cos(angle * bj_DEGTORAD)
    local real DestY = GetLocationY(Loc1) + HDistance * Sin(angle * bj_DEGTORAD)
    call RemoveLocation(Loc1)
    set Loc1 = null
    return Location(DestX, DestY)
endfunction    

function CF_GetLightningColourRed takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_RedColour")
endfunction

function CF_GetLightningColourGreen takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_GreenColour")
endfunction

function CF_GetLightningColourBlue takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_BlueColour")
endfunction

function CF_GetLightningColourAlpha takes lightning whichLightning returns real
    return CF_GetAttachedReal(whichLightning, "Lightning_AlphaColour")
endfunction

function CF_SetLightningToGround takes lightning whichLightning returns nothing
    local real X1 = CF_GetLightningX1(whichLightning)
    local real Y1 = CF_GetLightningY1(whichLightning)
    local real X2 = CF_GetLightningX2(whichLightning)
    local real Y2 = CF_GetLightningY2(whichLightning)
    call MoveLightningEx(whichLightning, true, X1, Y2, GetTerrainCliffLevel(X1, Y1), X2, Y2, GetTerrainCliffLevel(X2, Y2))
endfunction
07-27-2006, 12:24 PM#7
Blade.dk
I blame the desyncs on creating quests locally, as you said you were doing in the other thread.
07-27-2006, 12:49 PM#8
Toadcop
Ofc there are desync ! it's the same as to create a unit for GetLocalPlayer() or Destruct... thats all logicaly ! GetLocalPlayer() is very "Dangeres" to use !ofc for Lan games. =)
07-27-2006, 01:02 PM#9
Chuckle_Brother
Thats odd, because I thought Blade proved at one point that setting a variable(a local that is) locally was without issue.

Of course if the problem persists, Vile's method would work as well, just make sure the dummy unit sticks with the unit you want it "attached" to
07-27-2006, 01:06 PM#10
The)TideHunter(
You can set a variable localy, just not create 1.

This would work:

Collapse JASS:
...
    local string s
    if(GetLocalPlayer == SomePlayer) then
        set s = "Nobody can see this but me"
    else
        set s = "Aww, only that guy gets to see something secret"
    endif
    call DisplayEtcEtc(s)
...

This wouldent work:

Collapse JASS:
...
    local unit u
    if(GetLocalPlayer == SomePlayer) then
        set u = CreateUnit(etc)
    endif
...

EDIT: To put things in perspective, you cant create handles for 1 player.
07-27-2006, 02:13 PM#11
Chuckle_Brother
He wasn't, he was setting a local string locally.
07-27-2006, 02:39 PM#12
Blade.dk
Yeah, but in his other thread he was creating quest handles locally, and I blame the desyncs in his map on that. There's nothing wrong with the code posted in this thread.
07-27-2006, 02:50 PM#13
Linera
Well in the following map that i attached, they used create quest and its local quests.
Attached Files
File type: w3mElil's_Separate_Quest_Demo_v001.w3m (14.4 KB)