Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[ vJASS ] About Spawn Unit No New Posts General Jass Discussion

Started by
LembidiZ

0 Members and 1 Guest are viewing this topic.

[ vJASS ] About Spawn Unit
on: June 16, 2013, 05:53:54 AM

How do I make:

Quote
-Spawn ( The Unit ID ) ( Value )

Spawn unit with entered unit ID, you can set how much the spawned unit



[ vJASS ] About Spawn Unit
Reply #1 on: June 16, 2013, 12:33:09 PM

Do you want it as a chat command??


[ vJASS ] About Spawn Unit
Reply #2 on: June 16, 2013, 07:24:33 PM

Of course - .. -
Oh I want it vJASS :3 :3 Because it's neat and cute :3 :3



[ vJASS ] About Spawn Unit
Reply #3 on: June 19, 2013, 07:40:28 AM

Ok, working in a idea, but the part of using unitid to call the unit requires more time.  Could it be:

Quote
-spawn 5 Knights
So we can use the formal name?? I thinkit could be easier


[ vJASS ] About Spawn Unit
Reply #4 on: June 21, 2013, 02:35:15 AM

No, I want id Unit ID
I had listed the Unit on the quest :D :D



Re: [ vJASS ] About Spawn Unit
Reply #5 on: August 31, 2015, 12:41:40 PM

Well, you're going to need to figure out where to put them. Do you have a designated location for each player or do you want to base it off of the current location of a unit, or what? You didn't provide much information. Also, are you trying to make it so units will revive even though they aren't heroes, like in a more traditional RPG, or are you simply trying to create units once?



Re: [ vJASS ] About Spawn Unit
Reply #6 on: March 10, 2016, 01:48:14 AM

sorry bump, it's been a long time, i've been quite busy, anyway, please help me with these :3 :3
-spawn (Unit ID, not formal name!) (amounts, if not entered, just spawn it one)



Re: [ vJASS ] About Spawn Unit
Reply #7 on: March 10, 2016, 02:12:56 PM

Have you tried the S2I function?



Re: [ vJASS ] About Spawn Unit
Reply #8 on: March 10, 2016, 03:26:04 PM

You have still to convert the string in a valid integer.
It can be done of course, but it's not straight forward, for example 'hpea' (human peasant) is not a decimal base.
Hopefully there is already a resource for that :
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-ascii-190746/

Ok, here we go :

Code: jass
  1. library SpawnUnitByChat requires Ascii initializer init
  2.  
  3.    globals
  4.       private constant string KEY = "-spawn"
  5.       private constant player PLAYER = Player(0) // first player (red)
  6.       private constant real X = 0
  7.       private constant real Y = 0
  8.    endglobals
  9.  
  10.    private function Actions takes nothing returns nothing
  11.       local string chat = GetEventPlayerChatString()
  12.       local integer i = -1
  13.       local string s = ""
  14.       local string unitid = ""
  15.       local string count = ""
  16.      
  17.       chat = SubString(chat,StringLength(KEY)+1,StringLength(chat))
  18.       loop
  19.       set i = i+1
  20.       set s = SubString(chat,i,i+1)
  21.       exitwhen s == " " or s == null
  22.          set unitid = unitid+s
  23.       endloop
  24.  
  25.       loop
  26.       set i = i+1
  27.       set s = SubString(chat,i,i+1)
  28.       exitwhen s == " " or s == null
  29.          set count= count+s
  30.       endloop
  31.      
  32.       set i = S2I(count)
  33.       loop
  34.       set i = i-1
  35.          call CreateUnit(PLAYER,S2A(unitid),X,Y,0)
  36.       exitwhen i <= 0
  37.       endloop
  38.      
  39.    endfunction
  40.  
  41.    private function init takes nothing returns nothing
  42.        local trigger trig = CreateTrigger()
  43.  
  44.        call TriggerRegisterPlayerChatEvent(trig,PLAYER,KEY,false)
  45.        call TriggerAddAction(trig,function Actions)
  46.    endfunction
  47.  
  48. endlibrary

Note that i've written the code directly here, not tested, it could have errors, also you need to follow exactly this pattern :
-spawn unitid X

Where X is the numbers of units (optional).
We could improve the script and allow or not more spaces between the arguments, and add safety, but oh well i have not found an interesting string parsing library, so meh ...
« Last Edit: March 10, 2016, 04:55:51 PM by Troll-Brain »

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: [ vJASS ] About Spawn Unit
Reply #9 on: March 11, 2016, 06:46:24 PM

Now since i've the JNGP again, i've tried and fixed the two syntax errors.
The code seems to work as it should, after a short test with these commands :

-spawn hfoo 3
-spawn hpea

Code: jass
  1.     library SpawnUnitByChat initializer init requires Ascii
  2.      
  3.        globals
  4.           private constant string KEY = "-spawn"
  5.           private constant player PLAYER = Player(0) // first player (red)
  6.           private constant real X = 0
  7.           private constant real Y = 0
  8.        endglobals
  9.      
  10.        private function Actions takes nothing returns nothing
  11.           local string chat = GetEventPlayerChatString()
  12.           local integer i = -1
  13.           local string s = ""
  14.           local string unitid = ""
  15.           local string count = ""
  16.          
  17.           set chat = SubString(chat,StringLength(KEY)+1,StringLength(chat))
  18.           loop
  19.           set i = i+1
  20.           set s = SubString(chat,i,i+1)
  21.           exitwhen s == " " or s == null
  22.              set unitid = unitid+s
  23.           endloop
  24.      
  25.           loop
  26.           set i = i+1
  27.           set s = SubString(chat,i,i+1)
  28.           exitwhen s == " " or s == null
  29.              set count= count+s
  30.           endloop
  31.          
  32.           set i = S2I(count)
  33.           loop
  34.           set i = i-1
  35.              call CreateUnit(PLAYER,S2A(unitid),X,Y,0)
  36.           exitwhen i <= 0
  37.           endloop
  38.          
  39.        endfunction
  40.      
  41.        private function init takes nothing returns nothing
  42.            local trigger trig = CreateTrigger()
  43.      
  44.            call TriggerRegisterPlayerChatEvent(trig,PLAYER,KEY,false)
  45.            call TriggerAddAction(trig,function Actions)
  46.        endfunction
  47.      
  48.     endlibrary

Enjoy :)

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: [ vJASS ] About Spawn Unit
Reply #10 on: March 12, 2016, 03:20:10 AM

Now since i've the JNGP again, i've tried and fixed the two syntax errors.
The code seems to work as it should, after a short test with these commands :

-spawn hfoo 3
-spawn hpea

Code: jass
  1.     library SpawnUnitByChat initializer init requires Ascii
  2.      
  3.        globals
  4.           private constant string KEY = "-spawn"
  5.           private constant player PLAYER = Player(0) // first player (red)
  6.           private constant real X = 0
  7.           private constant real Y = 0
  8.        endglobals
  9.      
  10.        private function Actions takes nothing returns nothing
  11.           local string chat = GetEventPlayerChatString()
  12.           local integer i = -1
  13.           local string s = ""
  14.           local string unitid = ""
  15.           local string count = ""
  16.          
  17.           set chat = SubString(chat,StringLength(KEY)+1,StringLength(chat))
  18.           loop
  19.           set i = i+1
  20.           set s = SubString(chat,i,i+1)
  21.           exitwhen s == " " or s == null
  22.              set unitid = unitid+s
  23.           endloop
  24.      
  25.           loop
  26.           set i = i+1
  27.           set s = SubString(chat,i,i+1)
  28.           exitwhen s == " " or s == null
  29.              set count= count+s
  30.           endloop
  31.          
  32.           set i = S2I(count)
  33.           loop
  34.           set i = i-1
  35.              call CreateUnit(PLAYER,S2A(unitid),X,Y,0)
  36.           exitwhen i <= 0
  37.           endloop
  38.          
  39.        endfunction
  40.      
  41.        private function init takes nothing returns nothing
  42.            local trigger trig = CreateTrigger()
  43.      
  44.            call TriggerRegisterPlayerChatEvent(trig,PLAYER,KEY,false)
  45.            call TriggerAddAction(trig,function Actions)
  46.        endfunction
  47.      
  48.     endlibrary

Enjoy :)
Woah!! Thank you so much <3 <3
Trying.....

EDIT:
WOW IT WORKS LIKE A CHARM!!
THANK YOU SO MUCH MUCH WE DO!!
Thread Closed :3 :3
« Last Edit: March 12, 2016, 03:32:59 AM by LembidiZ »



Re: [ vJASS ] About Spawn Unit
Reply #11 on: March 12, 2016, 05:00:08 AM

um.. One last question, sorry damn.
How to make spawned units patrol to random points?



Re: [ vJASS ] About Spawn Unit
Reply #12 on: March 12, 2016, 06:24:08 AM

um.. One last question, sorry damn.
How to make spawned units patrol to random points?

That will be the anarchy :s

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: [ vJASS ] About Spawn Unit
Reply #13 on: March 19, 2016, 06:30:06 AM

That will be the anarchy :s

haha thanks anyway :D :D
You really save me ;D ;D



 

Started by Chriz.

Replies: 0
Views: 4815
Warcraft III Models

Started by Kuhneghetz

Replies: 0
Views: 2482
Warcraft III Models

Started by Callahan

Replies: 0
Views: 5202
Warcraft III Models

Started by moyack

Replies: 2
Views: 6131
WC3 Editing Tools

Started by TeslaTrooper

Replies: 4
Views: 9000
Starcraft 2 modding
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...