| 08-02-2003, 09:53 AM | #16 |
heres a function i made for a post below, it adds a player leaves event for all players to a selected trigger, call it at map initialization (no editor infront of me for two weeks... some formalities might be a bit off): Code:
function AnyPlayerLeaves takes trigger targetTrig returns nothing
local integerA = 1
loop
call TriggerRegisterPlayerEvent(targetTrig, ConvertPlayerIndextoPlayer(integerA), EVENT_PLAYER_LEAVE)
set integerA = integerA + 1
exitwhen integerA = 12
endloop
endfunctionbtw, data... i'm thinking that this might be one of the most usefull things for advanced mappers out there (i was thinking of making one myself, but in mod form i.e. functions to be used in RPGs or such). with your permission i would like to make a website to easily organize all this, database compatability and all (database compatibility means it will be easier to update and submit, it also means i can add things like "sort by return type" and "sort by submitter" without making millions of html files. I'm thinking the submit system would require a password (given to me, you and maybe a few others) and be made via HTML forms... that way all the functions won't have to go through me. I'f your interested say so but im in alaska untill late august... you'll have to wait untill then. |
| 08-02-2003, 11:14 AM | #17 |
This is a fun code ive used in one of my maps. It makes a unit run away from another unit. Code:
function Flee takes unit fleeingUnit, unit fleeeingFrom returns nothing
local real sy=GetLocationY(GetUnitLoc(fleeingUnit))
local real sx=GetLocationX(GetUnitLoc(fleeingUnit))
local real dy=GetLocationY(GetUnitLoc(fleeingFrom))
local real dx=GetLocationX(GetUnitLoc(fleeingFrom))
call IssuePointOrderLocBJ( fleeingUnit, "move", PolarProjectionBJ(GetUnitLoc(fleeingUnit), 512,Atan2BJ(( sy - dy ), ( sx - dx)) ))
endfunction |
| 08-02-2003, 12:04 PM | #18 | ||
Quote:
Code:
loop
exitwhen i >= bits_number
set source_int[i] = ModuloInteger(sum, 2)
set sum = sum / 2
set i = i + 1
endloopQuote:
That is what the code you quoted does. It stores the bits of the integer into an array. At the first position the sign bit is stored, then at the second position the least significant bit and so on. Checking if the integer is odd or even gets you the least significant bit. Then by dividing by 2 you remove that bit and the second bit is now the least significant bit and so on. |
| 08-02-2003, 01:50 PM | #19 |
GetSubString is a function to be used when you need to extract several strings from a string. Say you have the string: str = "-give player1 100 gold" Then the use of GetSubString would give: GetSubString(str, 0, " ") = "-give" GetSubString(str, 1, " ") = "player1" GetSubString(str, 2, " ") = "100" GetSubString(str, 3, " ") = "gold" GetSubString(str, 4, " ") = "" You get the point :P. I thought it would be useful for some mappers. The delimiters-string contains a set of characters to determine what separates strings, and the delimiters themselves are not returned. I don't really know when it could come in use, but I hate to hardcode things. A space (" ") would be sufficient in most cases, though. You might want to rename it, the title I gave it can cause confusion. Oh and the MidString and MidStringLength is like SubString, but they are specialized and simpler to use if you know what you want. I prefer to use them because I don't have to think as much :). Btw, yeah, exitwhen true is great :P. |
| 08-02-2003, 03:35 PM | #20 |
Ibox2 takes an character and should return its integer equvilent (for using dialog hotkeys). About the single return statement, I was taught it was better programming practice (easier to maintain), its possible this information is false. |
| 08-02-2003, 06:36 PM | #21 | ||
Quote:
Forgive my newbishness in this matter: what does 'least significant bit' mean? Rightmost bit? Leftmost bit? :P Peppar: Yeah, I finally figured out what was going on as soon as I looked up delimiter :P And I was beginning to think I had more programming experience than anyone around here emote_sweat Quote:
I've actually been thinking about this, because it's very clunky to store it all in a text file. I was thinking of the guy who made the JASS reference on sourceforge though, because it looks like he already has code for parsing .j files =) I'll ask around. |
| 08-02-2003, 06:40 PM | #22 | |
Quote:
Instead of Atan2BJ, why don't you just use: Code:
AngleBetweenPoints(GetUnitLoc(fleeingFrom), GetUnitLoc(fleeingUnit)) Unless I'm missing something? If not lemme know and I'll add it to the pack with that. |
| 08-02-2003, 06:42 PM | #23 |
How can I implement this fleeing thing in my Map? I want all Sheeps to flee from my Units when they´re in Range. |
| 08-02-2003, 06:53 PM | #24 | |
Quote:
Unit group all sheeps in range and then do a custom script action. I don't know what unit you want them to be fleeing from, so for the sake of example we'll say it's the triggering unit: call flee(GetEnumUnit(), GetTriggeringUnit()) GetEnumUnit() is the same thing as Picked Unit (the sheep). Change GetTriggeringUnit() to the unit you want them to flee from. |
| 08-02-2003, 07:03 PM | #25 |
As long as I have the JASS experts attention -- I would be FOREVER THANKFUL to someone who could devise a function to get rid of the following problem. Whenever you want to do actions for all units in a unit group or player group, you have to specify another function that contains the actions to perform on the picked units/players. e.g: Code:
function AOEDamageByUnitSimple takes unit whichUnit, real damage, real radius, boolean friendlyfire returns nothing
if (friendlyfire) then
call ForForce( GetForceOfPlayer(GetOwningPlayer(whichUnit)), function SubtractLife )
else
endif
endfunctionThe problem is that I can't take the damage variable passed to AOEDamageByUnitSimple and pass it to SubtractLife. The following gives a compiler error: Code:
call ForForce( GetForceOfPlayer(GetOwningPlayer(whichUnit)), function SubtractLife(damage) ) Even if I've setup SubtractLife to take an integer. :/ I'm worried that I'm gonna end up having to resort to globals, which would suck :P AH -- but that's not the only problem. Since you have to call a separate function, you if you return it doesn't quit the calling function, only the unit-group actions. Check out the unit type is in region boolean function in the pack to see my kludgy workaround for this. If anyone knows how to solve either of these without globals... HALLELUJAH! |
| 08-02-2003, 07:23 PM | #26 |
Just what does Forforce take? Does subtract life return what forforce needs? I'm not jass expert but you should probably tell us... |
| 08-02-2003, 07:32 PM | #27 | |
Quote:
Well, I kind of assumed you'd ecognize one of the functions built into war3 weaaddar ://// ForForce = Pick Every Player in Player Group SubtractLife doesn't return anything -- you're not passing what it returns, but the function itself. |
| 08-02-2003, 07:38 PM | #28 |
are you positive that its expecting a function and not say something different? Also doesn't the Forgroup require picked units or whatever to actually function? Edit: Theres unfortunate, most painful probability that the forgroup function only works with a specific group of functions... |
| 08-02-2003, 07:46 PM | #29 |
I don't have any "real" solution to your problem but you might want to consider using the Enum-variables that are reserved for the functions in Blizzard.j. It would be using globals, but you don't have to define them in the map that is run. For the return issue you could set a boolean value in one of the reserved variables to TRUE in the parent function, add a check in the child function to not run if it is FALSE and set it to FALSE whenever you want to skip subsequent calls. http://jass.sourceforge.net/doc/api/...urce.shtml#536 I'm not sure if this qualifies for your demand for functions not to use globals though :P. |
| 08-02-2003, 09:05 PM | #30 | |
Quote:
Well, I went through blizzard.j thinking about that, but I'm somewhat confused as to how the game engine actually treats the variables in there. There's only 1 global for stuff like get random unit from unit group, but you can run 293809013891 of that function at once and never have the values for the global mess with each other. I think the game might set the bj globals to a new variable for each trigger they're used in, but I'm not sure that it'll do that automatically if I use them in my own functions or if they only do that automatically for stuff defined in blizzard.j. Any idea? |
