Please help correct my System

Bankde

Member
Reaction score
20
It's not really system, just a item-sell function. I've tested it and it worked only for the first slot of hero. (No matter what I type the number, the result come out as slot1)

Code:
function Trig_Item_Sell_Conditions takes nothing returns boolean
    if ( SubStringBJ(GetEventPlayerChatString(), 1, 6) == "-sell " ) and ( S2I(SubStringBJ(GetEventPlayerChatString(), 7, 7)) <= 6 ) and ( S2I(SubStringBJ(GetEventPlayerChatString(), 7, 7)) >= 1 ) then
        return true
    endif
    return false
endfunction

function Trig_Item_Sell_Actions takes nothing returns nothing
    local string Message
    local item SoldItem = UnitItemInSlot(udg_Player_Hero[GetConvertedPlayerId(GetTriggerPlayer())],S2I(SubString(GetEventPlayerChatString(),7,7)))
    if GetItemType(SoldItem) == ITEM_TYPE_CHARGED then
        set Message = "You cannot sell the Charged Item"
    else
        call UnitRemoveItemFromSlot(udg_Player_Hero[GetConvertedPlayerId(GetTriggerPlayer())], S2I(SubString(GetEventPlayerChatString(),7,7)))
        set Message = "You have sold " + GetItemName(SoldItem) + " for " + I2S(GetItemLevel(SoldItem)*2) + " gold."
        call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD) + GetItemLevel(SoldItem)*2)
        call RemoveItem( SoldItem )
    endif
    call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 10, Message)
endfunction

//===========================================================================
function InitTrig_Item_Sell takes nothing returns nothing
    set gg_trg_Item_Sell = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_Item_Sell, Condition( function Trig_Item_Sell_Conditions ) )
    call TriggerAddAction( gg_trg_Item_Sell, function Trig_Item_Sell_Actions )
endfunction

udg_Player_Hero is variable which I set to hero when the player is picking.

The command is "-sell (number of slot)" for example: -sell 1
It seems to work only first slot but I can't find anything wrong.

Thank you very much for helping. +rep to all helpful reply.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
I think your sub string should be from 6 - 7:

SubString works likes so [x, y)
JASS:
// 

// &quot;-sell 1&quot;
    01234567
GetEventPlayerChatString(), 6, 7) // to extract slot number
GetEventPlayerChatString(), 0, 6) == &quot;-sell &quot;

I guess you always get the first item(slot 0) becuase S2I("") == 0
 

Bankde

Member
Reaction score
20
It seem to be strange but when I change it, ... it work !! Thank you so much !!! +rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top