Hero + Item Snippets

Status
Not open for further replies.
I

IKilledKEnny

Guest
Submissions

Hey I made this quick system to help people get players allied when they type massage with 2 triggers only. Map is attached if you don't want to read the Triggers and explanation. :D

http://www.thehelper.net/forums/showthread.php?t=52027


Things needed:
  • Warcraft III: The Frozen Throne (Expansion).​

Variables:
  • 1 Player Group variable no array (AllyPF)
  • 2 String variables with array equal to maximum num of players (12)(AllyStringColor, AllyStringName)
  • Integer Variable no array (Integer)

Code:
Setting Up Triggers
    Events
        Map initialization
    Conditions
    Actions
        Set AllyPF = (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing)))
        Player Group - Pick every player in AllyPF and do (Actions)
            Loop - Actions
                Set AllyStringName[(Player number of (Picked player))] = (Name of (Picked player))
                Trigger - Add to Actual Trigger <gen> the event (Player - (Picked player) types a chat message containing -Ally  as A substring)
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Red
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Blue
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Teal
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Purple
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Yellow
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Orange
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Green
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Pink
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Grey
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Light Blue
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Dark Green
        Set Integer = (Integer + 1)
        Set AllyStringColor[Integer] = Brown
        Custom script:   call DestroyForce(udg_AllyPF)
        Custom script:   call DestroyTrigger(GetTriggeringTrigger())

Code:
Actual Trigger
    Events
    Conditions
    Actions
        For each (Integer A) from 1 to 12, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Or - Any (Conditions) are true
                            Conditions
                                (Integer((Substring((Entered chat string), 7, 8)))) Equal to (Integer A)
                                (Substring((Entered chat string), 7, 22)) Equal to AllyStringName[(Integer A)]
                                (Substring((Entered chat string), 7, 17)) Equal to AllyStringColor[(Integer A)]
                    Then - Actions
                        Player - Make (Triggering player) treat (Player((Integer A))) as an Ally with shared vision
                    Else - Actions

What it would do, is in just 17.4 KB / 4 MB 3 things:
A.
When player writes: -Ally Num
He'll ally immediatly with the player that is that number (example: "-ally 3", player will immediatly ally with teal".

B.
When player writes: -Ally Color
He'll immediatly ally with the player that is that color. (Example: "-ally teal", player will immediatly ally with teal).

C.
When player writes: -Ally Name
He'll immediatly ally with that player that has that name (Example"-Ally TealLover" Assuming teal got this name player would ally with him).

Hope you enjoyed, move this theard if needed. Feedback is welcomed.

http://www.thehelper.net/forums/showthread.php?t=52027
 

Attachments

  • Simple Ally System ~IKilledKEnny~.w3x
    17.4 KB · Views: 342

DuckieKing

Elitist Through and Through
Reaction score
51
I was asked to repost my script with more comments, so here goes! (Be sure to read the comments on function FindHost_Cache first!)
JASS:
function FindHost takes nothing returns nothing
  local integer a=0
  set udg_Host=Player(0)  // sets host to red, to start us off
  loop
    exitwhen a&gt;11
    if udg_HostCheck[GetPlayerId(udg_Host)]&lt;udg_HostCheck[a] then  // checks if the current global player Host has fewer &quot;host credits&quot; than the player being looped
      set udg_Host=Player(a)  // if the looped player has more &quot;host credits&quot; than the current global player Host, the looped player is set as the new Host
    endif
  set a=a+1
  endloop
endfunction

function FindHost_Cache takes nothing returns nothing
  local gamecache gc=InitGameCache(&quot;temp.w3v&quot;)
  local integer a=0
  local integer b
  loop  // this loop is required, because this script is not reliable unless done many times; with some (slow) hosts it will fail 1/3 of the time
    exitwhen a&gt;9
    call StoreInteger(gc, &quot;map&quot;, &quot;host&quot;, GetPlayerId(GetLocalPlayer()))  // this stores for every player their own player Id, so it&#039;s different for every player...
    call TriggerSyncStart()
    call SyncStoredInteger(gc, &quot;map&quot;, &quot;host&quot;)  // so we sync it up, and most of the time it will sync to the HOST&#039;S PLAYER ID
    call TriggerSyncReady()
    set b=GetStoredInteger(gc, &quot;map&quot;, &quot;host&quot;)  // we set b to the variable synced by the last few lines
    set udg_HostCheck<b>=udg_HostCheck<b>+1  // this line gives the person whose Id is &#039;b&#039; one &quot;host credit&quot;
    set a=a+1
  endloop
  call ExecuteFunc(&quot;FindHost&quot;)  // starts the function that sets the host, go to function FindHost
  call FlushGameCache(gc)  // taking care of leaks, not totally necessary as this runs only once, ideally
  set gc=null  // and this line saves less than 1kb, but we like to remove all leaks
endfunction

function InitTrig_FindHost takes nothing returns nothing
  set gg_trg_FindHost=CreateTrigger()
  call TriggerRegisterTimerEvent(gg_trg_FindHost, 0.00, false)
  call TriggerAddAction(gg_trg_FindHost, function FindHost_Cache)
endfunction</b></b>


Add a trigger: FindHost
Make it custom script (Edit/Convert to Custom Text)
Add two globals: Player "Host" and integer array "HostCheck"
This is not perfect and in extreme cases it will fail. You can increase the number of loops to be even surer, but it does have some kind of delay. With 10 loops it tends to take about 5 seconds or less.
Note that although I wrote the actual script, the idea to sync local players' Ids was given to me by the shaman of Clan BoM.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Here is a little JASS sniplet, which counts how many items of same type a certain unit has. Useful, if you want to make item recipes, which require more than one instance of a certain item.

function CountSameItems takes unit a, item t returns integer

Place this into your maps header.

JASS:
function CountSameItems takes unit a, item t returns integer
    local integer p = UnitInventorySize(a)
    local integer i = 0
    local integer h = 0
    loop
        exitwhen i &gt; p
        if ( GetItemTypeId(UnitItemInSlot( a, i )) == GetItemTypeId(t) ) then
            set h = h + 1
        endif
        set i = i + 1
    endloop
    return h
endfunction


And use "Custom script" action to call it.

TmpInt
- global integer variable.

Code:
Count Items
    Events
        Unit - A unit Acquires an item
    Conditions
        (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
    Actions
        Custom script:   set udg_TmpInt = CountSameItems( GetTriggerUnit(),  GetManipulatedItem() )
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                TmpInt Equal to 3
            Then - Actions
                For each (Integer A) from 1 to 3, do (Actions)
                    Loop - Actions
                        Item - Remove (Item carried by (Triggering unit) of type Claws of Attack +15)
                Hero - Create Claws of Attack +50 and give it to (Triggering unit)
            Else - Actions
 

Vulcansurge

Ultra Cool Member
Reaction score
27
ITEM UPGRADING SYSTEM - By Vulcansurge

Custom Script:
Code:
function PlayerMsg takes player p, string s returns nothing
  call DisplayTextToPlayer(p,0,0,s)
endfunction

Actual Trigger:
JASS:
//============================================================================
//                              BASIC LASER
//============================================================================
function Trig_UpgradeBasicLaserJASS_Actions takes nothing returns nothing
  local integer l = 0
  local unit u = GetManipulatingUnit()
  local item i = GetManipulatedItem()
  local player p = GetOwningPlayer(u)
  local item iu

  local integer ut = 5    //UT = TOTAL UPGRADES:
  local integer array uc  //  - make sure to copy more rawcodes when
  local integer array ul  //    adding more or less upgrades.
    set ul[1]=&#039;I00H&#039;      //
    set ul[2]=&#039;I00D&#039;      //UL = ITEM RAWCODES:
    set ul[3]=&#039;I00E&#039;      //  - use ctrl + d in item editor to find these.
    set ul[4]=&#039;I00F&#039;      //  - must use &quot;I00X&quot; format.
    set ul[5]=&#039;I00G&#039;      //
    set uc[1]=700         //UC = UPGRADE COSTS:
    set uc[2]=800         //  - there should be one less than the total
    set uc[3]=900         //    number of levels, because the last level
    set uc[4]=1000        //    is not upgradeable.

  loop
  set l=l+1
  exitwhen l==ut
  if (GetItemTypeId(i)==ul[l]) then
    if (GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)&gt;=uc[l]) then
      call AdjustPlayerStateBJ(-uc[l],p, PLAYER_STATE_RESOURCE_GOLD)
      call PlayerMsg(p,&quot;|cFF0000FFNote:|r Your item is being upgraded&quot;)
      call UnitRemoveItemSwapped(i,u)
      call RemoveItem(i)
      call UnitAddItemByIdSwapped(&#039;I00C&#039;,u)
      set iu = GetLastCreatedItem()
      call TriggerSleepAction(10.00)
      call UnitRemoveItemSwapped(iu,u)
      call RemoveItem(iu)
      call UnitAddItemByIdSwapped(ul[(l+1)],u) 
    else
      call PlayerMsg(p,&quot;|cFF0000FFNote:|r You need more gold to upgrade this item&quot;)
    endif
  endif
  endloop 
endfunction
//===========================================================================
function InitTrig_UpgradeBasicLaserJASS takes nothing returns nothing
    set gg_trg_UpgradeBasicLaserJASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_UpgradeBasicLaserJASS, EVENT_PLAYER_UNIT_USE_ITEM )
    call TriggerAddAction( gg_trg_UpgradeBasicLaserJASS, function Trig_UpgradeBasicLaserJASS_Actions )
endfunction


Test Map:
 

Attachments

  • ItemUpgrader - System Testmapv2.w3x
    22.7 KB · Views: 338
S

Storm

Guest
[System] My Item Stack

My Item Stack​
This is triggered when a unit picks up or buys an item with the classification "Purchasable," but does not work if the inventory is full. Certain permanent items, such as "Claws of Attack", are not meant to be stacked, and may bug you game up if you try to stack them :p

NAME THE TRIGGER "Stack Items" FOR THIS TO WORK IF YOU ARE GOING TO COPY + PASTE!!!

JASS:

function Trig_Stack_Items takes nothing returns nothing
local integer a = 0
local item i = GetManipulatedItem()
local item m
if (GetItemType(i) != ITEM_TYPE_PERMANENT) then
    loop
    exitwhen a &gt; 5
        set m = UnitItemInSlot(GetTriggerUnit(),a)
        if (( GetItemTypeId(m) == GetItemTypeId(i)) and (m != i)) then
        call SetItemCharges(m,(GetItemCharges(m) + GetItemCharges(i)))
        call RemoveItem(i)
        endif
    set a = a + 1
    endloop
endif
endfunction

//===========================================================================
function InitTrig_Stack_Items takes nothing returns nothing
set gg_trg_Stack_Items = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Stack_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_Stack_Items, function Trig_Stack_Items )
endfunction

Edit: Changed functions. Updated Map file.
If there's anything wrong with this trigger please tell.
Demo:
 

Attachments

  • ItemStacking.w3x
    12.4 KB · Views: 314
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top