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")
 
(2 intermediate revisions by the same user not shown)
Line 28: Line 28:
== Semi-anonymous npc ==
== 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.
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>
<br><br>
Object type: npc<br>
Object type: npc<br>
Line 42: Line 43:
Gives in Hercules: <pre>
Gives in Hercules: <pre>
009-1,25,25,0    script    FooBar#009-1_0    32767,{
009-1,25,25,0    script    FooBar#009-1_0    32767,{
     callfunc "Qux", "FooBar#009-1_0", 25, 25;
     callfunc "Qux";
     end;
     end;
}
}
Line 50: Line 51:
009-1,25,25,0|script|FooBar#009-1_0|32767
009-1,25,25,0|script|FooBar#009-1_0|32767
{
{
    setarray @npcname$, "FooBar", "#009-1_0";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 72: Line 71:
Gives in Hercules: <pre>
Gives in Hercules: <pre>
009-1,25,25,0    script    FooBar    32767,{
009-1,25,25,0    script    FooBar    32767,{
     callfunc "Qux", "FooBar", 25, 25;
     callfunc "Qux";
     end;
     end;
}
}
Line 80: Line 79:
009-1,25,25,0|script|FooBar|32767
009-1,25,25,0|script|FooBar|32767
{
{
    setarray @npcname$, "FooBar", "";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 107: Line 104:
Gives in Hercules: <pre>
Gives in Hercules: <pre>
009-1,25,25,0    script    #009-1_anon0    161,{
009-1,25,25,0    script    #009-1_anon0    161,{
     callfunc "Qux", "#009-1_anon0", 25, 25;
     callfunc "Qux";
     end;
     end;
}
}
Line 115: Line 112:
009-1,25,25,0|script|#009-1_anon0|161
009-1,25,25,0|script|#009-1_anon0|161
{
{
    setarray @npcname$, "", "#009-1_anon0";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 144: Line 139:
Gives in Hercules: <pre>
Gives in Hercules: <pre>
009-1,25,25,3    script    FooBar#Baz    161,{
009-1,25,25,3    script    FooBar#Baz    161,{
     callfunc "Qux", "FooBar#Baz", 25, 25;
     callfunc "Qux";
     end;
     end;
}
}
Line 152: Line 147:
009-1,25,25,3|script|FooBar#Baz|161
009-1,25,25,3|script|FooBar#Baz|161
{
{
    setarray @npcname$, "FooBar", "#Baz";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 181: Line 174:
Gives in Hercules: <pre>
Gives in Hercules: <pre>
009-1,25,25,3    script    FooBar#Baz    161,{
009-1,25,25,3    script    FooBar#Baz    161,{
     callfunc "Qux", "FooBar#Baz", 25, 25;
     callfunc "Qux";
     end;
     end;
OnInit:
OnInit:
Line 193: Line 186:
009-1,25,25,3|script|FooBar#Baz|161
009-1,25,25,3|script|FooBar#Baz|161
{
{
    setarray @npcname$, "FooBar", "#Baz";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 231: Line 222:
     end;
     end;
OnTouch:
OnTouch:
     callfunc "Qux", "FooBar#Baz", 25, 25;
     callfunc "Qux";
     end;
     end;
OnInit:
OnInit:
Line 245: Line 236:
     end;
     end;
OnTouch;
OnTouch;
    setarray @npcname$, "FooBar", "#Baz";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 286: Line 275:
     end;
     end;
OnTouch:
OnTouch:
     callfunc "Qux", "FooBar#Baz", 25, 25;
     callfunc "Qux";
     end;
     end;
OnTimer10000:
OnTimer10000:
Line 306: Line 295:
     end;
     end;
OnTouch:
OnTouch:
    setarray @npcname$, "FooBar", "#Baz";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 356: Line 343:
     end;
     end;
OnTouch:
OnTouch:
     callfunc "Qux", "FooBar#Baz", 25, 25, 19, "ba,z";
     callfunc "Qux", 19, "ba,z";
     end;
     end;
OnTimer10000:
OnTimer10000:
Line 370: Line 357:
}
}
</pre>
</pre>
=== Automatically added properties ===
{| class="wikitable" border="1"
|-
! Property
! Value
|-
| name
| the full object name. unlike TMWA we can send the full name because Hercules has explode()
|-
| X
| the X location of the npc
|-
| Y
| the Y location of the npc
|}
Any custom property is added after the default properties
<br><br>
<br><br>


Line 430: Line 400:
     set @integer, 19;
     set @integer, 19;
     set @string$, "ba,z";
     set @string$, "ba,z";
    setarray @npcname$, "FooBar", "#Baz";
    setarray @npcloc, 25, 25;
     callfunc "Qux";
     callfunc "Qux";
     end;
     end;
Line 446: Line 414:
}
}
</pre>
</pre>
 
<br>
=== Automatically added variables ===
{| class="wikitable" border="1"
|-
! Variable
! Value
|-
| @npcname$
| an array of everything that comes before (and after if any) the "#" in the object name
|-
| @npcloc
| an array of the X and the Y location of the npc
|}
<br><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;
}