Worldedit
  Worldedit
Le site sur l'éditeur de warcraft 3 !
 
  FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres    Groupes d'utilisateursGroupes d'utilisateurs   medals.php?sid=47971c8dc13531004f53b0be6ea1c02bMédailles   S'enregistrerS'enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 
  FAQFAQ World Editor   UploadUploader une map ou une image    UploadAjouter sa map à l'annuaire   UploadConsulter l'annuaire

[vJass] library ConstructionStatus

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Fonction Jass
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 Troll-Brain
Ri1kamoua


Inscrit le: 23 Aoû 2007
Messages: 7143
Sujets: 147
Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance
Médailles: 2 (En savoir plus...)
Grand mage créateur de sort (Quantité : 1) Rédacteur de tuto #3 (Quantité : 1)

MessagePosté le: 12/04/09 18:56    Sujet du message: [vJass] library ConstructionStatus Citer

Créateur : Troll-Brain
Librairie requise : GroupUtils
Code :
Jass:
library ConstructionStatus initializer init uses GroupUtils

globals
    private constant real TIME_OUT = 30.0 // It is the periodic time (seconds) which the group will be refreshed (ghost units are removed)
endglobals

//==============================================================================
//  ConstructionStatus -- by Troll-Brain -- v 1.2
//==============================================================================
//
//  PURPOUSE:
//       * To know if an unit is finished, or being built/upgraded
//       * Note that it doesn't care about trained units, but ofc a trained unit will be considered as finished
//
//  HOW TO USE:
//       * function IsUnitFinished takes unit u returns boolean
//       * function IsUnitBeingBuilt takes unit u returns boolean
//       * function IsUnitBeingUpgraded takes unit u returns boolean
//
//       * Note that these 3 functions will return false if the unit is dead or not valid (for example == null)
//
//  PROS:
//       * Easy to use, can be done in a single custom script for gui users
//         
//  CONS:
//       * It will fail if the unit has an usable revive ability if the unit die during the upgrade or construction
//       * I could handle it thought, let me know if you have the use of it, but then you have to know that it will require more stuff
//
//  DETAILS:
//       * I simply catch construct and upgrade events
//
//  THANKS TO:
//       * Rising_Dusk : to tell me that i've forgotten the upgraded units
//       * grim001 : for more sexy functions/library names

//
//  HOW TO IMPORT:
//       * Just create a trigger named ConstructionStatus
//       * convert it to text and replace the whole trigger text with this one
//       * Do the same for the library GroupUtils if you don't already use it
//
//==============================================================================

globals
    private group BeingBuiltUnits
    private group BeingUpgradedUnits
endglobals

function IsUnitFinished takes unit u returns boolean
    return GetUnitTypeId(u) != 0 and not IsUnitType(u,UNIT_TYPE_DEAD) and not IsUnitInGroup(u,BeingBuiltUnits) and not IsUnitInGroup(u,BeingUpgradedUnits)
endfunction

function IsUnitBeingBuilt takes unit u returns boolean
    return not IsUnitType(u,UNIT_TYPE_DEAD) and IsUnitInGroup(u,BeingBuiltUnits)
endfunction

function IsUnitBeingUpgraded takes unit u returns boolean
    return not IsUnitType(u,UNIT_TYPE_DEAD) and IsUnitInGroup(u,BeingUpgradedUnits)
endfunction

private function HandleUnits takes nothing returns boolean
   
    if GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_START then
        call GroupAddUnit(BeingBuiltUnits,GetConstructingStructure())
       
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_CONSTRUCT_FINISH then
        call GroupRemoveUnit(BeingBuiltUnits,GetConstructedStructure())
       
    elseif GetTriggerEventId() == EVENT_PLAYER_UNIT_UPGRADE_START then
        call GroupAddUnit(BeingUpgradedUnits,(GetTriggerUnit()))
       
    else
        call GroupRemoveUnit(BeingUpgradedUnits,GetTriggerUnit())
    endif

    return false
endfunction

private function RefreshGroup takes nothing returns nothing
    call GroupRefresh(BeingBuiltUnits)
    call GroupRefresh(BeingUpgradedUnits)
endfunction

private function init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local timer tim = CreateTimer()

    set BeingBuiltUnits = NewGroup()
    set BeingUpgradedUnits = NewGroup()
    call TimerStart(tim,TIME_OUT,true,function RefreshGroup)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_CONSTRUCT_START)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_UPGRADE_START)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_UPGRADE_FINISH)
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_UPGRADE_CANCEL)
    call TriggerAddCondition(trig,Condition(function HandleUnits))
   
    // unneeded but i tend to null all handles, even if it is never destroyed
    set trig = null
    set tim = null
endfunction

//==============================================================================
//  CHANGELOG
//==============================================================================
//
//  v 1.2 :
//       * IsUnitFinished return false instead of true when the unit argument is not valid.
//
//  v 1.1 :
//       * It handles upgrading units as well, so IsUnitBeingUpgraded is added
//
//  v 1.0 :
//       * Since the initial release didn't handle morphed units and units created by trigger,
//       * i've fixed that
//
//  v 0.1 :
//       * Initial release

endlibrary

Jass:
function IsUnitBeingBuilt takes unit u returns boolean

Jass:
function IsUnitBeingUpgraded takes unit u returns boolean

Copyright : Libre
Remarques : Les fonctions retournent false si l'unité est morte ou non valide (null par exemple).
_________________


Dernière édition par Troll-Brain le 04/08/09 17:42; édité 5 fois
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Fonction Jass Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1

 
Sauter vers:  
Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum


Powered by phpBB © 2001, 2005 phpBB Group
Traduction par : phpBB-fr.com