28.12.2011, 07:42
Hey guys, I've been trying to script something for a while now, however I can't seem to get it to work.
Basically what I'm trying to do, is create a script that'll create a heap of beach balls on command. Sure, that's easy enough, but the difficult thing is, I need to be able to destroy them as well.
CreateObject returns the unique ID of the object created, which I need to try store in an array.
Here is what I'm trying to achieve:
Create a big stack of beach balls, and store all their unique ID's in an array. This array can then be used with DestroyObject to delete all the beach balls on command.
This is my current code, but it doesn't seem to work at all.
Any errors/pointers? Thanks
Basically what I'm trying to do, is create a script that'll create a heap of beach balls on command. Sure, that's easy enough, but the difficult thing is, I need to be able to destroy them as well.
CreateObject returns the unique ID of the object created, which I need to try store in an array.
Here is what I'm trying to achieve:
Create a big stack of beach balls, and store all their unique ID's in an array. This array can then be used with DestroyObject to delete all the beach balls on command.
This is my current code, but it doesn't seem to work at all.
Код:
#include <a_samp> #include <a_players> #include <a_vehicles> forward Balls(pid); forward destroyBalls(pid); public OnFilterScriptInit() { print("\n--------------------------------------------"); print("Test Script"); print("--------------------------------------------\n"); return 1; } public OnFilterScriptExit() { return 1; } // balls create function new ballarray[1000]; new ballarraylen = 0; new ballx; new ballz; public Balls(pid) { SendClientMessage(pid, 0x33CCFFAA, "Balls!"); for (new i = 0; i < 4; i++){ ballx = -1915.6129 - i; for (new ind = 0; ind < 25; ind++){ ballz = 422.2535 + ind; new debugstring[100] = "Creating ball at (xyz): "; new str[10]; valstr(str,ballx); strcat(debugstring, str, sizeof(debugstring)); strcat(debugstring, ", -769.5698, ", sizeof(debugstring)); valstr(str,ballz); strcat(debugstring, str, sizeof(debugstring)); print(debugstring); ballarray[ballarraylen] = CreateObject(1598,ballx,-769.5698,ballz,0.0,0.0,0.0); ballarraylen++; } } SendClientMessage(pid, 0x33CCFFAA, "Dropped Balls"); return 1; } public destroyBalls(pid) { SendClientMessage(pid, 0x33CCFFAA, "Destroying balls"); for (new ind = 0; ind < ballarraylen; ind++){ DestroyObject(ballarray[ind]); ballarray[ind] = 0; } ballarraylen = 0; SendClientMessage(pid, 0x33CCFFAA, "Balls destroyed"); return 1; } // strtok implementation strtok( const string[], &index, const seperator[] = " " ) { new index2, result[ 30 ]; index2 = strfind(string, seperator, false, index); if(index2 == -1) { if(strlen(string) > index) { strmid(result, string, index, strlen(string), 30); index = strlen(string); } return result; // This string is empty, probably, if index came to an end } if(index2 > (index + 29)) { index2 = index + 29; strmid(result, string, index, index2, 30); index = index2; return result; } strmid(result, string, index, index2, 30); index = index2 + 1; return result; } // end strtok // Main script body public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[30]; new idx; cmd = strtok(cmdtext, idx); if(strcmp(cmd, "/balls", true) == 0) { new tmp[30]; tmp = strtok(cmdtext, idx); new pid = strval(tmp); Balls(pid); return 1; } if(strcmp(cmd, "/destroyballs", true) == 0) { new tmp[30]; tmp = strtok(cmdtext, idx); new pid = strval(tmp); destroyBalls(pid); return 1; } return 0; }