• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Jass and vJass Systems v1.0

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
some scripts in Jass and vJass.
NOTICE: the map is unless, because it only shows you the crep revive.

Includes:

Custom Value
Creep Revive
Groud Friction
Get Player String Color
Get Player Language
Fill String Into String (don't know if it works)
Create Shadow
Set Camera Target Controller With Ploar Offset
Damage Units In Range


i know the documentation is not very good ^^ but i made all varilabes good to understand.

if you found a leak or bug post it here.
hope this helps somebody :)

Keywords:
Creep Revive; Custom Value; Friction; Ground; Player Colour; Player Language; Replace String; Shadow; Camers Target Controler; Damage; Circle
Contents

Map Scripts (Map)

Reviews
18:49, 22nd Nov 2009 TriggerHappy187: I'm rejecting this permanently. There is nothing you can do to make this approvable. Ground Friction - Hashtable wrapper. Custom Value - Hashtable wrapper. CreepRevive - Nothing with vJass+Waits will...

Moderator

M

Moderator

18:49, 22nd Nov 2009
TriggerHappy187:

I'm rejecting this permanently. There is nothing you can do to make this approvable.

  • Ground Friction - Hashtable wrapper.
  • Custom Value - Hashtable wrapper.
  • CreepRevive - Nothing with vJass+Waits will get approved with me. This could also be extremely simplified.
  • Get Player String Color - PCU works far better than your color functions (check Jass Submission Area).
  • Get Player Language - Not even completed. This script was found on wc3jass anyways.
  • Repace String - Simple function, not a script/system.
  • Shadow - Cool, but I see no uses whatsoever.
  • Camera Target Controller With Ploar Offset - You can inline the setting of x/y. This is also not a system/snippet. It's merely a coding practice.
  • DamageUnitsInRange fails because..
    • Dynamic Groups.
    • You don't need to null damagedealer.
    • Indentation is horrible. (could be jass tags)
    • Uses firstofgroup loop.
    • Null filters leak (at least until 1.24c goes final).
    • You don't need to null u, it will end up null by the end of the loop
 
Code:

JASS:
library CreepRevive initializer CreepInit
    globals
        private constant integer EnemyPlayerId   = GetPlayerId(Player(PLAYER_NEUTRAL_AGGRESSIVE)) //the enemy player id
        private constant string  ReviveEffect  = "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl" //the effect at respawn
        private constant real    TimeTillRevive = 30.00 //time befor the units will respawn
    // ---------------- END OF SETTINGS ----------------
    // ---------- do not change anything below----------
        private filterfunc       filter
        private trigger          CreepReviveTrigger = CreateTrigger()
        private trigger          AddUnitToGroup     = CreateTrigger()
        private hashtable        ReviveHash         = InitHashtable()
        private group            EnemyUnits         = CreateGroup()
    endglobals
    
    private function TrueFilter takes nothing returns boolean
        return true //just a simple function that returns true
    endfunction 
            
    private function CreepRevive takes nothing returns nothing
        local unit u3 = GetTriggerUnit() //the dieing unit
        local unit u4
        if GetOwningPlayer(u3) == Player(EnemyPlayerId) then //cheks if the unit belongs to the enemy
            call PolledWait(TimeTillRevive) //waits
            // may i will replace it with timer uititles (or something like that :D)
            set u4 = CreateUnit(Player(EnemyPlayerId),LoadInteger(ReviveHash, GetHandleId(u3), 0),LoadReal(ReviveHash, GetHandleId(u3), 1),LoadReal(ReviveHash, GetHandleId(u3), 2),LoadReal(ReviveHash, GetHandleId(u3), 3))
            call GroupAddUnit(EnemyUnits, u4)
            //create the new unit and add it to the group
            call DestroyEffect(AddSpecialEffect(ReviveEffect,LoadReal(ReviveHash, GetHandleId(u3), 1),LoadReal(ReviveHash, GetHandleId(u3), 2)))
            //create the sfx
            //------------------------------------------------------------------------------
            call SaveInteger(ReviveHash,GetHandleId(u4), 0, LoadInteger(ReviveHash, GetHandleId(u3), 0))
            call SaveReal(ReviveHash,GetHandleId(u4), 1, LoadReal(ReviveHash, GetHandleId(u3), 1))
            call SaveReal(ReviveHash,GetHandleId(u4), 2, LoadReal(ReviveHash, GetHandleId(u3), 2))
            call SaveReal(ReviveHash,GetHandleId(u4), 3, LoadReal(ReviveHash, GetHandleId(u3), 3))
            call FlushChildHashtable(ReviveHash, GetHandleId(u3))
            //store unitId, x, y and facting of the unit in the hashtable and clear the all childs of the old unit
        endif
        set u3 = null
        set u4 = null
        //nulling
    endfunction
    
    private function NewUnitEnter takes nothing returns nothing
        local unit u = GetTriggerUnit()
        if GetOwningPlayer(u)==Player(EnemyPlayerId) and IsUnitInGroup( u, EnemyUnits) == false then
            call GroupAddUnit(EnemyUnits, u)
            call SaveInteger(ReviveHash,GetHandleId(u), 0, GetUnitTypeId(u))
            call SaveReal(ReviveHash,GetHandleId(u), 1, GetUnitX(u))
            call SaveReal(ReviveHash,GetHandleId(u), 2, GetUnitY(u))
            call SaveReal(ReviveHash,GetHandleId(u), 3, GetUnitFacing(u))
        endif
    endfunction
           
    private function CreepInit takes nothing returns nothing    
        local unit u3
        local group group1 = CreateGroup()
        set filter = Filter(function TrueFilter)
        call GroupEnumUnitsOfPlayer(group1, Player(EnemyPlayerId),filter)
        loop
            set u3 = FirstOfGroup(group1)
            call GroupAddUnit(EnemyUnits, u3)
            exitwhen u3 == null
            call SaveInteger(ReviveHash,GetHandleId(u3), 0, GetUnitTypeId(u3))
            call SaveReal(ReviveHash,GetHandleId(u3), 1, GetUnitX(u3))
            call SaveReal(ReviveHash,GetHandleId(u3), 2, GetUnitY(u3))
            call SaveReal(ReviveHash,GetHandleId(u3), 3, GetUnitFacing(u3))
            call GroupRemoveUnit(group1,u3)
            set u3 = null
        endloop
        call TriggerRegisterAnyUnitEventBJ(CreepReviveTrigger, EVENT_PLAYER_UNIT_DEATH )
        call TriggerAddAction(CreepReviveTrigger, function CreepRevive)
        call TriggerRegisterEnterRectSimple(AddUnitToGroup, GetPlayableMapRect() )
        call TriggerAddAction(AddUnitToGroup, function NewUnitEnter)
        set AddUnitToGroup = null
        set CreepReviveTrigger = null
        call DestroyGroup(group1)
        set group1 = null
    endfunction
endlibrary

JASS:
// this is not so usefull but i need it and decited to add it here
// can be may usefull for physik systems or arrow key moving
library GroudFriction initializer FrictionInit
    globals
        private hashtable FrictionHash = InitHashtable()
    endglobals
    
    function SetTitleFriction takes integer TitleId, real friction returns nothing
        call SaveReal(FrictionHash,TitleId,0,friction)
    endfunction
    
    function GetTitleFriction takes integer TitleId returns real
        return LoadReal(FrictionHash,TitleId,0)
        return 1.
    endfunction
    
    private function FrictionInit takes nothing returns nothing
        call SetTitleFriction('Ldrt',.96)
        call SetTitleFriction('Ldro',.98)
        call SetTitleFriction('Lgrd',.99)
    endfunction
endlibrary

JASS:
//=================================================================================
// a very short library to store integers to units (better version of UnitUserData)
// USE SetCustomValue(unit, slot, value) to store an integer
// use GetCustomValue(unit, slot) to get the integer
// you also can clear it with ClearCustomValue(unit) or 
// ClearCustomValueSimple(unit , slot) to clear the whole or one slot.
//=================================================================================

library CustomValue
    globals
        private hashtable CustomValueHash = InitHashtable()
    endglobals
    
    function SetCustomValue takes unit u, integer slot, integer value returns nothing
        call SaveInteger(CustomValueHash, GetHandleId(u), slot, value)
    endfunction
    
    function GetCustomValue takes unit u, integer slot returns integer
        return LoadInteger(CustomValueHash, GetHandleId(u), slot)
        return 0
    endfunction
    
    function ClearCustomValue takes unit u returns nothing
        call FlushChildHashtable(CustomValueHash, GetHandleId(u))
    endfunction
    
    function ClearCustomValueSimple takes unit u, integer slot returns nothing
        call SaveInteger(CustomValueHash, GetHandleId(u), slot, 0)
    endfunction
endlibrary

JASS:
function GetPlayerStringColor takes player p returns string
    local string array s
    local integer i = GetPlayerId(p)
        set s[0] = "|c00FF0000"
        set s[1] = "|c000000FF"
        set s[2] = "|c001CE6B9"
        set s[3] = "|c00540081"
        set s[4] = "|c00FFFC01"
        set s[5] = "|c00FEBA0E"
        set s[6] = "|c0020C000"
        set s[7] = "|c00E55BB0"
        set s[8] = "|c00959697"
        set s[9] = "|c007EBFF1"
        set s[10] = "|c00106246"
        set s[11] = "|c004E2A04"
        set s[12] = "|c00000000"
    set p = null
    if i > 11 or i < 0 then
        return s[12]
    endif
    return s[i]
endfunction

JASS:
// this returns the language of a player (you can add more :P)
function GetPlayerLanguage takes player p returns string
    local unit u = CreateUnit(Player(15),'hfoo',0,0,0)
    local string s
    local string ss = "English"
    if GetLocalPlayer() == p then
        set s = GetUnitName(u)
    endif
    call RemoveUnit(u)
    set u = null
    set p = null
        if s =="Soldat" then
            set ss= "German"
        //elseif s == "???" then
            //set ss="???"
        //........
        endif
    return ss
endfunction

JASS:
function FillStringIntoString takes string BasicText, string FillInText, string Symbol returns string
    local integer i = 0
    local string s
    loop
        exitwhen i >= StringLength(BasicText)
        if SubString (BasicText,i-1,i) == Symbol then
            set s = s + FillInText
        else
            set s = s + SubString (BasicText,i-1,i)
        endif
        set i = i+1
    endloop
    return s
endfunction

JASS:
// creates a "shadow" on the ground.
// can be useful for missle systems
function CreateShadow takes real x, real y, real size returns image
	local image img
    if size == 0. then
        return null
	endif
	set img = CreateImage("ReplaceableTextures\\Shadows\\ShadowFlyer.blp", size, size, size, x-size*.5, y-size*.5, 0, 0, 0, 0, 2)
	call SetImageColor(img,255,255,255,190)
	call SetImageRenderAlways( img, true )
	call ShowImage(img, true)
	return img
endfunction

JASS:
// lock the camera to a unit with an offset
function SetCameraTargetControllerWithPloarOffset takes player p, unit u, real offset, real angle returns nothing
    local real x
    local real y
    set x = Cos(angle * bj_DEGTORAD) * offset
    set y = Sin(angle * bj_DEGTORAD) * offset
    if GetLocalPlayer()==p then
        call SetCameraTargetController(u,x,y,false)
    endif
endfunction

JASS:
// damages all units i a circle
function DamageUnitsInRange takes real x, real y, real z, real damage, unit damagedealer, real range returns nothing
    local group g = CreateGroup()
    local unit u= null
    local real array r
    call GroupEnumUnitsInRange(g,x, y, range, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if GetOwningPlayer(u) != GetOwningPlayer(damagedealer) then
            set r[0] = x - GetUnitX(u)
            set r[1] = y - GetUnitY(u)
            set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
            set r[3] = GetUnitFlyHeight(u)-z
            set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
            if r[4] <= range then
                call UnitDamageTarget(damagedealer, u, damage, true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            endif
        endif
        call GroupRemoveUnit(g,u)
        set u = null
    endloop
    call DestroyGroup(g)
    set damagedealer = null
    set g 	         = null
    set u 	         = null
endfunction
 
Level 14
Joined
Nov 18, 2007
Messages
816
Very very good job,
I beg to differ.
GetPlayerId(Player(PLAYER_NEUTRAL_AGGRESSIVE))==PLAYER_NEUTRAL_AGGRESSIVE

Use structs + (Handle)Table to attach things.

People who use |c00RRGGBB need to die. If WC3 worked the way youd expect it to, youd see no text at all. Besides, GetPlayerStringColor is horribly inefficient.

GetPlayerLanguage is...neigh useless.

DamageUnitsInRange is, too. Use xedamage instead.
 
Top