wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-10-2006, 02:53 AM   #1
Vuen
User
 
Join Date: Mar 2003
Posts: 279

Submissions (5)

Vuen will become famous soon enough (64)Vuen will become famous soon enough (64)Vuen will become famous soon enough (64)

Spell making session 4 winner

Default Vuen's RPG Item System

This is a tutorial on creating a very simple RPG item system in JASS. The point of the system is to allow units to only carry one weapon and one armor at a time.

The system uses one single trigger, has no global variables whatsoever, and uses no separate custom script code. It is completely multiplayer-compatible, and does not require The Frozen Throne. The system is player-independant, meaning it does not matter how many heroes each player has; it will work on each individual hero. It is not completely leak-free, but the leaks are insignificant and make the trigger much easier to understand.

No prior JASS knowledge is needed. If you are new to JASS, I encourage you to use this system to help you learn it, as I will walk you through all of the code. If you don't want to learn it and just want to use it, I've attached a copy of a demo map using the system so you can copy-paste the trigger. If you're still afraid of JASS, then I recommend Taaz's Item System.

This system cannot be combined with InvX or other inventory systems. If you're interested in more inventory functionality for your RPG, modify this one or look into other systems.

Let's get started!




Setting up the trigger

The only trigger we will need is a trigger that detects when an item is acquired; all we need to do is have it recognize when a weapon or armor is purchased or picked up, and drop all other items of the same type from the unit's inventory.

So lets make the trigger:

Trigger:
ItemSystem
Collapse Events
Unit - A unit Acquires an item
Conditions
Actions

If you plan on copy-pasting code, be sure the name is exactly "ItemSystem" (capitalization is important) otherwise it won't work. Now click Edit->Convert to Custom Text.




Recognizing Item Types

What we need now is a function that will tell us whether an item is a weapon, and another for armor; these will allow the trigger to recognize items.

For this example, I will consider all Claws of Attack as weapons, and all Rings of Protection as armor (since the game doesn't really have good pre-made armor items).

Here are the functions as I have written them. Each function takes an item-type as an argument, and checks if the item type matches any of the items to be considered Weapons or Armor; if it does, it drops out of the if block and returns true, otherwise it returns false.

Collapse JASS:
function isWeapon takes integer t returns boolean
    if t == 'rat3' then
    elseif t == 'rat6' then
    elseif t == 'rat9' then
    elseif t == 'ratc' then
    elseif t == 'ratf' then
    else
        return false
    endif
    return true
endfunction

function isArmor takes integer t returns boolean
    if t == 'rde0' then
    elseif t == 'rde1' then
    elseif t == 'rde2' then
    elseif t == 'rde3' then
    elseif t == 'rde4' then
    else
        return false
    endif
    return true
endfunction

Every item in the game is identified by a 4-character alphanumeric code (called rawcode). For example, the rawcode for "Claws of Attack +12" is 'ratc'. (These are converted to integers by Warcraft, so we use integers as the type.) To see these codes, open up the Object Editor, go to items, and press Ctrl+D. The codes will then be shown beside the item names:

Zoom (requires log in)

Simply list all of the item codes you want to be considered as weapons and armor in the above functions; you can list as many items as you want for each. (For custom items, two codes will be shown; the first is the actual code, and the second shows the original item it is based on. Use the first.)




Restricting Items

Here's the meat of the trigger. We want to restrict it so that a player can only use one weapon and one armor at a time.

We'll handle weapons first. Here is the function as I have written it. Be sure to replace the original Trig_ItemSystem_Actions function.


Collapse JASS:
function ShowItemError takes string str returns nothing
    call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetManipulatingUnit())), "|cffffcc00" + str + "|r")
endfunction

function Trig_ItemSystem_Actions takes nothing returns nothing
    local integer it
    local integer ut
    local integer i
    set it = GetItemTypeId(GetManipulatedItem())
    set ut = GetUnitTypeId(GetManipulatingUnit())

    if isWeapon(it) then
        set i = 1
        loop
            exitwhen i > UnitInventorySizeBJ(GetManipulatingUnit())
            if isWeapon(GetItemTypeId(UnitItemInSlotBJ(GetManipulatingUnit(), i))) and not(UnitItemInSlotBJ(GetManipulatingUnit(), i) == GetManipulatedItem()) then
                call UnitRemoveItemFromSlotSwapped( i, GetManipulatingUnit() )
                call UnitDropItemSlotBJ( GetManipulatingUnit(), GetManipulatedItem(), i )
                call ShowItemError("You may only carry one weapon at a time.")
            endif
            set i = i + 1
        endloop
    endif
endfunction

Allow me to explain. Whenever a unit picks up an item, first it assigns the item and unit raw-codes for the item acquired and the unit acquiring it to 'it' and 'ut' respectively. Then it checks if it's a weapon. If it's not, it drops out of the trigger and nothing happens.

If it is a weapon, the system loops through all of the unit's inventory slots. It checks to see whether the item in that slot is a weapon, and makes sure it's not the item that was just picked up. When it finds such a weapon, it drops it, switches the newly acquired item into its slot, and generates an error via the ShowItemError function.


To extend this to armor, we simply repeat the same block of code, replacing "isWeapon" with "isArmor" and changing the error message:

Collapse JASS:
    if isArmor(it) then
        set i = 1
        loop
            exitwhen i > UnitInventorySizeBJ(GetManipulatingUnit())
            if isArmor(GetItemTypeId(UnitItemInSlotBJ(GetManipulatingUnit(), i))) and not(UnitItemInSlotBJ(GetManipulatingUnit(), i) == GetManipulatedItem()) then
                call UnitRemoveItemFromSlotSwapped( i, GetManipulatingUnit() )
                call UnitDropItemSlotBJ( GetManipulatingUnit(), GetManipulatedItem(), i )
                call ShowItemError("You may only carry one suit of armor at a time.")
            endif
            set i = i + 1
        endloop
    endif

Just add this block of code to the function. That's it, we're done!

If you want to add more types of items to be restricted, such as Boots, Gloves, etc., just make a new isBoots or isGloves function, and repeat the above block of code.




The Completed Trigger

Here is the entire completed trigger for your pasting purposes. All you need to do to configure it for your RPG is put the appropriate item codes in the isWeapon or isArmor functions.

Hidden information:
Collapse JASS:
//****************************
//   Vuen's RPG Item System
//        version 1.0
//***************************


function isWeapon takes integer t returns boolean
    if t == 'rat3' then
    elseif t == 'rat6' then
    elseif t == 'rat9' then
    elseif t == 'ratc' then
    elseif t == 'ratf' then
    else
        return false
    endif
    return true
endfunction

function isArmor takes integer t returns boolean
    if t == 'rde0' then
    elseif t == 'rde1' then
    elseif t == 'rde2' then
    elseif t == 'rde3' then
    elseif t == 'rde4' then
    else
        return false
    endif
    return true
endfunction




function ShowItemError takes string str returns nothing
    call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetManipulatingUnit())), "|cffffcc00" + str + "|r")
endfunction

function Trig_ItemSystem_Actions takes nothing returns nothing
    local integer it
    local integer ut
    local integer i
    set it = GetItemTypeId(GetManipulatedItem())
    set ut = GetUnitTypeId(GetManipulatingUnit())

    if isWeapon(it) then
        set i = 1
        loop
            exitwhen i > UnitInventorySizeBJ(GetManipulatingUnit())
            if isWeapon(GetItemTypeId(UnitItemInSlotBJ(GetManipulatingUnit(), i))) and not(UnitItemInSlotBJ(GetManipulatingUnit(), i) == GetManipulatedItem()) then
                call UnitRemoveItemFromSlotSwapped( i, GetManipulatingUnit() )
                call UnitDropItemSlotBJ( GetManipulatingUnit(), GetManipulatedItem(), i )
                call ShowItemError("You may only carry one weapon at a time.")
            endif
            set i = i + 1
        endloop
    endif

    if isArmor(it) then
        set i = 1
        loop
            exitwhen i > UnitInventorySizeBJ(GetManipulatingUnit())
            if isArmor(GetItemTypeId(UnitItemInSlotBJ(GetManipulatingUnit(), i))) and not(UnitItemInSlotBJ(GetManipulatingUnit(), i) == GetManipulatedItem()) then
                call UnitRemoveItemFromSlotSwapped( i, GetManipulatingUnit() )
                call UnitDropItemSlotBJ( GetManipulatingUnit(), GetManipulatedItem(), i )
                call ShowItemError("You may only carry one suit of armor at a time.")
            endif
            set i = i + 1
        endloop
    endif
endfunction

//===========================================================================
function InitTrig_ItemSystem takes nothing returns nothing
    set gg_trg_ItemSystem = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ItemSystem, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_ItemSystem, function Trig_ItemSystem_Actions )
endfunction


Attached is a demo map containing the trigger. Feel free to use without credit. Enjoy!
Attached Images
File Type: png rawcodes.PNG (16.2 KB, 1174 views)
Attached Files
File Type: w3m Vuen's RPG Item System 1.0.w3m (18.1 KB, 278 views)

Last edited by Vuen : 04-15-2006 at 10:58 AM.
Vuen is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-20-2006, 09:24 AM   #2
Vuen
User
 
Join Date: Mar 2003
Posts: 279

Submissions (5)

Vuen will become famous soon enough (64)Vuen will become famous soon enough (64)Vuen will become famous soon enough (64)

Spell making session 4 winner

Default

So it's been a solid week since I posted this... No takers? Not even a single person looked at the map (besides me)?

I figured a pre-made item system in one single trigger with no globals whatsoever would be attractive to people. :(
Vuen is offline   Reply With Quote
Old 04-20-2006, 11:03 AM   #3
Born清odificate
Fear the bananamonster!
 
Born清odificate's Avatar


Respected User
 
Join Date: Oct 2004
Posts: 369

Submissions (26)

Born清odificate is just really nice (318)Born清odificate is just really nice (318)Born清odificate is just really nice (318)

Send a message via ICQ to Born清odificate Send a message via AIM to Born清odificate
Default

Mhm it might be useful for learning jass but i think you did the labour in vain : /
everyone who has just a lil idea of gui triggering would do such a lil system himselv in gui
__________________
Born清odificate is offline   Reply With Quote
Old 04-20-2006, 10:49 PM   #4
shadow1500
STARCRAFT II OMFG
 
shadow1500's Avatar
 
Join Date: Jul 2004
Posts: 1,004

Submissions (9)

shadow1500 is just really nice (306)shadow1500 is just really nice (306)shadow1500 is just really nice (306)

Send a message via ICQ to shadow1500 Send a message via AIM to shadow1500 Send a message via MSN to shadow1500
Default

Exactly, people learn jass to make more complex system than this.
shadow1500 is offline   Reply With Quote
Old 04-21-2006, 04:53 AM   #5
Vuen
User
 
Join Date: Mar 2003
Posts: 279

Submissions (5)

Vuen will become famous soon enough (64)Vuen will become famous soon enough (64)Vuen will become famous soon enough (64)

Spell making session 4 winner

Default

But you don't even need to learn any JASS to use it, you can just paste the trigger into your map. The GUI systems people make are far more complicated and still not as powerful as this, because they rely on item-class.
Vuen is offline   Reply With Quote
Old 04-21-2006, 05:19 AM   #6
Tiki
Transform and roll out!
 
Tiki's Avatar


Respected User
 
Join Date: Dec 2002
Posts: 2,901

Submissions (11)

Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)

AI tournament - 3rd place

Default

Id use it if I had a map =P
Its very thorough aswell, and can be used on more then just armor and weapons, good job.
__________________

www.sc2armory.com - Join our forums and community.
Latest and most up to date information about starcraft II.
Tiki is offline   Reply With Quote
Old 04-21-2006, 08:03 AM   #7
kaldoreielf
User
 
kaldoreielf's Avatar
 
Join Date: Mar 2006
Posts: 179

Submissions (2)

kaldoreielf has a little shameless behaviour in the past (-5)

Send a message via MSN to kaldoreielf
Default

very good job, infact theres about a 95% chance I'll put it in Nabru :-D
__________________
My Warcraft Log - Please leave some comments!

Funny Warcraft Pictures Gallery Latest Picture: Up-close Blood Mage
kaldoreielf is offline   Reply With Quote
Old 04-21-2006, 08:42 AM   #8
Blade.dk
.
 
Blade.dk's Avatar


Respected User
 
Join Date: May 2005
Posts: 1,990

Submissions (15)

Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)

Approved Map: Azeroth's Arcane ArenaSpell session 01 winner

Send a message via MSN to Blade.dk
Default

Nice tutorial, approved. Sorry for the delay.
__________________
Spell Making Course: Part 1: Making a simple stomp spell.
I wonder if I'll ever finish part 2.
Blade.dk is offline   Reply With Quote
Old 04-21-2006, 09:34 AM   #9
Whitehorn
SPOON!
 
Whitehorn's Avatar


Respected User
 
Join Date: Sep 1983
Posts: 4,900

Submissions (114)

Whitehorn is a name known to all (510)Whitehorn is a name known to all (510)Whitehorn is a name known to all (510)Whitehorn is a name known to all (510)Whitehorn is a name known to all (510)

Default

I'd stick this in KNIGHTS to save me a job, but the map is on hold :P
__________________
My Wargame

Be excellent to each other.
Whitehorn is offline   Reply With Quote
Old 05-15-2006, 07:10 AM   #10
bounty_hunter2
User
 
bounty_hunter2's Avatar
 
Join Date: Feb 2006
Posts: 221

Submissions (5)

bounty_hunter2 is on a distinguished road (22)

Send a message via MSN to bounty_hunter2
Default

kinda good, I have my own inventory sytem but Id used this if I didn't have mine
bounty_hunter2 is offline   Reply With Quote
Old 05-15-2006, 03:38 PM   #11
Tiki
Transform and roll out!
 
Tiki's Avatar


Respected User
 
Join Date: Dec 2002
Posts: 2,901

Submissions (11)

Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)

AI tournament - 3rd place

Default

Im using this now, good job.
__________________

www.sc2armory.com - Join our forums and community.
Latest and most up to date information about starcraft II.
Tiki is offline   Reply With Quote
Old 05-16-2006, 09:08 PM   #12
Oliver
User
 
Join Date: Mar 2006
Posts: 35

Submissions (1)

Oliver has little to show at this moment (7)

Default

I made something similar to this with simple triggers (i cant do the jass) this is jsut the same 6 item inventory. I also added special effects of wepsons on hands but thats simple n u wont wanan hear :p
Oliver is offline   Reply With Quote
Old 06-03-2006, 04:26 AM   #13
Tiki
Transform and roll out!
 
Tiki's Avatar


Respected User
 
Join Date: Dec 2002
Posts: 2,901

Submissions (11)

Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)Tiki is a jewel in the rough (244)

AI tournament - 3rd place

Default

Using the system, working great. Thanks :)

Would be cool if you can choose which slot of the 6 an item will go in and is reserved. So armor like goes in slot 1 and no other item cant. =p
__________________

www.sc2armory.com - Join our forums and community.
Latest and most up to date information about starcraft II.

Last edited by Tiki : 06-03-2006 at 04:26 AM.
Tiki is offline   Reply With Quote
Old 10-04-2006, 09:47 AM   #14
Xandramas
User
 
Xandramas's Avatar
 
Join Date: Aug 2004
Posts: 59

Xandramas is on a distinguished road (10)

Default

Great trigger, very easy to understand
Xandramas is offline   Reply With Quote
Old 08-29-2007, 12:05 AM   #15
slomka
User
 
Join Date: Jul 2007
Posts: 3

slomka has little to show at this moment (0)

Default lol

wow i can't believe no has posted anything about this since 06 this is a decent system which i'll you credit for you even gave them a copy and pasted version and still no one ill probably use something like this in an orpg im planning to make and btw good job +rep
slomka is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 04:58 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services