Jass Questions.

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Jass Questions.

Post by weirdone2 »

Alrite im'a go ahead make a quick lil key info thing. :P

Tid Bits of Info!
-Global array takes up 32kb, ouchies. -from Aero
-When using groups make sure to clear the units, destroy group, null group. -from HINDYhat
-To convert unittype Click here. -from HINDYhat

Systems

Aero's allying system=

Code: Select all

function GetBaseLength takes string s returns string
if SubString(s,0,5)=="-ally"then
return"5a"
elseif SubString(s,0,7)=="-unally"then
return"7b"
elseif SubString(s,0,7)=="-vision"then
return"7c"
elseif SubString(s,0,9)=="-unvision"then
return"9d"
endif
return""
endfunction

function AllyExecute takes nothing returns nothing
local integer i=0
local player p=GetTriggerPlayer()   
local integer id=GetPlayerId(p)
local string s=GetEventPlayerChatString()
local string l=GetBaseLength(StringCase(s,false))
local string array n
local player t
if l!=""then
set i=S2I(SubString(l,0,1))+1
set l=SubString(l,1,2)
else
set p=null
return
endif
set n[0]="red"
set n[1]="blue"
set n[2]="teal"
set n[3]="purple"
set n[4]="yellow"
set n[5]="orange"
set n[6]="green"
set n[7]="pink"
set n[8]="gray"
set n[9]="light blue"
set n[10]="dark green"
set n[11]="brown"
set n[12]=StringCase(SubString(s,i,i+10),false)
set n[13]=""
set i=0
loop
if n[i]==n[12]then
set n[0]="exit"
endif
exitwhen n[0]=="exit"
set i=i+1
endloop
set t=Player(i)
if id==i then
call DisplayTextToPlayer(p,0,0,"You can't perform Alliance Operations with yourself!")
elseif i>11then
call DisplayTextToPlayer(p,0,0,"Invalid player color.")
elseif (l=="a")and(not GetPlayerAlliance(p,t,ALLIANCE_PASSIVE))then
call SetPlayerAllianceStateAllyBJ(p,t,true)
set n[13]=GetPlayerName(p)+" is now allies with "+GetPlayerName(t)
elseif (l=="b")and(GetPlayerAlliance(p,t,ALLIANCE_PASSIVE))then
call SetPlayerAllianceStateAllyBJ(p,t,false)
set n[13]=GetPlayerName(p)+" is now enemies with "+GetPlayerName(t)
elseif (l=="c")and(not GetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION))then
call SetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION,true)
set n[13]=GetPlayerName(p)+" is now sharing vision with "+GetPlayerName(t)
elseif (l=="d")and(GetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION))then
call SetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION,false)
set n[13]=GetPlayerName(p)+" is no longer sharing vision with "+GetPlayerName(t)
endif
call DisplayTextToPlayer(GetLocalPlayer(),0,0,n[13])
set p=null
set t=null
endfunction

//=======================================================================
function InitTrig_AllySystem takes nothing returns nothing
local integer i=0
local trigger t=CreateTrigger()
loop
exitwhen i>11
call TriggerRegisterPlayerChatEvent(t,Player(i),"-",false)
set i=i+1
endloop
call TriggerAddAction(t,function AllyExecute)
set t=null
endfunction
Aero's get multiple units system=

Code: Select all

function func takes nothing returns nothing
local integer i=1747988528 //unit type know idea how to figure out yet
local group g=CreateGroup()
local player p=Player(15)
loop
exitwhen i>1747988532
set bj_groupEnumTypeId=i
call GroupEnumUnitsOfPlayer(g,p,filterGetUnitsOfPlayerAndTypeId)
set bj_ghoul[i-1747988428]=FirstOfGroup(g)
call GroupClear(g)
set i=i+1
endloop
call DestroyGroup(g)
set g=null
set p=null
endfunction
Looks like Aero has contributed the most, way to look out m8t. ^^

Orginal Post
weirdone2 wrote:I'm having some trouble with my allying system so is it possible to convert color to string? Heres my code

Code: Select all

function Trig_ally_Actions takes nothing returns nothing
local string s=GetEventPlayerChatString()
local player p=GetTriggerPlayer()
local integer i=StringLength(s)
local string splayers=GetPlayerColor(p)
if SubString(s,6,i)=="red" then
call DisplayTextToPlayer(Player(0),0,0,splayers+"wishes to ally you, type -ally "+splayers+"to ally them")
endif		
endfunction

//===========================================================================
function InitTrig_ally takes nothing returns nothing
local integer i=0
    set gg_trg_ally = CreateTrigger()
	loop
	exitwhen i>10
    call TriggerRegisterPlayerChatEvent(gg_trg_ally,Player(i),"-ally",false)
    set i=i+1
	endloop
	call TriggerAddAction(gg_trg_ally,function Trig_ally_Actions)
endfunction
Last edited by weirdone2 on July 29th, 2007, 4:23 pm, edited 9 times in total.
User avatar
backspaceoneone
Junior Member
Posts: 44
Joined: July 21st, 2007, 7:31 am

Re: How to convert color to string?

Post by backspaceoneone »

So you need a allying system? Ive got a fairly easy one that I can post if you'd like, its only one trigger for the allying, another for unallying.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: How to convert color to string?

Post by weirdone2 »

Sure post it and i'll see if it's what I need cuz rite now mine is looking pretty big, even if I find out how to convert color to string it'll still be quite big. :P
User avatar
backspaceoneone
Junior Member
Posts: 44
Joined: July 21st, 2007, 7:31 am

Re: How to convert color to string?

Post by backspaceoneone »

Code: Select all

Ally
    Events
        Player - Player 1 (Red) types a chat message containing -ally as A substring
        Player - Player 2 (Blue) types a chat message containing -ally as A substring
        Player - Player 3 (Teal) types a chat message containing -ally as A substring
        Player - Player 4 (Purple) types a chat message containing -ally as A substring
        Player - Player 5 (Yellow) types a chat message containing -ally as A substring
        Player - Player 6 (Orange) types a chat message containing -ally as A substring
        Player - Player 7 (Green) types a chat message containing -ally as A substring
        Player - Player 8 (Pink) types a chat message containing -ally as A substring
        Player - Player 9 (Gray) types a chat message containing -ally as A substring
        Player - Player 10 (Light Blue) types a chat message containing -ally as A substring
        Player - Player 11 (Dark Green) types a chat message containing -ally as A substring
        Player - Player 12 (Brown) types a chat message containing -ally as A substring
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 1, 5)) Equal to -ally
                (Integer((Substring((Entered chat string), 7, 8)))) Greater than or equal to 1
                (Integer((Substring((Entered chat string), 7, 8)))) Less than or equal to 12
            Then - Actions
                Player - Make (Triggering player) treat (Player((Integer((Substring((Entered chat string), 7, 8)))))) as an Ally with shared vision
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + (has allied  + (Name of (Player((Integer((Substring((Entered chat string), 7, 8)))))))))
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 10)) Equal to red
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(1)))))
                Player - Make (Triggering player) treat Player 1 (Red) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 11)) Equal to blue
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(2)))))
                Player - Make (Triggering player) treat Player 2 (Blue) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 11)) Equal to teal
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(3)))))
                Player - Make (Triggering player) treat Player 3 (Teal) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 13)) Equal to purple
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(4)))))
                Player - Make (Triggering player) treat Player 4 (Purple) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 13)) Equal to yellow
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(5)))))
                Player - Make (Triggering player) treat Player 5 (Yellow) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 13)) Equal to orange
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(6)))))
                Player - Make (Triggering player) treat Player 6 (Orange) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 12)) Equal to green
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(7)))))
                Player - Make (Triggering player) treat Player 7 (Green) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 11)) Equal to pink
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(8)))))
                Player - Make (Triggering player) treat Player 8 (Pink) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 11)) Equal to gray
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(9)))))
                Player - Make (Triggering player) treat Player 9 (Gray) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 11)) Equal to grey
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(9)))))
                Player - Make (Triggering player) treat Player 9 (Gray) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 17)) Equal to light blue
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(10)))))
                Player - Make (Triggering player) treat Player 10 (Light Blue) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 16)) Equal to lightblue
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(10)))))
                Player - Make (Triggering player) treat Player 10 (Light Blue) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 17)) Equal to dark green
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(11)))))
                Player - Make (Triggering player) treat Player 11 (Dark Green) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 16)) Equal to darkgreen
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(11)))))
                Player - Make (Triggering player) treat Player 11 (Dark Green) as an Ally with shared vision
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Substring((Entered chat string), 7, 12)) Equal to brown
            Then - Actions
                Game - Display to (All players) for 30.00 seconds the text: ((Name of (Triggering player)) + ( has allied  + (Name of (Player(12)))))
                Player - Make (Triggering player) treat Player 12 (Brown) as an Ally with shared vision
            Else - Actions
It looks big but its just conditions (substrings 4tw) for each player. Of course the unally trigger is the same except the substrings are changed because "-unally" is longer then "-ally", it has "player has unallied" and it changes the alliance to enemy.

I did have another system made by someone else which was uber small jass, 6 lines or so but I couldnt find it =(
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: How to convert color to string?

Post by weirdone2 »

Hmm thats bigger then mine will be, alot bigger :shock: , and what I need is for them both to ally for it to ally. :P Thx for trying though.
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: How to convert color to string?

Post by Aero »

Holy shit let me redo that

I'll give you a nice jass one.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: How to convert color to string?

Post by weirdone2 »

Kewl I got lazy about halfway thru on mine and said meh i'll finish it tomorrow lolz. So i'll be looking forward to seeing yours. :)

Edit: well I finished it now thought its not completely done just kinda in beta stages lolz since already its got a limitation that only allows you to ally with another person at a time like if blue were to type -ally red but then also type -ally green, then unless red typed -accept 2 really quick he wont b able to ally withhim until he types it again. XD I haven't even tested it yet so feel free to point out errors and such that you notice. :P

Code: Select all

function Trig_ally_Actions takes nothing returns nothing
local string s=GetEventPlayerChatString()
local player p=GetTriggerPlayer()
local integer i=StringLength(s)
local integer il=1
local integer ic=1
local string array sally
local integer iplayers=GetConvertedPlayerId(p)
local integer array ially
set sally[1]="Red"
set sally[2]="Blue"
set sally[3]="Teal"
set sally[4]="Purple"
set sally[5]="Yellow"
set sally[6]="Orange"
set sally[7]="Green"
set sally[8]="Pink"
set sally[9]="Gray"
set sally[10]="Light Blue"
loop
exitwhen il>10
if SubString(s,0,i)=="-ally "+sally[il]  then
	set ially[iplayers]=il
	call DisplayTextToPlayer(Player(0),0,0,sally[iplayers]+"wishes to ally you, type -accept "+I2S(iplayers)+"to ally them")
endif
set il=il+1
endloop
set il=1
set ic=1
loop
loop
exitwhen il>10
exitwhen ic>10
if SubString(s,0,i)=="-accept "+I2S(il) then
if ially[il]==ic then 	
if iplayers==ic then
    call SetPlayerAlliance(p,ConvertedPlayer(ially[il]),ALLIANCE_PASSIVE,true)
    call SetPlayerAlliance(p,ConvertedPlayer(ially[il]),ALLIANCE_HELP_REQUEST,true)
    call SetPlayerAlliance(p,ConvertedPlayer(ially[il]),ALLIANCE_HELP_RESPONSE,true)
    call SetPlayerAlliance(p,ConvertedPlayer(ially[il]),ALLIANCE_SHARED_SPELLS,true)
endif
endif
endif
set il=il+1
endloop
set il=1
set ic=ic+1
endloop
endfunction

//===========================================================================
function InitTrig_ally takes nothing returns nothing
local integer i=0
    set gg_trg_ally = CreateTrigger()
	loop
	exitwhen i>10
    call TriggerRegisterPlayerChatEvent(gg_trg_ally,Player(i),"-",false)
    set i=i+1
	endloop
	call TriggerAddAction(gg_trg_ally,function Trig_ally_Actions)
endfunction

Also handyhat I noticed you deleted your post. What was that about? You gave up? :P
HINDYhat
Senior Member
Posts: 101
Joined: June 1st, 2007, 9:05 pm

Re: How to convert color to string?

Post by HINDYhat »

Actually, I had posted mine, and then I had done like a few functions, when I noticed that I had done totally the wrong thing... And so then I tried to test the map, but since my Warcraft 3 disc has a 3 cm scratch right through the middle, my test wc3 didn't open, and I didn't want to feel the shame of posting something that didn't work. = I deleted my post.
User avatar
weirdone2
Forum Staff
Posts: 926
Joined: June 3rd, 2007, 8:03 pm

Re: How to convert color to string?

Post by weirdone2 »

hehe ic thats alrite just wondering why the post i'd seen dissapeared. :P I think i'ma change my -accept # to colors though numbers just dont look good in an allying system. o.0 And still no ones pointed out anything wrong with it im sure ters plenty wrong with it sniffles.

Edit: hmm I wonder what happened to aero. XD
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: How to convert color to string?

Post by Aero »

Aero's Ally/Vision system

Code: Select all

function GetBaseLength takes string s returns string
if SubString(s,0,5)=="-ally"then
return"5a"
elseif SubString(s,0,7)=="-unally"then
return"7b"
elseif SubString(s,0,7)=="-vision"then
return"7c"
elseif SubString(s,0,9)=="-unvision"then
return"9d"
endif
return""
endfunction

function AllyExecute takes nothing returns nothing
local integer i=0
local player p=GetTriggerPlayer()   
local integer id=GetPlayerId(p)
local string s=GetEventPlayerChatString() 
local string l=GetBaseLength(StringCase(s,false))
local string array n
local player t
if l!=""then
set i=S2I(SubString(l,0,1))+1
set l=SubString(l,1,2)
else
set p=null
return
endif
set n[0]="red"
set n[1]="blue"
set n[2]="teal"
set n[3]="purple"
set n[4]="yellow"
set n[5]="orange"
set n[6]="green"
set n[7]="pink"
set n[8]="gray"
set n[9]="light blue"
set n[10]="dark green"
set n[11]="brown"
set n[12]=StringCase(SubString(s,i,i+10),false)
set n[13]=""
set i=0
loop
if n[i]==n[12]then
set n[0]="exit"
endif
exitwhen n[0]=="exit"
set i=i+1
endloop
set t=Player(i)
if id==i then
call DisplayTextToPlayer(p,0,0,"You can't perform Alliance Operations with yourself!")
elseif i>11then
call DisplayTextToPlayer(p,0,0,"Invalid player color.")
elseif (l=="a")and(not GetPlayerAlliance(p,t,ALLIANCE_PASSIVE))then
call SetPlayerAllianceStateAllyBJ(p,t,true)
set n[13]=GetPlayerName(p)+" is now allies with "+GetPlayerName(t)
elseif (l=="b")and(GetPlayerAlliance(p,t,ALLIANCE_PASSIVE))then
call SetPlayerAllianceStateAllyBJ(p,t,false)
set n[13]=GetPlayerName(p)+" is now enemies with "+GetPlayerName(t)
elseif (l=="c")and(not GetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION))then
call SetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION,true)
set n[13]=GetPlayerName(p)+" is now sharing vision with "+GetPlayerName(t)
elseif (l=="d")and(GetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION))then
call SetPlayerAlliance(p,t,ALLIANCE_SHARED_VISION,false)
set n[13]=GetPlayerName(p)+" is no longer sharing vision with "+GetPlayerName(t)
endif
call DisplayTextToPlayer(GetLocalPlayer(),0,0,n[13])
set p=null
set t=null
endfunction

//=======================================================================
function InitTrig_AllySystem takes nothing returns nothing
local integer i=0
local trigger t=CreateTrigger()
loop
exitwhen i>11
call TriggerRegisterPlayerChatEvent(t,Player(i),"-",false)
set i=i+1
endloop
call TriggerAddAction(t,function AllyExecute)
set t=null
endfunction
Alright, here is how it works.

-ally color (Allies)
-unally color (Unallies)
-vision color (Shared Vision)
-unvision color (Unshared Vision)

Key Points:

-System uses no globals! (Yay! --> Means that your map takes up less permanent memory!)
-You can share vision with an enemy.
-When you ally an enemy with whom you're sharing vision, you become allies with shared vision.
-If you're sharing vision with an ally and unally them, they still retain shared vision
-Allying an enemy will not automatically share vision
-Messages will display to all players when you change your alliance status
-If you're trying to ally an ally, nothing will happen and no message will display. Same thing for shared vision
-You cannot ally/vision yourself (It will tell you you're a moron)
-You will receive no message if you typed "-" but "vision", "ally", "unally" or "unally" doesn't follow. If either of these follow the "-", but the player is invalid, you will receive an error message.

Also, this system is not case sensitive, -alLY rEd will work the same as -Ally Red.

I tested this myself and all is in order. Enjoy.

[Edit: Yes, weirdone2, your system is flawed but points for effort =P]