From The Mana World
m (Gumi moved page User:Meko/Tiled/NPC Proposal to User:Gumi/Tiled/NPC Proposal: Automatically moved page while renaming the user "Meko" to "Gumi")
 
(75 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This proposal is to enable npc creation from Tiled.
This proposal is to enable npc creation from Tiled. It could even provide a way to add a "npc finder" to manaplus so that players can easily know where a npc is (manaplus would simply have to look at the tmx).
Should not be used for floating npcs (no map).
Should not be used for floating npcs (no map).


= Usage =
= Usage =
For the examples below we will use the map 009-1 and position 25, 25. The only mandatory property is "callfunc"
For the examples below we will use the map 009-1 and position 25, 25. The only mandatory property to make a npc is "callfunc". To make a store, put "items" instead of "callfunc".
<br>
<br>
== Basic npc ==
== Shop npc [RC] ==
Object type: NPC<br>
Object type: shop<br>
Object name: FooBar#Baz
Object name: FooBar#Baz
{| class="wikitable" border="1"
|-
! Property
! Value
|-
| items
| '''Item,Item:*2,Item,Item:9'''
|}
Gives in Hercules: <pre>
009-1,25,25,0    shop    FooBar#Baz    32767,Item:*1,Item:*2,Item:*1,Item:9
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,0|shop|FooBar#Baz|32767,Item:*1,Item:*2,Item:*1,Item:9
</pre>
<br>
== Semi-anonymous npc ==
When you have multiple copies of a npc with the same name, you can add '''#''' at the end '''without anything else''' to append an auto-generated suffix. For example, the barrels would become barrel# instead of barrel#(number). This way you do not have to worry about giving a safe name to a npc.
This also works for npcs starting and ending with # like #Knockback#.
<br><br>
Object type: npc<br>
Object name: FooBar'''#'''
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
Line 17: Line 41:
|}
|}


Gives: <pre>
Gives in Hercules: <pre>
009-1,25,25,0|script|FooBar#Baz|127
009-1,25,25,0    script    FooBar#009-1_0    32767,{
    callfunc "Qux";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,0|script|FooBar#009-1_0|32767
{
    callfunc "Qux";
    end;
}
</pre>
<br>
 
== Named npc ==
Object type: npc<br>
Object name: FooBar
{| class="wikitable" border="1"
|-
! Property
! Value
|-
| callfunc
| Qux
|}
 
Gives in Hercules: <pre>
009-1,25,25,0    script    FooBar    32767,{
    callfunc "Qux";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,0|script|FooBar|32767
{
{
    set @npcname$, "FooBar";
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
}
}
</pre>
</pre>
That's nice but the NPC does not have a visible sprite, it defaults to 127. Let's add a sprite.
That's nice but this npc is not sent to the client since its ID is 32767. Let's add a sprite.
<br><br>'''''@wushin: There is a "end;" instead of a "close;" because not all function send "mes" so "close2;" should be put before "return;" in the functions'''''
<br><br>'''''@wushin: There is a "end;" instead of a "close;" because not all function send "mes" so "close2;" should be put before "return;" in the functions'''''
<br><br>
<br><br>


== Adding a sprite ==
== Adding a sprite ==
Object type: NPC<br>
Object type: npc<br>
Object name: FooBar#Baz
Object name: #
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
Line 44: Line 102:
|}
|}


Gives: <pre>
Gives in Hercules: <pre>
009-1,25,25,0|script|FooBar#Baz|161
009-1,25,25,0    script    #009-1_anon0    161,{
    callfunc "Qux";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,0|script|#009-1_anon0|161
{
{
    set @npcname$, "FooBar";
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
}
}
</pre>
</pre>
The "sprite" property is non-mandatory and defaults to 127 when not set.
The "sprite" property is non-mandatory and defaults to [[Dev:Special_NPCs|32767]] when not set.
<br><br>
<br><br>


== Setting the direction ==
== Setting the direction ==
Object type: NPC<br>
Tiled has a built-in "Rotation" property for objects. To set the direction, set the rotation to any multiple of 90 (or a multiple of 45 if your npc supports all 8 directions). The minimum is -180 and the maximum is 180. For example, 90 is facing west and 180 (or -180) is facing north.
Object name: FooBar#Baz
<br><br>
Object type: npc<br>
Object name: FooBar#Baz<br>
Rotation: '''90'''
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
! Property
! Property
! Value
! Value
|-
| direction
| '''3'''
|-
|-
| sprite
| sprite
Line 73: Line 137:
|}
|}


Gives: <pre>
Gives in Hercules: <pre>
009-1,25,25,3    script    FooBar#Baz    161,{
    callfunc "Qux";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,3|script|FooBar#Baz|161
009-1,25,25,3|script|FooBar#Baz|161
{
{
    set @npcname$, "FooBar";
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 84: Line 154:


== Setting as debug npc ==
== Setting as debug npc ==
Object type: NPC<br>
Object type: npc<br>
Object name: FooBar#Baz
Object name: FooBar#Baz<br>
Rotation: 90
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
Line 93: Line 164:
| debug
| debug
| '''true'''
| '''true'''
|-
| direction
| 3
|-
|-
| sprite
| sprite
Line 104: Line 172:
|}
|}


Gives: <pre>
Gives in Hercules: <pre>
009-1,25,25,3    script    FooBar#Baz    161,{
    callfunc "Qux";
    end;
OnInit:
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,3|script|FooBar#Baz|161
009-1,25,25,3|script|FooBar#Baz|161
{
{
    set @npcname$, "FooBar";
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 119: Line 197:


== Adding a trigger area ==
== Adding a trigger area ==
Object type: NPC<br>
Object type: npc<br>
Object name: FooBar#Baz
Object name: FooBar#Baz<br>
Rotation: 90
<br><br>
Use tiled to mark the area of the trigger. To have a 0,0 trigger '''set the "trigger" property to "true"'''.
 
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
! Property
! Property
! Value
! Value
|-
| trigger
| '''2,4'''
|-
|-
| debug
| debug
| true
| true
|-
| direction
| 3
|-
|-
| sprite
| sprite
Line 142: Line 218:
|}
|}


Gives: <pre>
Gives in Hercules: <pre>
009-1,25,25,3    script    FooBar#Baz    161,2,4,{
    end;
OnTouch:
    callfunc "Qux";
    end;
OnInit:
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,3|script|FooBar#Baz|161,2,4
009-1,25,25,3|script|FooBar#Baz|161,2,4
{
{
     end;
     end;
OnTouch:
OnTouch;
    set @npcname$, "FooBar";
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 158: Line 246:
<br>
<br>


== Adding custom variables ==
== Adding a recurring timer ==
Object type: NPC<br>
Object type: npc<br>
Object name: FooBar#Baz
Object name: FooBar#Baz<br>
Rotation: 90
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
Line 166: Line 255:
! Value
! Value
|-
|-
| @quux
| interval
| '''19'''
| '''10000,Function'''
|-
| @norf$
| '''baz'''
|-
|-
| trigger
| trigger
Line 177: Line 263:
| debug
| debug
| true
| true
|-
| direction
| 3
|-
|-
| sprite
| sprite
Line 189: Line 272:


Gives: <pre>
Gives: <pre>
009-1,25,25,3    script    FooBar#Baz    161,2,4,{
    end;
OnTouch:
    callfunc "Qux";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
    end;
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}
</pre>
<br>
Gives in TMWA: <pre>
009-1,25,25,3|script|FooBar#Baz|161,2,4
009-1,25,25,3|script|FooBar#Baz|161,2,4
{
{
     end;
     end;
OnTouch:
OnTouch:
    set @quux, 19;
    set @norf$, "baz";
    set @npcname$, "FooBar";
     callfunc "Qux";
     callfunc "Qux";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
     end;
     end;
OnInit:
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
     if(DEBUG) end;
     if(DEBUG) end;
     disablenpc "FooBar#Baz";
     disablenpc "FooBar#Baz";
Line 204: Line 309:
}
}
</pre>
</pre>
Any property starting with @ is treated as a custom variable. Variables should be FIXED values (ie. 3), not dynamic values (ie. @foo - 3). Only temporary variables (@) can be set through NPC objects. To set global variables, please manually add a floating NPC.
<br>
<br><br>'''''@wushin: Should variables be cleaned before the "end;" ?'''''


<br><br>
== Passing arguments to the function (Hercules only) ==
 
Object type: npc<br>
= Examples =
Object name: FooBar#Baz<br>
== Debug npc ==
Rotation: 90
Object type: NPC<br>
Object name: Debug#3
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
Line 218: Line 320:
! Value
! Value
|-
|-
| sprite
| arguments
| 154
| '''19,"ba,z"'''
|-
| interval
| 10000,Function
|-
| trigger
| 2,4
|-
|-
| debug
| debug
| true
| true
|-
| sprite
| 161
|-
|-
| callfunc
| callfunc
| Debug
| Qux
|}
|}


Gives: <pre>
Gives in Hercules: <pre>
020-1,75,85,0|script|Debug#3|154
009-1,25,25,3    script   FooBar#Baz    161,2,4,{
{
    end;
     set @npcname$, "Debug";
OnTouch:
     callfunc "Debug";
     callfunc "Qux", 19, "ba,z";
    end;
OnTimer10000:
     callfunc "Function";
    initnpctimer;
     end;
     end;
OnInit:
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
     if(DEBUG) end;
     if(DEBUG) end;
     disablenpc "Debug#3";
     disablenpc "FooBar#Baz";
     end;
     end;
}
}
</pre>
</pre>
<br>
<br><br>
 


== Banker ==
== Adding custom variables (TMWA only) ==
Object type: NPC<br>
For TMWA, any property that starts with @ is interpreted as a custom variable.
Object name: Richard
<br><br>
Object type: npc<br>
Object name: FooBar#Baz<br>
Rotation: 90
{| class="wikitable" border="1"
{| class="wikitable" border="1"
|-
|-
! Property
! Property
! Value
! Value
|-
| @integer
| '''19'''
|-
| @string$
| '''ba,z'''
|-
| interval
| 10000,Function
|-
| trigger
| 2,4
|-
| debug
| true
|-
|-
| sprite
| sprite
Line 254: Line 390:
|-
|-
| callfunc
| callfunc
| Banker
| Qux
|}
|}


Gives: <pre>
Gives in TMWA: <pre>
009-2,20,99,0|script|Richard|161
009-1,25,25,3|script|FooBar#Baz|161,2,4
{
{
     set @npcname$, "Richard";
    end;
     callfunc "Banker";
OnTouch:
     set @integer, 19;
    set @string$, "ba,z";
     callfunc "Qux";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
    end;
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
     end;
     end;
}
}
</pre>
</pre>
<br>

Latest revision as of 19:42, 15 June 2020

This proposal is to enable npc creation from Tiled. It could even provide a way to add a "npc finder" to manaplus so that players can easily know where a npc is (manaplus would simply have to look at the tmx). Should not be used for floating npcs (no map).

Usage

For the examples below we will use the map 009-1 and position 25, 25. The only mandatory property to make a npc is "callfunc". To make a store, put "items" instead of "callfunc".

Shop npc [RC]

Object type: shop
Object name: FooBar#Baz

Property Value
items Item,Item:*2,Item,Item:9

Gives in Hercules:

009-1,25,25,0    shop    FooBar#Baz    32767,Item:*1,Item:*2,Item:*1,Item:9


Gives in TMWA:

009-1,25,25,0|shop|FooBar#Baz|32767,Item:*1,Item:*2,Item:*1,Item:9


Semi-anonymous npc

When you have multiple copies of a npc with the same name, you can add # at the end without anything else to append an auto-generated suffix. For example, the barrels would become barrel# instead of barrel#(number). This way you do not have to worry about giving a safe name to a npc. This also works for npcs starting and ending with # like #Knockback#.

Object type: npc
Object name: FooBar#

Property Value
callfunc Qux

Gives in Hercules:

009-1,25,25,0    script    FooBar#009-1_0    32767,{
    callfunc "Qux";
    end;
}


Gives in TMWA:

009-1,25,25,0|script|FooBar#009-1_0|32767
{
    callfunc "Qux";
    end;
}


Named npc

Object type: npc
Object name: FooBar

Property Value
callfunc Qux

Gives in Hercules:

009-1,25,25,0    script    FooBar    32767,{
    callfunc "Qux";
    end;
}


Gives in TMWA:

009-1,25,25,0|script|FooBar|32767
{
    callfunc "Qux";
    end;
}

That's nice but this npc is not sent to the client since its ID is 32767. Let's add a sprite.

@wushin: There is a "end;" instead of a "close;" because not all function send "mes" so "close2;" should be put before "return;" in the functions

Adding a sprite

Object type: npc
Object name: #

Property Value
sprite 161
callfunc Qux

Gives in Hercules:

009-1,25,25,0    script    #009-1_anon0    161,{
    callfunc "Qux";
    end;
}


Gives in TMWA:

009-1,25,25,0|script|#009-1_anon0|161
{
    callfunc "Qux";
    end;
}

The "sprite" property is non-mandatory and defaults to 32767 when not set.

Setting the direction

Tiled has a built-in "Rotation" property for objects. To set the direction, set the rotation to any multiple of 90 (or a multiple of 45 if your npc supports all 8 directions). The minimum is -180 and the maximum is 180. For example, 90 is facing west and 180 (or -180) is facing north.

Object type: npc
Object name: FooBar#Baz
Rotation: 90

Property Value
sprite 161
callfunc Qux

Gives in Hercules:

009-1,25,25,3    script    FooBar#Baz    161,{
    callfunc "Qux";
    end;
}


Gives in TMWA:

009-1,25,25,3|script|FooBar#Baz|161
{
    callfunc "Qux";
    end;
}


Setting as debug npc

Object type: npc
Object name: FooBar#Baz
Rotation: 90

Property Value
debug true
sprite 161
callfunc Qux

Gives in Hercules:

009-1,25,25,3    script    FooBar#Baz    161,{
    callfunc "Qux";
    end;
OnInit:
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}


Gives in TMWA:

009-1,25,25,3|script|FooBar#Baz|161
{
    callfunc "Qux";
    end;
OnInit:
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}


Adding a trigger area

Object type: npc
Object name: FooBar#Baz
Rotation: 90

Use tiled to mark the area of the trigger. To have a 0,0 trigger set the "trigger" property to "true".

Property Value
debug true
sprite 161
callfunc Qux

Gives in Hercules:

009-1,25,25,3    script    FooBar#Baz    161,2,4,{
    end;
OnTouch:
    callfunc "Qux";
    end;
OnInit:
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}


Gives in TMWA:

009-1,25,25,3|script|FooBar#Baz|161,2,4
{
    end;
OnTouch;
    callfunc "Qux";
    end;
OnInit:
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}


Adding a recurring timer

Object type: npc
Object name: FooBar#Baz
Rotation: 90

Property Value
interval 10000,Function
trigger 2,4
debug true
sprite 161
callfunc Qux

Gives:

009-1,25,25,3    script    FooBar#Baz    161,2,4,{
    end;
OnTouch:
    callfunc "Qux";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
    end;
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}


Gives in TMWA:

009-1,25,25,3|script|FooBar#Baz|161,2,4
{
    end;
OnTouch:
    callfunc "Qux";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
    end;
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}


Passing arguments to the function (Hercules only)

Object type: npc
Object name: FooBar#Baz
Rotation: 90

Property Value
arguments 19,"ba,z"
interval 10000,Function
trigger 2,4
debug true
sprite 161
callfunc Qux

Gives in Hercules:

009-1,25,25,3    script    FooBar#Baz    161,2,4,{
    end;
OnTouch:
    callfunc "Qux", 19, "ba,z";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
    end;
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}




Adding custom variables (TMWA only)

For TMWA, any property that starts with @ is interpreted as a custom variable.

Object type: npc
Object name: FooBar#Baz
Rotation: 90

Property Value
@integer 19
@string$ ba,z
interval 10000,Function
trigger 2,4
debug true
sprite 161
callfunc Qux

Gives in TMWA:

009-1,25,25,3|script|FooBar#Baz|161,2,4
{
    end;
OnTouch:
    set @integer, 19;
    set @string$, "ba,z";
    callfunc "Qux";
    end;
OnTimer10000:
    callfunc "Function";
    initnpctimer;
    end;
OnInit:
    if(DEBUG >= 2) end;
    initnpctimer;
    if(DEBUG) end;
    disablenpc "FooBar#Baz";
    end;
}