www.pudn.com > ro4fserver.rar > script.c
#include#include #include #include #include "mmo.h" #include "core.h" #include "npc.h" #include "script2.h" #include "script.h" extern struct mmo_map_data map_data[]; int internal_fd; struct map_session_data *internal_sd; lua_State *L; void get_char_data(struct mmo_charstatus cs) { zeny=cs.zeny; class=cs.class; status_point=cs.status_point; skill_point=cs.skill_point; hp=cs.hp; max_hp=cs.max_hp; sp=cs.sp; max_sp=cs.max_sp; option=cs.option; karma=cs.karma; manner=cs.manner; hair=cs.hair; hair_color=cs.hair_color; clothes_color=cs.clothes_color; weapon=cs.weapon; sheild=cs.sheild; head_top=cs.head_top; head_mid=cs.head_mid; head_bottom=cs.head_bottom; strcpy(name,cs.name); base_level=cs.base_level; job_level=cs.job_level; str=cs.str; agi=cs.vit; int_=cs.int_; dex=cs.dex; luk=cs.luk; } void sendMessage(char *msg) { int len; len=mmo_map_npc_say(internal_fd,WFIFOP(internal_fd,0),internal_sd->npc_id,msg); if(len>0) WFIFOSET(internal_fd,len); } void sendMenu(char *options) { int len; len=mmo_map_npc_select(internal_fd,WFIFOP(internal_fd,0),internal_sd->npc_id,options); if(len>0) WFIFOSET(internal_fd,len); } void sendNext() { int len; len=mmo_map_npc_next(internal_fd,WFIFOP(internal_fd,0),internal_sd->npc_id); if(len>0) WFIFOSET(internal_fd,len); } void sendEnd() { int len; len=mmo_map_npc_close(internal_fd,WFIFOP(internal_fd,0),internal_sd->npc_id); if(len>0) WFIFOSET(internal_fd,len); menuSelect=0; next=0; } void changeJob(int job) { mmo_map_jobchange(internal_fd,job); } void changeLook(int i, int j) { int len; len=mmo_map_set_look(internal_fd,WFIFOP(internal_fd,0),internal_sd->account_id,i,j); if(len>0) mmo_map_sendarea(internal_fd,WFIFOP(internal_fd,0),len,0); } void statusChange(int status,int new) { mmo_map_update_param(internal_fd,status,new); } void changeSavePoint(char *name,int x, int y) { struct map_session_data *temp_sd; temp_sd=session[internal_fd]->session_data; strcpy(temp_sd->status.save_point.map,name); temp_sd->status.save_point.x=x; temp_sd->status.save_point.y=y; } void sendImage(char *name, int type) { int len; len=send_image(internal_fd,WFIFOP(internal_fd,0),name,type); if(len>0) WFIFOSET(internal_fd,len); } unsigned char *parse_script(unsigned char *script) { int length =strlen(script); char *final; final=(char *)malloc(length+1); script[length-1]=0; script[length]=0; strcpy(final,script+2); return final; } void warp(char *map,int x, int y) { mmo_map_changemap(internal_fd,internal_sd,map,x,y,2); } void waitInput() { int len; len=mmo_map_npc_amount_request(internal_fd,WFIFOP(internal_fd,0),internal_sd->npc_id); if(len>0) WFIFOSET(internal_fd,len); } int run_script(int fd,struct map_session_data *sd) { unsigned char *script; struct map_session_data *temp_sd; menuSelect=sd->local_reg[15]; input=sd->local_reg[14]; temp_sd=session[fd]->session_data; internal_fd=fd; internal_sd=sd; get_char_data(temp_sd->status); script=map_data[sd->mapno].npc[sd->npc_n]->u.script; lua_dostring(L,script); sd->local_reg[15]=0; return(1); } int script_init() { menuSelect=0; next=0; L=lua_open(0); if(L==NULL) { printf("Error with lua\n"); return(1); } tolua_ragnarok_open(L); lua_baselibopen(L); lua_strlibopen(L); lua_mathlibopen(L); return(0); } void script_close() { tolua_ragnarok_close(L); lua_close(L); }