Hello, I am currently creating an ammunition system that the ammo shows up as charges on a permanent item, and if you run out of the charges you can't attack anymore.
I am new to JASS and have a few questions about my script...
1. How do i remove an integer leak? I try to set it to null and JASSCRAFT says i cant convert an integer to null.
2. I have tested it, and even when the unit has ammo, it orders him stop and displays the message. what am I doing wrong?
3. I had heard somewhere that you can remove the attack ability from a unit (and give it back later), is this true? It would make things a hell of a lot easier.
4. JC says that 2 lines of my script is wrong. (its in bold).
I am new to JASS and have a few questions about my script...
1. How do i remove an integer leak? I try to set it to null and JASSCRAFT says i cant convert an integer to null.
2. I have tested it, and even when the unit has ammo, it orders him stop and displays the message. what am I doing wrong?
3. I had heard somewhere that you can remove the attack ability from a unit (and give it back later), is this true? It would make things a hell of a lot easier.
4. JC says that 2 lines of my script is wrong. (its in bold).
Code:
//|----------------------|
//| AMMUNITION SYSTEM|
//|----------------------|
//note that I000 is the default item for ammunition until further versions.
//clip item is 'I001'
//the following function "ammoatizes" the unit.
function CreateAmmoUnit takes unit u, integer i returns nothing
local item it=CreateItem('I000', GetUnitX(u), GetUnitY(u))
call UnitAddItem(u, it)
call SetItemCharges(it, i)
endfunction
function UseAmmo takes unit u, integer i returns nothing //This sets the charges to be lower
local item it=UnitItemInSlot(u, 1)
local integer int
set int=GetItemCharges(it)-i
call SetItemCharges(it, int)
endfunction
function AddAmmo takes unit u, integer i returns nothing //this adds ammo
local item it=UnitItemInSlot(u, 1)
local integer int
set int=GetItemCharges(it)+i
call SetItemCharges(it, int)
endfunction
function GetAmmo takes unit u returns integer//this returns the charges in slot 1,
//the default slot for ammo(undroppable)
local integer i=GetItemCharges(UnitItemInSlot(u,1))
return i
endfunction
function AmmoErrorMessage takes integer i, player p returns nothing //this is for messages
local string message
if i==0 then
set message="You don't have enough ammunition to attack."
call DisplayTimedTextToForce(GetForceOfPlayer(p), 5.00, message)
elseif i==1 then
set message="The maximum ammunition you can have is 100."
call DisplayTimedTextToForce(GetForceOfPlayer(p), 5.00, message)
elseif i==2 then
set message="You don't have any ammunition."
call DisplayTimedTextToForce(GetForceOfPlayer(p), 5.00, message)
elseif i==3 then
set message="The maximum number of clips you can have is 100."
call DisplayTimedTextToForce(GetForceOfPlayer(p), 5.00, message)
elseif i==4 then
set message="Your Hero is trying to attack, but doesn't have any ammunition."
call DisplayTimedTextToForce(GetForceOfPlayer(p), 5.00, message)
endif
endfunction
//
//now time for triggers
//
function Trig_Attacking_Actions takes nothing returns nothing
local integer i
if GetIssuedOrderIdBJ() == String2OrderIdBJ("attack") then //this is if its actually ordered to attack
[COLOR="Red"][B] if not GetItemType(UnitItemInSlot(GetOrderedUnit(), 1))=='I000' then[/B][/COLOR]
call IssueImmediateOrderBJ( GetOrderedUnit(), "stop" )
call AmmoErrorMessage(0, GetTriggerPlayer())
elseif GetAmmo(GetOrderedUnit())<1 then //checks if it has no ammo
call IssueImmediateOrderBJ( GetOrderedUnit(), "stop" )
call AmmoErrorMessage(0, GetTriggerPlayer())
else
call UseAmmo(GetOrderedUnit(), 1) //if nothing's wrong, it sets the charges
endif
elseif GetIssuedOrderIdBJ() == String2OrderIdBJ("smart") then
//this does the exact same thing as the previous one, only
//this is for it is a "smart" attack,
//A.K.A. not ordered to attack, it did it on its own.
[COLOR="red"] [B]if not GetItemType(UnitItemInSlot(GetOrderedUnit(), 1))=='I000' then[/B][/COLOR]
call IssueImmediateOrderBJ( GetOrderedUnit(), "stop" )
call AmmoErrorMessage(0, GetTriggerPlayer())
elseif GetAmmo(GetOrderedUnit())<1 then
call IssueImmediateOrderBJ( GetOrderedUnit(), "stop" )
call AmmoErrorMessage(0, GetTriggerPlayer())
else
call UseAmmo(GetOrderedUnit(), 1)
endif
endif
endfunction
//===========================================================================
function InitTrig_Attacking takes nothing returns nothing
set gg_trg_Attacking = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Attacking, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddAction( gg_trg_Attacking, function Trig_Attacking_Actions )
endfunction
//yea yea, I know I have a lot of simialar functions, but I like to write scripts this way,
//instead of writing it out everytime, I like to keep it simple
//thanks for the help I hope you give me!