How to add more perl functions.
Hello all,in my chapter,I will explain the basics of function creation,including mob,zone and other class.This tutorial is very simple,and intended to explain this for people which don't know C++ very well.
First of all.There are two files that you will need to use for adding functions. -Parser.cpp:Here is where we will add the function.This looks like: Code:
else if (!strcmp(strlwr(command),"save")) { // khuong Code:
"sub save{push(@cmd_queue,{func=>'save',args=>join(',',@_)});}" I will teach you how to get those arguments to use later in the function(for example the command quest::summonitem(22); gives 22 as argument,for item id). Let's get in the function code,in this case is 'save': Code:
else if (!strcmp(strlwr(command),"save")) { // khuong You won't need to care about it to make your function,just remember to change the name. In the second line,you can see what the function does.You need to know the basics of c++ for this.if(mob) just is used to know if the client who triggered it exists.For a example,if a timer triggers it,we will have no 'mob',if we hail a NPC and you trigger something,then 'mob' will exist.Then,if(mob->IsClient()),is used to know if the thing who triggered it,was a client.Easy,right?That would prevent crashes,for example if we are using a timer and we try to change it's level,it will crash.So if(mob && mob->IsClient()) is used to know if the thing which triggered it exists,and the thing which triggered it is a client. If those two are TRUE,then it is going to use the function save to the client ( mob->CastToClient()->Save(); ). We need to know some things first: -mob:Is the 'thing' which triggered the action.For example,if we hail a NPC and it has something like if($text=~/hail/i) {quest::say("you hailed me");},the client who triggered it is 'mob'. -other:is the 'thing' which IS triggered.In the last example,'other' is the NPC. so if we are using: Code:
mob->CastToClient()->Save(); Then,if we want to set pvp on client,how we should do it?mob->SetPvP(true) ? Nah,we need to use mob->CastToClient()->SetPvP(true);,remember it. It is always good to add some error checks,so it won't crash. Another example,but now using other class.Let's take a look at doanim function: Code:
else if (!strcmp(strlwr(command),"doanim")) { So we need to get that info right?It is very simple.To get an argument,we can use arglist.That is an array,so if we give two arguments,we will take the first with arglist[0],and the second with arglist[1]. If the arguments are integers,we should use the function atoi to prevent errors,because if we give a character instead of a number it can crash.So if we wanna use an integer from the argument given,we will do this: atoi(arglist[0]).If the argument is a string we should use a function in STD library:parms.c_str(). And if we want to get the zone name,we should use zone->GetShortName();. That easy!!. Some examples: Code:
else if (!strcmp(strlwr(command),"setheading")) Code:
else if (!strcmp(strlwr(command),"permaclass")) {//Cofruben:-Makes the client the class specified Code:
else if (!strcmp(strlwr(command),"surname")) { //Cofruben:-Changes the last name. |
very nice
this'll help out a lot |
All times are GMT -4. The time now is 11:36 AM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.