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 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