• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Custom JASS Natives - (Requests & Submissions)

Status
Not open for further replies.
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
  1. JNGP
  2. SharpCraft

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

  • 3rd Person Camera.w3x
    27.4 KB · Views: 427
  • SharpCraft - Natives.w3x
    19.8 KB · Views: 323
  • SharpCraft - THW Chatroom.w3x
    22.1 KB · Views: 372
  • plugins.zip
    19.1 KB · Views: 377
  • Extract-Play.zip
    378.9 KB · Views: 331
Last edited:
PurgeandFire said:
Is there anyway to sync these values? Or retrieve them for particular players? e.g.:

AFAIK, no.

It always detects for the local player.

With WarCom it may be possible, but right now I don't think so.

PurgeandFire said:
Otherwise, I assume they work kinda like GetCameraTargetPositionX/Y(), right?

Yeah
 
Can you use this in Bnet??

Yes but the natives won't be synced.

Is it possible to emulate an order given by some player, i mean just like you do with the mouse/keyboard ?
If you can, then i have a silly awesome idea about how to use it.

Yes

Queuing orders pls, unit loses order, unit starts/stops moving events.

I am waiting for MindWorX to provide support for events in SharpCraft before I create any.

Thanks for the suggestions.

Updated with String API (unfinished)
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
Level 16
Joined
Jul 31, 2012
Messages
2,217
That is still nonsence for now, i'm talking about the hundred (well maybe thousands) of people that don't search hive, and so, do not know about this (and maybe neither of the JNGP)
Still, i think this is for more complexe (hive reserved) maps, not like maps that are published everywhere and has some reputation, like IID
 
Level 16
Joined
Aug 7, 2009
Messages
1,403
By the way do we have a documentation of what we can reach using SharpCraft (with class names too)? I was thinking of making an ability modifier type of library where you could dinamically change the icon, tooltip and stats of abilities (and I'd also like to make it possible to reset individual cooldowns for units, but I don't exactly know how it's stored and how it works, so the ability library should be fine, for now). I study C# this semester, so it'd be nice if I could practice what I've learned so far with "serious" things, I'm sick of of all the "make these classes, implement these getters/setter, make a constructor, implement a compareTo method and make a method that sorts an array and returns with it" tests that we have, because they're ridicilous....

It's nice to see that RtC is finally getting some love :)
 
By the way do we have a documentation of what we can reach using SharpCraft (with class names too)? I was thinking of making an ability modifier type of library where you could dinamically change the icon, tooltip and stats of abilities (and I'd also like to make it possible to reset individual cooldowns for units, but I don't exactly know how it's stored and how it works, so the ability library should be fine, for now). I study C# this semester, so it'd be nice if I could practice what I've learned so far with "serious" things, I'm sick of of all the "make these classes, implement these getters/setter, make a constructor, implement a compareTo method and make a method that sorts an array and returns with it" tests that we have, because they're ridicilous....

It's nice to see that RtC is finally getting some love :)

For now you can check out the GitHub page or check the source of the plugins in the main post. There's currently not much documentation but I'd be glad to help you with whatever you need and I'm sure MindWorX would too.

Right now SharpCraft doesn't support modifying object structs (W3UNITINFO, W3ABILITYINFO ect..). This means you can't create natives like SetAbilityTooltip like you could with RtC. If you know what you're doing you can implement those yourself, until then you'll have to wait for MindWorX to do it.

I will be updating the thread with Events for the mouse natives later today along with some more functions.
 

MindWorX

Tool Moderator
Level 20
Joined
Aug 3, 2004
Messages
709
Is there anyway to sync these values? Or retrieve them for particular players? e.g.:
GetMouseX takes player p returns real

Otherwise, I assume they work kinda like GetCameraTargetPositionX/Y(), right?

You can sync it using a GetLocalPlayer block and then syncing the gamecache. :) It's not fast enough for FPS, but it's an option.
 
Last edited:
Level 16
Joined
Aug 7, 2009
Messages
1,403
For now you can check out the GitHub page or check the source of the plugins in the main post. There's currently not much documentation but I'd be glad to help you with whatever you need and I'm sure MindWorX would too.

Right now SharpCraft doesn't support modifying object structs (W3UNITINFO, W3ABILITYINFO ect..). This means you can't create natives like SetAbilityTooltip like you could with RtC. If you know what you're doing you can implement those yourself, until then you'll have to wait for MindWorX to do it.

I will be updating the thread with Events for the mouse natives later today along with some more functions.

Okay, I see. Thanks for the reply. Well, I think I'll just wait for the necessary changes then, and maybe try to figure out something cooler instead, propably something related to data structures, or something. IDK.

A way to detect who clicked on a trackable is also something that has A LOT of potential. Or at least at first I thought it had, but with mouse events that's no longer the case :'D
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Syncing is pretty much the idea i have in mind if you can simulate a player unit order.

@Luorax : it's already possible, even if it means X trackables and X triggers for X players and play with GetLocalPlayer and "" string for trackable path model, instead of 1 trackable and 1 trigger for X players.
And yes it works, or at least it worked.
 
Last edited:
So what, custom trigger events ?
Still local stuff or it will trigger for each computer ?

Or you "just" have added these constants integers ?
Ofc i'm not bitching, just trying to understand what's new.

Check the main post the events are listed there.

I will do my best to get natives synced on WarCom but they won't be synced on battle.net AFAIK.
 
Update
  • Http support.
  • StringContains/StringCount added.

JASS:
//http
    native HttpRequest    takes string method, string url, string cookies, string values returns string
    native HttpLastCookie takes nothing returns string
//string
    native StringContains  takes string str, string sub returns boolean
    native StringCount     takes string str, string sub returns integer

Here's me logging into the chatroom in JASS with the Http functions.

thwchat-inw3.jpg
 
Status
Not open for further replies.
Top