HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Pistol Reloading Sidearm

12-29-2006, 10:22 PM#1
illidan92
I was trying to do this with GUI but I think it's impossible without more than 1 trigger and some global variables and confusing crap, so here it is in JASS:
Collapse JASS:
function Trig_Shooting_Pistols_JASS_Func002Func004C takes nothing returns boolean
    if ( not ( udg_Pistol_Ammo[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))] <= 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Shooting_Pistols_JASS_Func002Func007C takes nothing returns boolean
    if ( ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) <= GetRandomInt(60, 75) ) ) then
        return true
    endif
    if ( ( GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD) <= 76 ) ) then
        return true
    endif
    return false
endfunction

function Trig_Shooting_Pistols_JASS_Func002C takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A01Y' ) ) then
        return false
    endif
    if ( not ( udg_Pistol_Ammo[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))] > 0 ) ) then
        return false
    endif
    if ( not Trig_Shooting_Pistols_JASS_Func002Func007C() ) then
        return false
    endif
    return true
endfunction

function Trig_Shooting_Pistols_JASS_Actions takes nothing returns nothing
    local unit u
    if ( Trig_Shooting_Pistols_JASS_Func002C() ) then
        set udg_Pistol_Ammo[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))] = ( udg_Pistol_Ammo[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))] - 1 )
        call AdjustPlayerStateBJ( GetRandomInt(1, 8), GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD )
        call TriggerSleepAction( 0.10 )
        if ( Trig_Shooting_Pistols_JASS_Func002Func004C() ) then
            set u=GetSpellAbilityUnit()
            set udg_Player_Pistol_Reloading[GetConvertedPlayerId(GetOwningPlayer((u)))] = true
            call AdjustPlayerStateBJ( -5, GetOwningPlayer((u)), PLAYER_STATE_RESOURCE_LUMBER )
            call UnitRemoveAbilityBJ( 'A01Y', (u) )
            call PlaySoundOnUnitBJ( gg_snd_colt_clipout_C, 100, (u) )
            call PolledWait( 2.00 )
            call PlaySoundOnUnitBJ( gg_snd_colt_clipin_C, 100, (u) )
            call PolledWait( 0.50 )
            set udg_Pistol_Ammo[GetConvertedPlayerId(GetOwningPlayer((u)))] = 5
            call UnitAddAbilityBJ( 'A01Y', (u) )
            set udg_Player_Pistol_Reloading[GetConvertedPlayerId(GetOwningPlayer((u)))] = false
        else
            call IssueImmediateOrderBJ( GetSpellAbilityUnit(), "stop" )
        endif
    else
    endif
endfunction

//===========================================================================
function InitTrig_Shooting_Pistols_JASS takes nothing returns nothing
    set gg_trg_Shooting_Pistols_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Shooting_Pistols_JASS, EVENT_PLAYER_UNIT_SPELL_CHANNEL )
    call TriggerAddAction( gg_trg_Shooting_Pistols_JASS, function Trig_Shooting_Pistols_JASS_Actions )
endfunction

It triggers it to shoot and will reload in the same trigger. If anyone can find any leaks or anything wrong with it please tell me. The spell is based off of carrion swarm as a secondary weapon for snipers or machine gunners and works beautifully. Normally if your lumber is magazines you should only deduct 1 wood, but for snipers each one is a bullet because in WW2 you had to manually load each round into the gun, so to match the amount of bullets I had to use 5 (springfields and K98s would hold 5 rounds). I used gold as gun heat so you can remove those conditions if you want.
12-29-2006, 11:39 PM#2
Anopob
1st of all, for your conditions, I don't think you need tons of those if's. I learnt that you can just use return [condition here] and it should work. Also, at the end of Trig_Shooting_Pistols_JASS_Actions, do set u = null
And I'll see if I can find anything else.

EDIT: It works and you just want to get help for the leaks, right?
12-29-2006, 11:57 PM#3
illidan92
Quote:
Originally Posted by Anopob
1st of all, for your conditions, I don't think you need tons of those if's. I learnt that you can just use return [condition here] and it should work. Also, at the end of Trig_Shooting_Pistols_JASS_Actions, do set u = null
And I'll see if I can find anything else.

EDIT: It works and you just want to get help for the leaks, right?
Yeah.

I'll get to work on that stuff soon, thanks.