Page 1 of 3

-godly all command on teve map

Posted: November 30th, 2011, 1:59 am
by Durge
Ok, just figure I'd start a new thread since it had no relevance to my other thread, since it was based solely on the repick system.

So I was wondering how do you know what to put in the SubString(<w/e>,<here>,<and here>).

Heres what I'm trying to do, I followed what you did for your repick command haxorico, maybe it's something completely different thats the problem, I'm not sure.

Spoiler:
function GodlyItem takes nothing returns nothing
local string bum=StringCase(GetEventPlayerChatString(),false)
if SubString(bum,7,10)=="all"then

call UnitAddItemByIdSwapped('I02Z',GetTriggerUnit())
call UnitAddItemByIdSwapped('I047',GetTriggerUnit())
call UnitAddItemByIdSwapped('I046',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04N',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04O',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04P',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05H',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05G',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05F',GetTriggerUnit())
endif
set bum=""
endfunction

function main
local integer godlooper=0
loop
exitwhen godlooper>=1
call TriggerRegisterPlayerChatEvent(trgGodly,Player(godlooper),"-godly",false)
call TriggerAddAction(trgGodly,function GodlyItem)
set godlooper=godlooper+1
endloop

Re: -godly all command on teve map

Posted: November 30th, 2011, 2:17 am
by Risugami

Code: Select all

set bum=""


Why are you setting bum to ""? I'm aware of leaks but strings are fine.

Well, there's a better way to do it. Like for example:

Code: Select all

function GodlyItem takes string s2 returns nothing
if SubString(s2,0,10)=="-godly all"then
call UnitAddItemByIdSwapped('I02Z',GetTriggerUnit())
call UnitAddItemByIdSwapped('I047',GetTriggerUnit())
call UnitAddItemByIdSwapped('I046',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04N',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04O',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04P',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05H',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05G',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05F',GetTriggerUnit())
endif
endfunction


I didn't tested it if it would work so I don't recommend for you to use it. IIRC that's how JJ's CP handles strings.

Another questions pops out is. Why are you using SubStrings? If you're just gonna make a "-godly all" as a exact match. But if you still want to use substrings this could help you.

warcraft-map-discussion-f67/queries-t22780.html#p152826

Re: -godly all command on teve map

Posted: November 30th, 2011, 2:31 am
by Durge
Oh, that makes a lot more sense, thanks for the help Risugami

EDIT:Ok, I've revised my command, but to no avail it still does not work.
Here is what I have

Spoiler:
globals
trigger trgGodly=CreateTrigger()

endglobals
function GodlyItem takes nothing returns nothing
call TriggerRegisterPlayerChatEvent(trgGodly,GetTriggerPlayer(),"-godly all",true)
call UnitAddItemByIdSwapped('I02Z',GetTriggerUnit())
call UnitAddItemByIdSwapped('I047',GetTriggerUnit())
call UnitAddItemByIdSwapped('I046',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04N',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04O',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04P',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05H',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05G',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05F',GetTriggerUnit())
endfunction

function main
call TriggerAddAction(trgGodly,function GodlyItem)

Re: -godly all command on teve map

Posted: November 30th, 2011, 4:23 am
by Risugami
It doesn't work because you didn't have a condition. I am not in my computer right now so...

First of all, put call 'TriggerRegisterPlayerChatEvent(trgGodly,GetTriggerPlayer(),"-godly all",true)' into a new function or something that returns boolean so you'll make that as condition. So whenever it returns true it will call function GodlyItem. Which creates the items and such.

[EDIT: This should work, please do test it:]

After endglobals:

Code: Select all

function GI_Conditions takes nothing returns boolean
    if GetEventPlayerChatString() == "-godly all" then
        return true
    endif
    return false
endfunction

function GI_Actions takes nothing returns nothing
    call UnitAddItemByIdSwapped('I02Z',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I047',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I046',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I04N',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I04O',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I04P',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I05H',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I05G',GetTriggerUnit())
    call UnitAddItemByIdSwapped('I05F',GetTriggerUnit())
endfunction


And this is at the function main part: (AFTER LOCALS!)

Code: Select all

    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i>11
        call TriggerRegisterPlayerChatEvent( t, Player(i), "-godly all", true)
        set i = i+1
    endloop
    call TriggerAddCondition(t, Condition(function GI_Conditions))
    call TriggerAddAction(t, function GI_Actions)


It should work with all players but I didn't tested it really. But well it should work.

Re: -godly all command on teve map

Posted: November 30th, 2011, 5:13 am
by Kyoshiro
just a question.
since when can units have more than 6 inv slots?

Re: -godly all command on teve map

Posted: November 30th, 2011, 5:53 am
by haxorico
wtf? Why are you guys making it so complicated?

Your code is good, I suspect you didn't use CreateTrigger() on globals but used null as its given by default.
Here is the full code you need to have.

Spoiler:

Code: Select all

globals
trigger trgGodly=CreateTrigger()
endglobals

function GodlyItem takes nothing returns nothing
local string bum=StringCase(GetEventPlayerChatString(),false)
if SubString(bum,7,10)=="all"then
call UnitAddItemByIdSwapped('I02Z',GetTriggerUnit())
call UnitAddItemByIdSwapped('I047',GetTriggerUnit())
call UnitAddItemByIdSwapped('I046',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04N',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04O',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04P',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05H',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05G',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05F',GetTriggerUnit())
endif
set bum=""
endfunction

function main takes nothing returns nothing
local integer godlooper=0
loop
exitwhen godlooper>=1
call TriggerRegisterPlayerChatEvent(trgGodly,Player(godlooper),"-godly",false)
call TriggerAddAction(trgGodly,function GodlyItem)
set godlooper=godlooper+1
endloop
endfunction


As for the string="". Strings takes more space the more characters they contain, for example on C# - each character takes 16bit (IIRC).

Re: -godly all command on teve map

Posted: November 30th, 2011, 5:56 am
by Risugami
Kyoshiro wrote:just a question.
since when can units have more than 6 inv slots?


UnitAddItemByIdSwapped doesn't add the item on inventory. You still have to pick it up. But, you do have a point. o.o

@haxorico. My bad, :\

Re: -godly all command on teve map

Posted: November 30th, 2011, 5:59 am
by haxorico
If you want to have some debugging, here is what I used to do. try this code, and tell me how it goes.

Spoiler:

Code: Select all

globals
trigger trgGodly=CreateTrigger()
endglobals

function GodlyItem takes nothing returns nothing
local string bum=StringCase(GetEventPlayerChatString(),false)
if SubString(bum,0,10)=="-godly all"then
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Success - The code detected the command")
else
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"You wrote " + GetEventPlayerChatString() + " and not -godly all")
endif
set bum=""
endfunction

function main takes nothing returns nothing
local integer godlooper=0
loop
exitwhen godlooper>=1
call TriggerRegisterPlayerChatEvent(trgGodly,Player(godlooper),"-",false)
call TriggerAddAction(trgGodly,function GodlyItem)
set godlooper=godlooper+1
endloop
endfunction

Re: -godly all command on teve map

Posted: November 30th, 2011, 6:00 am
by Durge
Technically shouldn't this work also?
Chattrigger is set as null in globals

Spoiler:
function Chattrg takes nothing returns nothing
set Chattrigger = CreateTrigger()
call TriggerRegisterPlayerChatEvent(Chattrigger,GetTriggerPlayer(),"-godly all",true)
call TriggerAddAction(Chattrigger,function Godly)
endfunction
function Godly takes nothing returns nothing
call UnitAddItemByIdSwapped('I02Z',GetTriggerUnit())
call UnitAddItemByIdSwapped('I047',GetTriggerUnit())
call UnitAddItemByIdSwapped('I046',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04N',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04O',GetTriggerUnit())
call UnitAddItemByIdSwapped('I04P',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05H',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05G',GetTriggerUnit())
call UnitAddItemByIdSwapped('I05F',GetTriggerUnit())
endfunction


EDIT:The problem seems to be the items not spawning for some reason.

I even tried this as well

Spoiler:
call CreateItemLoc('102Z',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('1047',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('1046',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('104N',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('104P',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('105H',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('105G',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('105F',GetUnitLoc(GetTriggerUnit()))
call CreateItemLoc('104O',GetUnitLoc(GetTriggerUnit()))

Re: -godly all command on teve map

Posted: November 30th, 2011, 8:09 am
by haxorico
I never tried spawning items etc, just never needed to.
The question is. Is the structure okay?
And no, the code above will not work and I will explain why.

This what happens in maps:
The maps loading function main.
Inside it, it is given event commands like RegisterPlayerChatEvent, meaning that everytime the Player mentioned in there is writing something, run a function. The player who used that specific event, is the TriggeringPlayer.

What you did, was as it initilizes, tell it to activate the event for the TriggeringPlayer, which is? No one ran any trigger so it doesnt know who to give the event to. That is why we use a loop to give it to all 12 players (0-11).
Also, what is calling the function Chattrg?

And lastly, the way I wrote it, is so if you have more command strings, you can just place them inside, without making it all over again. I gave a structure and gave an example on how to use that structure.