(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > JASS Functions

JASS Functions Approved JASS functions will be located here.
Remember to submit your own resources to the submission forum.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 09-30-2007, 02:56 AM   #1 (permalink)
 
PandaMine's Avatar

User
 
Join Date: Sep 2007
Posts: 58

PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)


[JASS] Function differentiate between Replays and actual gameplay

This function I discovered myself (and with the help of Captain Griffein from wc3campaigns). Simply put, if your actually playing a game, it will return true HOWEVER if your viewing the game as a replay it will return false. The function has been tested in MultiPlayer and it now causes no desyncs. There is only one downside, and that is the function uses up one pause (if anyone knows how to prevent this please tell)

How does it work?
Simply put a replay is just a file that contains the inputs from the various players when playing a game. However when Wc3 views a replay, there are differences then if you were physically playing the game. One of the differences is pausing. If you are actually playing and you pause a game, it is paused. However during a replay, if you pause a game the replay simply finishes at the point you paused the game, if the game is resumed some time later then the replay completely skips the pause phase. There are only a few things that work in real time during pauses when your playing the game (anything else you do during the pause just gets 'suspended' until the game is resumed). The 2 things that work in real time are camera angles and trigger sleep action.

The function works by moving the camera during the pause. If the camera is moved during the pause, then you are playing the actual game. If the camera isn't moved then it is the replay (since the pause phase is totally skipped)
Notes:

- You can hide the pause message that happens in multiplayer (i.e. ******** has paused the game) by calling the function in Cinematic Mode. The cinematic mode has to last around 10 seconds to fully hide the message

- It is HIGHLY recommended that you save the returning value of the function into a boolean variable i.e.
 set someboolean = IsInGame()
So you only call the function once (since it takes up a pause)


HERE IS THE FUNCTION
//<- InGame function created by PandaMine with help from Captain Griffein
function IsInGame takes nothing returns boolean
local integer counter = 1
local real camerax
local real cameray
local real x
local real y
local boolean output
loop
    exitwhen counter > 12
    if GetLocalPlayer() == Player(counter-1) then
        set camerax = GetCameraTargetPositionX()
        set cameray = GetCameraTargetPositionY()
    endif
    set counter = counter + 1
endloop
set counter = 1
call PauseGame(true)
call TriggerSleepAction(0)
loop
    exitwhen counter > 12
    if GetLocalPlayer() == Player(counter-1) then
        call SetCameraPosition(camerax + 1,cameray + 1)
    endif
    set counter = counter + 1
endloop
call TriggerSleepAction(0)
call PauseGame(false)
set counter = 1
loop
    exitwhen counter > 12
    if GetLocalPlayer() == Player(counter-1) then
        set x = GetCameraTargetPositionX()
        if x == camerax + 1 then
            set output = true
        else
            set output = false
        endif
        call SetCameraPosition(camerax,cameray)
    endif
    set counter = counter + 1
endloop
return output
endfunction

With the new change to the function, it no longer needs to be synchronised however you should still initialize it like this because it has been reported that selecting units + triggersleepaction can cause desyncs

function Initiate takes nothing returns nothing
call EnableUserControl(false)
call TriggerSleepAction(.0)
set udg_InGame = IsInGame()
call EnableUserControl(true)
endfunction

Last edited by PandaMine; 12-15-2007 at 08:44 AM..
PandaMine is offline  
Old 09-30-2007, 05:04 AM   #2 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

You don't need to set ints/reals to 0 at the end of a function.

Otherwise, I'll test this in a bit, (or tomorrow, whichever) and if it works, very nice.

I can see it being a bit annoying to the people ingame, though...
PurplePoot is offline  
Old 09-30-2007, 05:36 AM   #3 (permalink)
 
PandaMine's Avatar

User
 
Join Date: Sep 2007
Posts: 58

PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)


I actually did the setting of ints and reals to 0 for concerns about desyncs, but it doesnt really matter

Yes it can be annoying to use in the game, but as far as I know its the only fullproof multiplayer way of determining if the game is being played or viewed as a replay. Like I mentioned if you call the function in Cinematic mode the message is hidden
PandaMine is offline  
Old 09-30-2007, 05:53 PM   #4 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

-Tested and it works great-

Beautiful. Very nice find.

~Approved~
PurplePoot is offline  
Old 11-20-2007, 10:29 PM   #5 (permalink)
 
PandaMine's Avatar

User
 
Join Date: Sep 2007
Posts: 58

PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)


Id just like to mention (forgot to say this before and had problems with it) that the returning variable is NOT synchronised. This means that you either need to use sync natives or the various sync functions out there to synchronise the returning boolean otherwise you would get various problems
PandaMine is offline  
Old 11-25-2007, 10:37 AM   #6 (permalink)
 
Captain Griffen's Avatar

******
 
Join Date: Nov 2005
Posts: 747

Captain Griffen is a jewel in the rough (241)Captain Griffen is a jewel in the rough (241)Captain Griffen is a jewel in the rough (241)Captain Griffen is a jewel in the rough (241)


Griffen, not Griffein. But a very useful function, particularly for stuff like replay data, etc.
__________________
Quote:
[20-00-13] MasterHaosis: Because I am retarded douchebag
[20-15-23] MasterHaosis: I am faggot, retard and such..
[20-21-22] MasterHaosis: because I am chat moderator. And you dont have right to speak against me
~Void~: Knock it off, for fuck's sake. Get that bullshit out of your signature and stop being so immature. Let it die out.
Captain Griffen is offline  
Old 11-25-2007, 11:59 PM   #7 (permalink)
 
PandaMine's Avatar

User
 
Join Date: Sep 2007
Posts: 58

PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)


I should really learn how to spell your name correctly LOL
PandaMine is offline  
Old 12-11-2007, 12:50 AM   #8 (permalink)
 
PandaMine's Avatar

User
 
Join Date: Sep 2007
Posts: 58

PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)


Update, mentioned a simple way on how you can synchronise the data
PandaMine is offline  
Old 12-15-2007, 08:42 AM   #9 (permalink)
 
PandaMine's Avatar

User
 
Join Date: Sep 2007
Posts: 58

PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)PandaMine has little to show at this moment (24)


There was a problem with this version of the function, it seemed that synchronising the boolean also synchronised it with replays, which meant that it always returned true. To prevent this the function has completely been rewritten, the returning value now does not need to be synchronised and it works fully functionally with replays and in multiplayer

The function has been completely recoded, a lot of silly uneeded stuff was removed (the 2 sync functions have been removed and the globals) and I have just tested it and it works prefectly as intended
PandaMine is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[JASS] Jass function crashs the game!!! Chaos-Mapper Triggers & Scripts 15 05-01-2008 01:30 PM
keep getting an error message wit this jass function DurotarLord Map Development 7 01-24-2006 02:10 PM
Jass function:AddLightningEx, does not always work properly? Lookoverthere Triggers & Scripts 0 12-29-2005 05:18 AM
[JASS] First JASS Function...err Kramy Triggers & Scripts 2 11-21-2005 09:36 AM
[JASS] function jass or maybe triggers.. help!! Tabris Triggers & Scripts 0 06-09-2004 09:45 AM

All times are GMT. The time now is 08:33 AM.






Your link here 
Remortgages | Los Angeles Car Accident Attorney | Credit Cards | Bulgarian Property | Credit Card Offers
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Copyright©Ralle