Changeset 481
- Timestamp:
- Nov 15, 2009, 3:13:50 AM (15 years ago)
- Location:
- Daodan
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/src/Daodan_BSL.c
r476 r481 3 3 #include <time.h> 4 4 #include <ffi.h> 5 5 #include <math.h> 6 6 #include "inifile.h" 7 7 … … 218 218 else index = args[0].value_int32; 219 219 Character* Chr = ONgGameState + 0x1260 ; 220 int* health = (int *)&Chr[index] + 0x144;220 int* health = (int)&Chr[index] + 0x144; 221 221 222 222 ret->value_int32 = *health; … … 226 226 *health = args[1].value_int32; 227 227 } 228 ret->value_int32 = *health; 229 ret->type = sl_int32; 230 return 0; 231 } 232 228 return 0; 229 } 230 231 uint16_t ONICALL bsl_distance(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { 232 233 if (numargs < 2) return 1; 234 int index; 235 int index2; 236 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); 237 else index = args[0].value_int32; 238 if (index == -1) index = args[0].value_int32; 239 240 if (args[1].type == sl_str32) index2 = DDrGetCharacterIndexFromName(args[1].value_str32); 241 else index2 = args[1].value_int32; 242 if (index2 == -1) index2 = args[1].value_int32; 243 244 Character* Chr = ONgGameState + 0x1260; 245 Character* Char1 = &Chr[index]; 246 Character* Char2 = &Chr[index2]; 247 248 ret->value_float = sqrt( pow((Char1->Location.X - Char2->Location.X), 2) + pow((Char1->Location.Y - Char2->Location.Y), 2) + pow((Char1->Location.Z - Char2->Location.Z),2)); 249 ret->type = sl_float; 250 return 0; 251 } 252 uint16_t ONICALL bsl_location(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { 253 int index; 254 if (numargs < 2) return 1; 255 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); 256 else index = args[0].value_int32; 257 if (index == -1) index = args[0].value_int32; 258 Character* Chr = ONgGameState + 0x1260; 259 float* loc; 260 if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x")) 261 loc = &(Chr[index].Position.X); 262 else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y")) 263 loc = &(Chr[index].Position.Y); 264 else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z")) 265 loc = &(Chr[index].Position.Z); 266 else if (numargs == 4) { 267 //currently broken. crashes oni. 268 Chr[index].Position.X = args[1].value_float; 269 Chr[index].Position.Y = args[2].value_float; 270 Chr[index].Position.Z = args[3].value_float; 271 ret->value_float = 1; 272 ret->type = sl_float; 273 return 0; 274 } 275 else return 1; 276 277 ret->value_float = *loc; 278 ret->type = sl_float; 279 280 if(numargs == 3) { 281 //currently broken, does nothing. 282 *loc = args[2].value_float; 283 } 284 return 0; 285 } 233 286 234 287 uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) … … 332 385 uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) 333 386 { 387 334 388 ret->type = sl_int32; 335 389 ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32); 390 336 391 return 0; 337 392 } … … 397 452 { 398 453 int index; 399 if (numargs < 4) index = 0;400 elseif (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);454 455 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); 401 456 else index = args[0].value_int32; 402 457 403 458 Character* Chr = ONgGameState + 0x1260; 404 459 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); … … 408 463 int Input1 = 0; 409 464 int Input2 = 0; 410 for(i = 1; i < numargs ; i++) {465 for(i = 1; i < numargs - 1; i++) { 411 466 for(j = 0; j < 32; j++) { 412 if(strcmp(args[i].value_str32, Actions1[j].Name)) Input1 = Input1 | Actions1[j].Bit; 413 DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit); 467 if(!strcmp(args[i].value_str32, Actions1[j].Name)) { 468 Input1 = Input1 | Actions1[j].Bit; 469 } 414 470 } 415 471 for(j = 0; j < 9; j++) { 416 if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; 417 418 } 419 } 420 for(i = 0; i < numargs; i++) { 421 DDrConsole_PrintF("%s", args[i].value_str32); 422 } 423 // if 472 if(!strcmp(args[i].value_str32, Actions2[j].Name)) { 473 Input2 = Input2 | Actions2[j].Bit; 474 } 475 } 476 } 477 Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1; 478 Active->Input.Current.Actions2 = Active->Input.Current.Actions1 | Input2; 479 if( Input1 + Input2 == 0 ) { 480 DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name); 481 return 0; 482 } 483 if ( args[numargs - 1].value_int32 <= 0) { 484 return 0; 485 } 486 else { 487 args[numargs - 1].value_int32 -= 1; 488 *dontuse2 = 1; 489 *dontuse1 = 1; 490 } 424 491 return 0; 425 492 } … … 673 740 } 674 741 675 uint16_t ONICALL bsl_findmsg(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)676 {677 //DDrMake_Weapon_Message(args[0].value_str32);678 return false;679 }680 742 void SLrDaodan_Initalize() 681 743 { … … 689 751 690 752 SLrConfig(); 691 SLrScript_Command_Register_ReturnType("d_wp", "Shows weapon message", "wpn:string", sl_void, bsl_findmsg);692 753 693 754 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); … … 703 764 SLrScript_Command_Register_ReturnType("d_getdamage","Gets the amount of damage a character has caused", "[ai_name:string | script_id:int]", sl_int32, bsl_getdamage); 704 765 SLrScript_Command_Register_ReturnType("d_name","Gets or sets a character's name", "[ai_name:str | script_id:int] [newname:string]", sl_str32, bsl_chrname); 705 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", " script_id:int", sl_int32, bsl_nametoindex);766 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex); 706 767 SLrScript_Command_Register_ReturnType("d_health","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_health); 707 768 SLrScript_Command_Register_ReturnType("d_regen","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_regen); 708 769 SLrScript_Command_Register_ReturnType("d_maxhealth","Gets or sets a character's maximum health", "[ai_name:str | script_id:int] [newmaxhealth:int] [scalehealth:bool]", sl_str32, bsl_maxhealth); 709 770 SLrScript_Command_Register_ReturnType("d_powerup","Gets or sets a character's powerups", "ai_name:str|script_id:int powerup:str", sl_int32, bsl_powerup); 710 SLrScript_Command_Register_ReturnType("d_holdkey","Makes an AI hold a key", "[ai_name:string | script_id:int] keys", sl_int32, bsl_holdkey); 711 SLrScript_Command_Register_ReturnType("d_isheld","Checks for a held key", "keys", sl_int32, bsl_isheld); 712 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress.", "keys", bsl_waitforkey); 713 714 //broken. sometimes crashes, and sometimes returns a string... : / 715 SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker); 716 717 SLrScript_Command_Register_ReturnType("d_active","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset); 771 SLrScript_Command_Register_ReturnType("d_holdkey","Makes a character hold a key", "[ai_name:string | script_id:int] keys frames:int", sl_int32, bsl_holdkey); 772 SLrScript_Command_Register_ReturnType("d_isheld","Checks if player is holding a key", "keys", sl_int32, bsl_isheld); 773 SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "ai_name:str | script_id:int xyz:string [newlocation:float]", sl_float, bsl_location); 774 SLrScript_Command_Register_ReturnType("d_distance","Returns the distance between two characters", "ai_name:str | script_id:int ai_name:str | script_id:int ", sl_float, bsl_distance); 775 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "keys", bsl_waitforkey); 776 777 //broken, only works for one damage type. 778 //SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker); 779 780 //used for debugging. 781 SLrScript_Command_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset); 718 782 719 783 SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf);
Note:
See TracChangeset
for help on using the changeset viewer.