- Joined
- Jun 23, 2007
- Messages
- 4,066
I will be updating this thread with all API created for SharpCraft. Feel free to request anything you would like to see in JASS, or submit your own creations here (including the source).
Requirements
Keyboard & Mouse
These can be used to detect mouse clicks and movement as well as detect key pressing / releasing.
Third Person Camera (With Mouse)
Interface
Various functions related to the game interface.
Stopwatch
Http
You can use these to communicate with websites.
String
Requirements
Keyboard & Mouse
These can be used to detect mouse clicks and movement as well as detect key pressing / releasing.
Third Person Camera (With Mouse)
JASS:
native GetMouseX takes nothing returns real
native GetMouseY takes nothing returns real
native GetMouseTerrainX takes nothing returns real
native GetMouseTerrainY takes nothing returns real
native GetMouseUIX takes nothing returns real
native GetMouseUIY takes nothing returns real
native GetTriggerKey takes nothing returns integer
native GetTriggerWheelDelta takes nothing returns integer
native GetTriggerKeyString takes nothing returns string
native IsMouseOverUI takes nothing returns boolean
native IsKeyDown takes integer vkey returns boolean
native TriggerRegisterAnyKeyEvent takes trigger whichTrigger, integer state returns nothing
native TriggerRegisterAnyMouseEvent takes trigger whichTrigger, integer state returns nothing
native TriggerRegisterKeyEvent takes trigger whichTrigger, integer vkey, integer state returns nothing
native TriggerRegisterMouseEvent takes trigger whichTrigger, integer vkey, integer state returns nothing
native TriggerRegisterMouseWheelEvent takes trigger whichTrigger returns nothing
JASS:
scope Mouse initializer onInit
globals
private constant integer MOUSE_LEFT = 0
private constant integer MOUSE_RIGHT = 2
private constant integer EVENT_MOUSE_DOWN = 0
private constant integer EVENT_MOUSE_UP = 1
endglobals
private function LeftDown takes nothing returns nothing
local integer vkey = GetTriggerKey()
if (vkey == MOUSE_LEFT) then
call BJDebugMsg("Left mouse clicked")
elseif (vkey == MOUSE_RIGHT) then
call BJDebugMsg("Right mouse clicked")
else
call BJDebugMsg("Unhandled key " + I2S(vkey))
endif
endfunction
private function LeftUp takes nothing returns nothing
local integer vkey = GetTriggerKey()
if (vkey == MOUSE_LEFT) then
call BJDebugMsg("Left mouse released")
elseif (vkey == MOUSE_RIGHT) then
call BJDebugMsg("Right mouse released")
else
call BJDebugMsg("Unhandled key " + I2S(vkey))
endif
endfunction
//===========================================================================
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyMouseEvent(t, EVENT_MOUSE_DOWN)
call TriggerAddAction(t, function LeftDown)
set t = CreateTrigger()
call TriggerRegisterMouseEvent(t, MOUSE_LEFT, EVENT_MOUSE_UP)
call TriggerRegisterMouseEvent(t, MOUSE_RIGHT, EVENT_MOUSE_UP)
call TriggerAddAction(t, function LeftUp)
endfunction
endscope
JASS:
scope Keyboard initializer onInit
private function KeyDown takes nothing returns nothing
call BJDebugMsg(GetTriggerKeyString() + " pressed")
endfunction
//===========================================================================
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyKeyEvent(t, 0)
call TriggerAddAction(t, function KeyDown)
endfunction
endscope
Interface
Various functions related to the game interface.
JASS:
native FramesPerSecond takes nothing returns real
native EnableChatMessages takes boolean flag returns nothing
native InterfaceMessage takes string message, integer area, real duration returns nothing
native PlayerChatMessage takes integer pid, string message, integer whichGroup, real duration returns nothing
Stopwatch
JASS:
native StopWatchCreate takes nothing returns integer
native StopWatchTicks takes integer id returns integer
native StopWatchMark takes integer id returns integer
native StopWatchDestroy takes integer id returns nothing
JASS:
scope Stopwatch initializer onInit
globals
private constant integer ITERATIONS = 4000
endglobals
private function Actions takes nothing returns boolean
local integer sw
local integer i
local real array ticks
local string output
set i = 0
set sw = StopWatchCreate()
loop
exitwhen i == ITERATIONS
// TEST 1 HERE
set i = i + 1
endloop
set ticks[0] = StopWatchTicks(sw)
set output = I2S(ITERATIONS) + " iterations of Test #1 took " + I2S(StopWatchMark(sw)) + " milliseconds to finish.\n"
call StopWatchDestroy(sw)
set i = 0
set sw = StopWatchCreate()
loop
exitwhen i == ITERATIONS
// TEST 2 HERE
set i = i + 1
endloop
set ticks[1] = StopWatchTicks(sw)
set output = output + I2S(ITERATIONS) + " iterations of Test #2 took " + I2S(StopWatchMark(sw)) + " milliseconds to finish.\n\n"
call StopWatchDestroy(sw)
if (ticks[0] > ticks[1]) then
set ticks[2] = 100 - (ticks[1]/ticks[0] * 100)
set output = output + "Test #2 was " + R2S(ticks[2]) + "% faster than Test #1\n\n"
else
set ticks[2] = 100 - (ticks[0]/ticks[1] * 100)
set output = output + "Test #1 is " + R2S(ticks[2]) + "% faster than Test #2\n\n"
endif
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, output)
return false
endfunction
//===========================================================================
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddCondition(t, function Actions)
endfunction
endscope
Http
You can use these to communicate with websites.
JASS:
native HttpLastCookie takes nothing returns string
native HttpPendingResponse takes integer id returns string
native HttpRequest takes string method, string url, string cookies, string values returns string
native StartRequest takes string method, string url, string cookies, string values, integer id returns nothing
JASS:
struct Http
string reqMethod = ""
string url = ""
string cookies = ""
string values = ""
method BeginRequest takes nothing returns nothing
call StartRequest(this.reqMethod, this.url, this.cookies, this.values, this)
endmethod
static method Post takes string url, string cookies, string values returns string
return HttpRequest("POST", url, cookies, values)
endmethod
static method Get takes string url, string cookies returns string
return HttpRequest("GET", url, cookies, "")
endmethod
static method onInit takes nothing returns nothing
local string resp = null
local Http req = Http.create()
set req.url = "hiveworkshop.com"
set req.reqMethod = "GET"
call req.BeginRequest()
loop
exitwhen resp != null
set resp = HttpPendingResponse(req)
call TriggerSleepAction(0)
endloop
call req.destroy()
call ClearTextMessages()
call BJDebugMsg(resp)
endmethod
endstruct
String
JASS:
native StringReplace takes string str, string old, string new returns string
native StringContains takes string str, string sub returns boolean
native StringCount takes string str, string sub returns integer
native StringPos takes string str, string sub returns integer
native StringReverse takes string str returns string
native StringTrim takes string str returns string
native StringTrimStart takes string str returns string
native StringTrimEnd takes string str returns string
native StringSplit takes string str, string sub, integer index returns string
native StringInsert takes string str, integer index, string val returns string
JASS:
local string str = "hello world"
call BJDebugMsg(StringReplace(str, "hello", "hey")) // hey world
call BJDebugMsg(StringReverse(str)) // dlrow olleh
call BJDebugMsg(StringInsert(str, 0, "H")) // Hello world
call BJDebugMsg(StringSplit(str, " ", 1)) // world
call BJDebugMsg(StringTrim(str)) // hello world
call BJDebugMsg(I2S(StringPos(str, "ello"))) // 1
Attachments
Last edited: