| 01-29-2006, 05:32 AM | #1 |
JASS:function Power takes real x, real n returns real local real y = 1 loop exitwhen n == 0 set y = y * x set n = n - 1 call BJDebugMsg(R2S(y)) endloop return y endfunction function Trig_Melee_Initialization_Actions takes nothing returns nothing local real r = S2R(GetEventPlayerChatString()) local real n = 19.0 local unit u = CreateUnit( Player(0), 'hfoo', 0.0, 0.0, 270.0) if r > 1048575 then call DisplayTextToForce(GetPlayersAll(), "AddLife value is too large!") return endif loop call BJDebugMsg(R2S(Power(2.0,n))) if r >= Power(2.0, n) then call UnitAddAbility( u, udg_AddLife[R2I(n)]) set r = r - Power(2.0, n) endif set n = n - 1 exitwhen n == 0 endloop endfunction //=========================================================================== function InitTrig_Melee_Initialization takes nothing returns nothing set gg_trg_Melee_Initialization = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_Melee_Initialization, Player(0), "", false ) call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions ) endfunction So there's the trigger. So what's supposed to happen, is when red types a number in the chat line, it creates a footmen with that much extra health. udg_AddLife is an ability array of 20 (00 - 19) health bonuses. The problem is, it won't let me do a odd value for the bonus health. I have no clue what is wrong with it. And the trigger uses Power instead of Pow because I thought it was just another stupid blizz limitation, but apparently it isn't. |
| 01-29-2006, 07:51 AM | #2 |
your trigger registers only when red player types an empty message... empty message? duh :/ |
| 01-29-2006, 07:59 AM | #3 |
Yes, you can't type empty string. Eventually " ". ![]() |
| 01-29-2006, 08:20 AM | #4 |
I did some things for you on how to get working JASS:
local string s = GetEventPlayerChatString( )
local real r
set s = SubString ( s , StringLength ("health #") , StringLength( s ) )
set r = S2R ( s )
call DisplayTextToForce( GetPlayersAll(), ( ( "trigger fired" + " and s := " )+ s ) )
call DisplayTextToForce( GetPlayersAll(), "r " + R2S ( r ) )
// now r should have correct value .....
and our event is :
call TriggerRegisterPlayerChatEvent( gg_trg_Melee_Initialization, Player(0), "health #", false )
the boolean set to false determines that we should match a substring.
now type "health #" + SomeNumber and see
like "health #244" you can change the substring we want to match though... |
| 01-29-2006, 03:33 PM | #5 |
Wow... yes the trigger fires, test it yourself. The empty message is a SUBSTRING. which means it fires whenever red types any message, not just a certain number, or whatever. In any case, that's not the problem. The trigger ALWAYS creates a new footman, but if I specify it to add 5 health, the footman only has 424 (420 base health + 4). If I specify 7, 426. If I specify 6, also 426. And if I specify 4, also 424. |
| 01-29-2006, 06:00 PM | #6 |
I would say the problem is in you +1hp ability. |
| 01-29-2006, 07:38 PM | #7 |
Actually PCPharaoh, it has been said that using empty message as substring for the event registering causes desyncs and some other weird problems. 1) Don't use reals, just integers for the input . 2) The script overall sucks (sorry but it is true=), it is not efficient at all. JASS:function Trig_Melee_Initialization_Actions takes nothing returns nothing local integer r = S2I(GetEventPlayerChatString()) local integer pow = R2I(Pow(2,19)) local integer i=19 local unit u = CreateUnit( Player(0), 'hfoo', 0.0, 0.0, 270.0) if r > 1048575 then call DisplayTextToForce(GetPlayersAll(), "AddLife value is too large!") return endif loop call BJDebugMsg(R2S(Power(2.0,n))) if (r >= pow) then call UnitAddAbility( u, udg_AddLife[i]) set r = r - pow endif exitwhen (pow==1) set pow = pow / 2 set i=i-1 endloop endfunction //=========================================================================== function InitTrig_Melee_Initialization takes nothing returns nothing set gg_trg_Melee_Initialization = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_Melee_Initialization, Player(0), "", false ) call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions ) endfunction |
| 01-30-2006, 01:31 AM | #8 |
Thanks vex. All working now. edit:I have to spread some around before giving to you again. Maybe tomorrow. :P Not that it's that important, but I'm kind of curious what the problem was with my previous code. Any ideas? |
| 01-30-2006, 01:34 AM | #9 |
probably was some stuff about float precision |
