Need help on spell creation from typing

Nyph

Occasional News Reader
Reaction score
87
Im working on a small-ish project and i need a system to create a spell by saying -csp <spellcode>,<numberofeffects>,<spelleffect1>,<spelleffect1intensity>,<spelleffect#>,<spelleffect#intensity>

I have a system for doing the effects but i don't have a very good idea on how
to do the saving of variables through substrings.

I've tried heaps of stuff on it in the last couple of hours but i can't find how to get an integer from a substring.
Can anyone help me here? I want to do it without jass and i dont care how much custom script i use.
 

Somatic

You can change this now in User CP.
Reaction score
84
Check if Substring (x,y) = String(integer X)

I guess this is it.... hope it helps
 

Nyph

Occasional News Reader
Reaction score
87
Nope that didn't do anything because what i want it to do is take an integer from a place in a substring and checking if (x,y) = String(integer x) doesnt do it for me.
 
Reaction score
333
Im working on a small-ish project and i need a system to create a spell by saying -csp <spellcode>,<numberofeffects>,<spelleffect1>,<spelleffect1intensity>,<spelleffect#>,<spelleffect#intensity>

I have a system for doing the effects but i don't have a very good idea on how
to do the saving of variables through substrings.

I've tried heaps of stuff on it in the last couple of hours but i can't find how to get an integer from a substring.
Can anyone help me here? I want to do it without jass and i dont care how much custom script i use.

I was working on a map and came across a similar problem.

I have written a simple system for parsing parameters in a string which are separated by commas and also a "String2Id" function which can convert a string like "A001" or "Adef" to its base-256 ID.

It is in vJass, but if you have the Jass Newgen pack you can just paste everything in the map header or a few triggers and then call it with custom scripts.

JASS:
library Functions

function StringFind takes string find, string subject, integer offset returns integer
    local integer len = StringLength(find)
    local integer pos = offset
    local string s
    local string str

    if ( offset &lt; 1 ) then
        set pos = 1
    endif
    if ( find == &quot;&quot; ) then
        return -1
    endif

    loop
        set s = SubStringBJ(subject, pos, pos+len-1)
        if ( s == find ) then
            return pos
        endif
        if ( SubStringBJ(subject, pos, pos) == &quot;&quot; ) then
            return -1
        endif
        set pos = pos + 1
    endloop
    return -1
endfunction

function AsciiCharToInteger takes string char returns integer
    local string charMap = &quot; !\&quot;#$%&amp;&#039;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~&quot;
    local string u = SubString(char, 0, 1)
    local string c
    local integer i = 0
    if u == &quot;&quot; or u == null then
        return 0
    elseif u == &quot;\b&quot; then // Backspace?
        return 8
    elseif u == &quot;\t&quot; then // Horizontal Tab?
        return 9
    elseif u == &quot;\n&quot; then // Newline
        return 10
    elseif u == &quot;\f&quot; then // Form feed?
        return 12
    elseif u == &quot;\r&quot; then // Carriage return
        return 13
    endif
    loop
        set c = SubString(charMap, i, i + 1)
        exitwhen c == &quot;&quot;
        if c == u then
            return i + 32
        endif
        set i = i + 1
    endloop
    return 0
endfunction

function StringToId takes string s returns integer
    local integer a = AsciiCharToInteger(SubString(s, 0, 1))
    local integer i = 0

    loop
        set i=i+1
        exitwhen i &gt;= StringLength(s)

        set a=a*256+AsciiCharToInteger(SubString(s, i, i+1))
    endloop

    return a
endfunction

endlibrary


JASS:
library Parser requires Functions

    globals
        private string AllowedParamChars = &quot; -1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
    endglobals
    
    struct ParamData
        integer a = 0
        string array params [10]

        method AddParam takes string s returns nothing
            if (this.a &lt; 10) then
                set this.params[this.a] = s
                set this.a = this.a+1
            endif
        endmethod
        
        method onDestroy takes nothing returns nothing
            local integer i = 0

            loop
                exitwhen i&gt;=this.a
                set this.params<i> = null
                set i = i+1
            endloop
        endmethod
    endstruct

    function GetParamData takes string s returns ParamData
        local integer i = 0
        local string a = &quot;&quot;
        local string c = &quot;&quot;
        local ParamData dat = ParamData.create()

        loop
           exitwhen i&gt;StringLength(s)

           set a = SubString(s, i, i+1)
           
           if (StringFind(a, AllowedParamChars, 0)&gt;-1 and a != &quot;&quot;) then
               set c=c+a
           elseif (SubString(s, i, i+2) == &quot;, &quot;) then
               call dat.AddParam(c)
               set i = i+1
               set c = &quot;&quot;
           elseif (a == &quot;&quot; and c != &quot;&quot;) then
               call dat.AddParam(c)
           else
               call dat.destroy()
               return -1
           endif

           set i=i+1
        endloop

        return dat
    endfunction

endlibrary</i>


This is largely a WIP, so don't make fun of my sloppy coding.

Call the parser with:
Code:
Custom Script: call GetParamData(udg_your_string)

It takes a string like this: "foo, bar, 59, ninethousand" and then separates it into the strings "foo", "bar", "59" and "ninethousand" and stores them in the params property of the ParamData struct it returns.

To convert a string to an ID, simply call:
Code:
Custom Script: set udg_ability_id = StringToId(udg_your_string)

StringToId("A001") returns exactly the same thing as 'A001' would in the trigger editor.

Hope this helps.
 

Somatic

You can change this now in User CP.
Reaction score
84
Code:
Shells Control 
    Events 
        Player - Player 1 (Red) types a chat message containing -shells as A substring 
        Player - Player 2 (Blue) types a chat message containing -shells as A substring 
        Player - Player 3 (Teal) types a chat message containing -shells as A substring 
        Player - Player 4 (Purple) types a chat message containing -shells as A substring 
        Player - Player 5 (Yellow) types a chat message containing -shells as A substring 
        Player - Player 6 (Orange) types a chat message containing -shells as A substring 
        Player - Player 7 (Green) types a chat message containing -shells as A substring 
        Player - Player 9 (Gray) types a chat message containing -shells as A substring 
        Player - Player 8 (Pink) types a chat message containing -shells as A substring 
        Player - Player 10 (Light Blue) types a chat message containing -shells as A substring 
        Player - Player 11 (Dark Green) types a chat message containing -shells as A substring 
        Player - Player 12 (Brown) types a chat message containing -shells as A substring 
    Conditions 
    Actions 
        If (All Conditions are True) then do (Then Actions) else do (Else Actions) 
            If - Conditions 
                (Integer((Substring((Entered chat string), 9, 9)))) Not equal to 0 
                 String : Length of [Entered Chat String] Equal to 9
            Then - Actions 
                Set Shells[(Player number of (Triggering player))] = (Integer((Substring((Entered chat string), 9, 9)))) 
                Game - Display to (Player group((Triggering player))) for 4.00 seconds the text: (Shells Per Barrage Set To :  + (String(Shells[(Player number of (Triggering player))]))) 
            Else - Actions 
                Game - Display to (Player group((Triggering player))) for 4.00 seconds the text: (Shells Per Barrage Set To :  + (String(Shells[(Player number of (Triggering player))])))

This is a code i did before, i hope it kinda helps as a reference.
 

Nyph

Occasional News Reader
Reaction score
87
Thanks TheDamien, I will try to work through this. +rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top