Item-based Upgrade System
3 posters
Page 1 of 1
Item-based Upgrade System
Alright Myre, here it is. Just plug the code into your map (make sure the trigger names are exactly what I tell you to make them), fill out the values, and test away.
Code 1: "The Meat and Potatoes"
This code is what does all the work for you. It fires automatically, on its own. All you need to do is put it in the item + upgrade values in Code 2.
(Note: The trigger name MUST match the text following "scope" (first line). No spaces, either. So if the trigger name is "riffraff", the first line should be "scope riffraff".)
Code 2: "The Broth"
Here, you set your values. The trigger name can be whatever you want, doesn't matter. What does, is two things:
1: You MUST call "Set_Values" at some point (1-2 seconds) after map initialization.
2: You need to set all the values (at least the ones you plan to use) for this to work. Instructions are included, and if you have any questions you can ask.
That should be it. If you have any questions, or if something doesn't work, let me know.
Code 1: "The Meat and Potatoes"
This code is what does all the work for you. It fires automatically, on its own. All you need to do is put it in the item + upgrade values in Code 2.
(Note: The trigger name MUST match the text following "scope" (first line). No spaces, either. So if the trigger name is "riffraff", the first line should be "scope riffraff".)
- Code:
scope UpgradeComputer
globals
//The following are given their values in the "Set Values" trigger.
integer array ATK_ITEM_IDS[10] //The array of item IDs for attack upgrades
integer array DEF_ITEM_IDS[10] //Same as above, for defense upgrades
integer array HP_ITEM_IDS[10] //Same as above, for hp upgrades
integer array ATK_UPG_IDS[10] //Ids of the attack upgrades
integer array DEF_UPG_IDS[10] //Ids of the defense upgrades
integer array HP_UPG_IDS[10] //Ids of the hp upgrades
private constant integer COMPUTER_ID = 13 //The # of the computer player
//In JASS, player #'s start from 0. So it goes:
//0 == Player 1 (Red)
//1 == Player 2 (Blue)
//And so on. Just put the Computer's JASS-number (Player number - 1, really) in there.
endglobals
private function Conditions takes nothing returns boolean
local integer i = 1
local integer id = GetItemTypeId(GetManipulatedItem())
loop
exitwhen i > 10
if id == ATK_ITEM_IDS[i] or id == DEF_ITEM_IDS[i] or id == HP_ITEM_IDS[i] then
return true
else
set i = i + 1
endif
return false
endfunction
private function Actions takes nothing returns nothing
local integer id = GetItemTypeId(GetManipulatedItem())
local integer i = 1
local integer upgrade = 0
local boolean found = false
//Checking the attack upgrades
loop
exitwhen i > 10 or found == true
if id == ATK_ITEM_IDS[i] then
set upgrade = ATK_UPG_IDS[i]
set ATK_ITEM_IDS[i] = 0
set found = true
else
set i = i + 1
endif
endloop
//Wasn't an attack upgrade, checking for defense
if found != true then
set i = 1
loop
exitwhen i > 10 or found == true
if id == DEF_ITEM_IDS[i] then
set upgrade = DEF_UPG_IDS[i]
set DEF_ITEM_IDS = 0
set found = true
else
set i = i + 1
endif
endloop
endif
//Wasn't either of them, checking for HP now
if found != true then
set i = 1
loop
exitwhen i > 10 or found == true
if id == HP_ITEM_IDS[i] then
set upgrade = HP_UPG_IDS[i]
set HP_ITEM_IDS[i] = 0
set found = true
else
set i = i + 1
endif
endloop
endif
call SetPlayerTechResearched(COMPUTER_ID, upgrade, i)
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition(t, Condition( function Conditions ) )
call TriggerAddAction(t, function Actions )
set t = null
endfunction
endscope
Code 2: "The Broth"
Here, you set your values. The trigger name can be whatever you want, doesn't matter. What does, is two things:
1: You MUST call "Set_Values" at some point (1-2 seconds) after map initialization.
2: You need to set all the values (at least the ones you plan to use) for this to work. Instructions are included, and if you have any questions you can ask.
- Code:
library
function Set_Values takes nothing returns nothing
//Replace the "Ixxx" with the rawcode ID of each upgrade item (not the upgrade), IN ORDER.
//The 0's are placeholders in case you wanna add more levels later
set ATK_ITEM_IDS[1] = 'Ixxx'
set ATK_ITEM_IDS[2] = 'Ixxx'
set ATK_ITEM_IDS[3] = 'Ixxx'
set ATK_ITEM_IDS[4] = 'Ixxx'
set ATK_ITEM_IDS[5] = 'Ixxx'
set ATK_ITEM_IDS[6] = 0
set ATK_ITEM_IDS[7] = 0
set ATK_ITEM_IDS[8] = 0
set ATK_ITEM_IDS[9] = 0
set ATK_ITEM_IDS[10] = 0
set DEF_ITEM_IDS[1] = 'Ixxx'
set DEF_ITEM_IDS[2] = 'Ixxx'
set DEF_ITEM_IDS[3] = 'Ixxx'
set DEF_ITEM_IDS[4] = 'Ixxx'
set DEF_ITEM_IDS[5] = 'Ixxx'
set DEF_ITEM_IDS[6] = 0
set DEF_ITEM_IDS[7] = 0
set DEF_ITEM_IDS[8] = 0
set DEF_ITEM_IDS[9] = 0
set DEF_ITEM_IDS[10] = 0
set HP_ITEM_IDS[1] = 'Ixxx'
set HP_ITEM_IDS[2] = 'Ixxx'
set HP_ITEM_IDS[3] = 'Ixxx'
set HP_ITEM_IDS[4] = 'Ixxx'
set HP_ITEM_IDS[5] = 'Ixxx'
set HP_ITEM_IDS[6] = 0
set HP_ITEM_IDS[7] = 0
set HP_ITEM_IDS[8] = 0
set HP_ITEM_IDS[9] = 0
set HP_ITEM_IDS[10] = 0
//The following are for the actual upgrades used, not the items to trigger them.
//The same stuff applies for the following as it does above.
set ATK_UPG_IDS[1] = 'Rxxx'
set ATK_UPG_IDS[2] = 'Rxxx'
set ATK_UPG_IDS[3] = 'Rxxx'
set ATK_UPG_IDS[4] = 'Rxxx'
set ATK_UPG_IDS[5] = 'Rxxx'
set ATK_UPG_IDS[6] = 0
set ATK_UPG_IDS[7] = 0
set ATK_UPG_IDS[8] = 0
set ATK_UPG_IDS[9] = 0
set ATK_UPG_IDS[10] = 0
set DEF_UPG_IDS[1] = 'Rxxx'
set DEF_UPG_IDS[2] = 'Rxxx'
set DEF_UPG_IDS[3] = 'Rxxx'
set DEF_UPG_IDS[4] = 'Rxxx'
set DEF_UPG_IDS[5] = 'Rxxx'
set DEF_UPG_IDS[6] = 0
set DEF_UPG_IDS[7] = 0
set DEF_UPG_IDS[8] = 0
set DEF_UPG_IDS[9] = 0
set DEF_UPG_IDS[10] = 0
set HP_UPG_IDS[1] = 'Rxxx'
set HP_UPG_IDS[2] = 'Rxxx'
set HP_UPG_IDS[3] = 'Rxxx'
set HP_UPG_IDS[4] = 'Rxxx'
set HP_UPG_IDS[5] = 'Rxxx'
set HP_UPG_IDS[6] = 0
set HP_UPG_IDS[7] = 0
set HP_UPG_IDS[8] = 0
set HP_UPG_IDS[9] = 0
set HP_UPG_IDS[10] = 0
endfunction
endlibrary
That should be it. If you have any questions, or if something doesn't work, let me know.
Re: Item-based Upgrade System
I know the code is for Myre, but I'm curious. what do these codes do?
Mooo-Gunsniper- Admin
-
Number of posts : 481
Location : "Canadia"
Age : 30
Reputation : 3
Registration date : 2008-04-24
Re: Item-based Upgrade System
It's for an upgrade system in BFaC's Last Stand. The version this is going to be in is going through a complete overhaul with new terrain and such, so it's going to take me a while to release a version with this implemented. Good news is though, BFaC's forces will stand a better chance further into the game. They'll still get owned though.
Myre- Moderator
-
Number of posts : 280
Location : In a time paradox.
Reputation : 0
Registration date : 2008-05-11
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|