• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Sending gold to player typeing massages.

Status
Not open for further replies.
Level 14
Joined
Mar 4, 2009
Messages
1,156
I want to make sending gold easier so i don't have to click 100 times for 1 gold...
i want to do it with typing
player 1 types -100 gold to blue
add add gold to blue

how can i do that whit any typed number?

(i don't wanna make it easier clicking one time for 2 gold because it is not good in this game.....)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Using Jass for most of it since GUI would be shit for this sort of thing. Uses a string array called MessageParts and an integer variable called MessagePartsLength. The Jass script goes in the "custom script section" (select your map icon in the trigger editor and paste it into the text area at the lower right).

JASS:
function PlayerNameToPlayer takes string name returns player
    set name = StringCase(name,false)
    if name == "red" then
        return Player(0)
    elseif name == "blue" then
        return Player(1)
    elseif name == "teal" then
        return Player(2)
    elseif name == "purple" then
        return Player(3)
    elseif name == "yellow" then
        return Player(4)
    elseif name == "orange" then
        return Player(5)
    elseif name == "green" then
        return Player(6)
    elseif name == "pink" then
        return Player(7)
    elseif name == "grey" or name == "gray" then
        return Player(8)
    elseif name == "light blue" or name == "lightblue" then
        return Player(9)
    elseif name == "dark green" or name == "darkgreen" then
        return Player(10)
    elseif name == "brown" then
        return Player(11)
    endif
    return null
endfunction

function SplitString takes string to, string sp returns nothing
    local integer i = 0
    local integer l = StringLength(sp)
    local integer e = StringLength(to)
    local integer a = 0
    set udg_MessagePartsLength = -1
    loop
        exitwhen i+l>e
        if SubString(to,i,i+l) == sp then
            set udg_MessagePartsLength = udg_MessagePartsLength + 1
            set udg_MessageParts[udg_MessagePartsLength] = SubString(to,a,i)
            set a = i+l
        endif
        set i = i + 1
    endloop
    if i<=e then
        set udg_MessagePartsLength = udg_MessagePartsLength + 1
        set udg_MessageParts[udg_MessagePartsLength] = SubString(to,a,i+1)
    endif
endfunction

function GiveDigest takes player t, string in returns integer
    local integer g
    local player p
    call SplitString(in," ")
    if udg_MessagePartsLength < 3 or udg_MessagePartsLength > 4 or udg_MessageParts[1] != "gold" or udg_MessageParts[2] != "to" then
        return 0
    elseif udg_MessagePartsLength == 4 then
        set udg_MessageParts[3] = udg_MessageParts[3] + udg_MessageParts[4]
    endif
    set g = S2I(udg_MessageParts[0])
    if g < 0 then
        set g = -g
    endif
    set p = PlayerNameToPlayer(udg_MessageParts[3])
    if g > 0 and g <= GetPlayerState(t,PLAYER_STATE_RESOURCE_GOLD) and p != null then
        call SetPlayerState(t,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(t,PLAYER_STATE_RESOURCE_GOLD)-g)
        call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+g)
        return g
    endif
    return 0
endfunction

Then the GUI component, uses integer variable GoldReturned.

  • Send Gold
    • Events
      • Player - Player 1 (Red) types a chat message containing gold to as A substring
      • -------- Repeat for the other players --------
    • Conditions
    • Actions
      • Custom script: set udg_GoldReturned = GiveDigest(GetTriggerPlayer(),GetEventPlayerChatString())
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • GoldReturned Greater than 0
        • Then - Actions
          • -------- Display a message confirming the gold was sent --------
        • Else - Actions
          • -------- Display a message informing the user the command failed --------
 
Level 8
Joined
Mar 12, 2008
Messages
437
Maybe "-give 100 02" that gives 100 gold to player 02 (blue).
Then you have to check if the first 5 are "give". You also have to check which number the two last are, and which number is inbetween the 6th first and 3rd last letters.

Otherwise, you can use a system that's easier to use but harder to make:

"-give 100 to blue"

Then you first need to check what the last three letters are to find out what number the player wrote:
red
lue -> First, check if the last ten are "light blue". If not, check if the last four are "blue".
eal -> check if the last four are "teal"
ple -> check if the last six are "purple"
low -> yellow
nge -> orange
een -> green or dark green. Here you'll have to do a double check.
ink -> pink
ray -> gray
own -> brown

Then make an integer variable and set it to the length of the string (eg. 5 for brown, 3 for red).

Then compare if the last variable+1 to variable+4 are equal to " to ". Then you can just check what number it is between letter number 7 and last variable+5 letters.
 
Level 14
Joined
Mar 4, 2009
Messages
1,156
Using Jass for most of it since GUI would be shit for this sort of thing. Uses a string array called MessageParts and an integer variable called MessagePartsLength. The Jass script goes in the "custom script section" (select your map icon in the trigger editor and paste it into the text area at the lower right).

I am nto shure did i do it good but i have error with costum scrip code
 
Status
Not open for further replies.
Top