wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 05-22-2009, 11:26 PM   #1
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default OnDoubleClick

I got tired of seeing strange, overcomplicated, hacky implementations of this simple thing.
* Does anyone actually need the event to be removable? I can't think of a legit reason for so, but if you prove such need I can easily add a way for it.
* It fails if you double click too fast and there are many units of the same type around (the game will consider it a select all double click)
* As always, names are subject to change before approval...

Collapse Example:
scope OnDoubleClickDemo initializer xxx

    private function meh takes player p, unit u returns nothing
        call BJDebugMsg(GetPlayerName(p)+" double clicks "+GetUnitName(u) )
    endfunction
    
    private function xxx takes nothing returns nothing
        call OnDoubleClick( meh )
    endfunction

endscope


Collapse OnDoubleClick:
library OnDoubleClick initializer init
//******************************************************
//* OnDoubleClick
//* -------------
//*  Calls a function when a player does a double click
//*
//*  Usage:
//*      call OnDoubleClick( function_name )
//*
//*  The function must take a player as first argument
//* and unit as second argument, ie:
//*
//*  function function_name takes player clickingPlayer, unit clickedUnit returns nothing
//*
//*
//********************************************************


//====================================================================================
 globals
    // The interval between clicks must be smaller than WAIT_TIME for them to count
    private constant real WAIT_TIME = 1.0
 endglobals

 //=====================================================================================
 globals
    private constant integer HUMAN_PLAYERS = 12
    private constant real EXAGGERATED_GAME_LENGTH = 1000000.0
    private timer T

    private OnDoubleClickListener array listener
    private integer listeners = 0
 endglobals

 function interface OnDoubleClickListener takes player clickingPlayer, unit clickedUnit returns nothing

 function OnDoubleClick takes OnDoubleClickListener od returns nothing
     set listener[listeners] = od
     set listeners = listeners + 1
 endfunction

 private struct PlayerData extends array [HUMAN_PLAYERS]
    unit lastClickUnit
    real lastClick
 endstruct


 private function onSelected takes nothing returns nothing
  local player     p  = GetTriggerPlayer()
  local PlayerData d  = PlayerData[GetPlayerId(p ) ]
  local real       now= TimerGetElapsed(T)
  local unit       u  = GetTriggerUnit()
  local integer    i
     if (d.lastClick + WAIT_TIME >= now)  and (d.lastClickUnit == u) then
         // double click!!11
         set i=0
         loop
             exitwhen (i==listeners)
             call listener[i].evaluate(p,u)
             set i=i+1
         endloop
         set d.lastClick = -WAIT_TIME
     else
         set d.lastClick = now
         set d.lastClickUnit = u
     endif

  set p=null
  set u=null
 endfunction

 private function init takes nothing returns nothing
  local integer i=0
  local trigger tr=CreateTrigger()
    loop
        exitwhen (i==HUMAN_PLAYERS)
        call TriggerRegisterPlayerUnitEvent(tr, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        set PlayerData[i].lastClick = -WAIT_TIME
        set i=i+1
    endloop

    call TriggerAddAction(tr, function onSelected)
    set T=CreateTimer()
    call TimerStart(T, EXAGGERATED_GAME_LENGTH, false, null)
    set tr=null
 endfunction


endlibrary
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 05-23-2009, 02:34 AM   #2
azlier
User
 
Join Date: Jun 2008
Posts: 116

azlier is on a distinguished road (10)

Default

It's... weird. Can't you at least make it behave like a standard WC3 event? It feels odd to use, right now.

>I can't think of a legit reason for so, but if you prove such need I can easily add a way for it.
Well, it could be used with some dynamic triggers. Or triggers that or no longer needed. I don't really need the function to stay around, getting called on each double click, slowing the game down.

>strange, overcomplicated, hacky
It's what I do best.

Collapse JASS:
TimerGetElapsed(T)
I heard that TimerGetElapsed was sort of inaccurate? Sure, it matters next to nothing in this case, but I do like accuracy.

Collapse JASS:
local player     p  = GetTriggerPlayer()
  local PlayerData d  = PlayerData[GetPlayerId(p ) ]
  local real       now= TimerGetElapsed(T)
  local unit       u  = GetTriggerUnit()
  local integer    i
Ow, my eyes. I really dislike when people space their code like that. Not that it affects me, but still.
__________________
You hate me, don't you?
azlier is offline   Reply With Quote
Old 05-23-2009, 04:25 AM   #3
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by azlier
It's... weird. Can't you at least make it behave like a standard WC3 event? It feels odd to use, right now.
Function interfaces are better than standard wc3 events. The syntax is a lot cleaner.

Quote:
Originally Posted by Vexorian
I can't think of a legit reason for so, but if you prove such need I can easily add a way for it.
I would add it just for completeness...

Anyway, the TimerGetElapsed call would be more accurate if you used 36000 seconds (10 hours) instead of 1000000. Not that it matters much.
grim001 is offline   Reply With Quote
Old 05-23-2009, 04:38 AM   #4
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

36000 is good for values like 0.02, for 1.00 even 1800000 would be all right, but I guess I could use 10 hours, even 10 hours is being unrealistic...

Quote:
Well, it could be used with some dynamic triggers. Or triggers that or no longer needed. Or triggers that or no longer needed. I don't really need the function to stay around, getting called on each double click, slowing the game down.
I think even the command card icons actually impact the performance more (if at all) than a TriggerEvaluate() when you double click units...

In reality, I cannot think of a way the map is actually going to use more than two of these events.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 06-07-2009, 03:41 PM   #5
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

I am approving this. Because I can and couldn't see anything wrong in it.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 06-08-2009, 06:33 PM   #6
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by Vexorian
I am approving this. Because I can and couldn't see anything wrong in it.

Can you please not do this?
We have enough proof in political history of mankind that such behaviour is bad practise and inevitably leads to corruption of the whole system. (in this case forum)

We have enough competent coders here so there really is no need for you to do everyones job.

And the last time I checked there was a mod who resigned for exactly the same behavior.

The correct course of action would be to unapprove this resource for proper validation and give yourself -10 rep (because you also can do that can't you?)
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 06-08-2009, 09:44 PM   #7
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

This comes directly from the submission rules:

A moderator / administrator cannot approve his or her own resource. It must be reviewed and approved by another qualified staff member.
Mr.Malte is offline   Reply With Quote
Old 06-08-2009, 10:50 PM   #8
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Who cares? Honestly.
grim001 is offline   Reply With Quote
Old 06-08-2009, 11:03 PM   #9
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by grim001
Who cares? Honestly.
me.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 06-08-2009, 11:22 PM   #10
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Quote:
We have enough proof in political history of mankind that such behaviour is bad practise and inevitably leads to corruption of the whole system. (in this case forum)
It's a risk I have evaluated and decided that it is not worth caring about.

In my case it would have been as easy to nod Anitarf in IRC and make him approve this thing... it is really just relative, if I did that nobody would have known and nobody would have complained but it is not really that much different.

I like this resource, and when comparing with the other attempts it is really much better, and I can't think of a way it would be better.

This is just a web forum...
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 06-09-2009, 12:00 AM   #11
AnemicRoyalty
Moderator
 
AnemicRoyalty's Avatar


Texturing Moderator
Project Member: WotTH
 
Join Date: Dec 2006
Posts: 805

Submissions (23)

AnemicRoyalty is a name known to all (524)AnemicRoyalty is a name known to all (524)AnemicRoyalty is a name known to all (524)AnemicRoyalty is a name known to all (524)AnemicRoyalty is a name known to all (524)AnemicRoyalty is a name known to all (524)

Skinning Contest #14 WinnerSkinning Contest #15 WinnerHero Contest #2 - 1st Place

Default

You will now refer to him as Vexorian Caesar!

Seriously though, it's not that big of a deal.
__________________
The WC3 Unit Wrap Compilation Project - An essential resource for WC3 texturing
Zoom (requires log in)To Do List:
  • Complete/Revise DoE & Aot3 Models & Textures
  • DIII: TFA Textures
  • Finish and release a bunch of stuff
AnemicRoyalty is offline   Reply With Quote
Old 06-09-2009, 01:10 AM   #12
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Vex is the only person on this entire website that can do that and not raise a red flag in my book. He's easily the most knowledgeable on topics such as these and truth be told, when he submits something, short of the naming convention for the functions, it is always quality and worthy of our database.

If you'd prefer, I could just auto-approve anything Vex submits, but really, having it open to a bit of discussion beforehand is healthy.
__________________
Rising_Dusk is offline   Reply With Quote
Old 06-09-2009, 01:23 AM   #13
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

I would do that when the resource really matters.

Though honestly, all the code mods even the past ones had my trust in that I wouldn't mind if they approved their things by themselves when they consider it convenient.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 06-09-2009, 07:31 AM   #14
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by Vexorian
It's a risk I have evaluated and decided that it is not worth caring about.

In my case it would have been as easy to nod Anitarf in IRC and make him approve this thing... it is really just relative, if I did that nobody would have known and nobody would have complained but it is not really that much different.
The difference is that it is a public display of bad behaviour and that people like to imitate.
And what makes it worse is that it already happened with a mod before and you people don't seem to get it that this thing are related and lead to each other.

So please play good buddies over the IRC as much as you like, but when it comes to public display follow the fucking rules.

Quote:
Originally Posted by Vexorian
I like this resource, and when comparing with the other attempts it is really much better, and I can't think of a way it would be better.
This is not about your expertise in jass, you can be an omnipotent demigod for all I care, it still does not make it right.

Quote:
Originally Posted by Vexorian
This is just a web forum...
Would you like me to call you Draco from now on?

==========================================
I still insist that this be unapproved and approved by someone else.

http://en.wikipedia.org/wiki/Cronyism
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 11:28 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services