- #include <a_samp>
- #include <a_mysql>
- #include <streamer>
- #include <sscanf2>
- #include <zcmd>
- #define host "localhost"
- #define user "root"
- #define db "mydb" /* CHANGE THIS TO YOUR DATABASE NAME */
- #define pass ""
- #define COLOR_GREY 0xAFAFAFAA
- static mysql;
- enum aDATA {
- aID,
- ValidActor,
- aName[24],
- ActorSkin,
- Float:aX,
- Float:aY,
- Float:aZ,
- Float:aA,
- Text3D:ActorText,
- ActorPlayer,
- Actor_AnimLib[30],
- Actor_AnimName[30]
- };
- new ActorData[MAX_ACTORS][aDATA];
- /* SQL */
- forward OnActorLoad();
- #define FILTERSCRIPT
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Blank Filterscript by your name here");
- print("--------------------------------------\n");
- sql_LoadAllActors();
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- #else
- main()
- {
- print("\n----------------------------------");
- print(" Blank Gamemode by your name here");
- print("----------------------------------\n");
- }
- #endif
- /* Commands */
- CMD:reloadactors(playerid,params[]) {
- sql_LoadAllActors();
- return true;
- }
- CMD:changeactoranim(playerid,params[]) {
- new id;
- if(sscanf(params,"i",id)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /changeactoranim [actorid]");
- new calc = id-1;
- if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
- new animlib[32];
- new animname[32];
- GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
- sql_UpdateActorAnim(id,animlib,animname);
- SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> You have changed actors animation to your current animation. Reload actors to apply effects");
- return true;
- }
- CMD:createactor(playerid,params[]) {
- new actorName[24],skin;
- if(sscanf(params,"is[24]",skin,actorName)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /createactor [skinid] [name] ");
- new Float:x,Float:y,Float:z,Float:a;
- GetPlayerPos(playerid,x,y,z);
- GetPlayerFacingAngle(playerid,a);
- new animlib[32];
- new animname[32];
- GetAnimationName(GetPlayerAnimationIndex(playerid),animlib,32,animname,32);
- sql_CreateActor(actorName, skin, x,y,z,a, animlib, animname);
- new string[128];
- format(string,sizeof(string), "New actor created. Skin ID: %i Name: %s. Type /reloadactors to reload all actors",skin,actorName);
- SendClientMessage(playerid,COLOR_GREY,string);
- return true;
- }
- CMD:setactorskin(playerid,params[]) {
- new ss[10],id;
- if(sscanf(params,"is[10]",id,ss)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /setactorskin [actorid] [skinid]");
- new calc = id-1;
- if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
- sql_UpdateActor(id,"skin",ss);
- new string[128];
- format(string,sizeof(string),"<ACTOR SYSTEM> Edited actors ID: %i Skin ID to %s. Reload actors to apply effects",id,ss);
- SendClientMessage(playerid,COLOR_GREY,string);
- return true;
- }
- CMD:setactorname(playerid,params[]) {
- new ss[24],id;
- if(sscanf(params,"is[24]",id,ss))
- return SendClientMessage(playerid,COLOR_GREY,"Usage: /setactorname [actorid] [new_name]");
- new calc = id-1;
- if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
- new string[128];
- format(string,sizeof(string),"<ACTOR SYSTEM> Edited actors ID: %i name to %s. Reload actors to apply effects",id,ss);
- SendClientMessage(playerid,COLOR_GREY,string);
- sql_UpdateActor(id,"name",ss);
- return true;
- }
- CMD:moveactor(playerid,params[]) {
- new id;
- if(sscanf(params,"i",id)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /moveactor [actorid]");
- new calc = id-1;
- if(ActorData[calc][ValidActor] == 0) return SendClientMessage(playerid,COLOR_GREY,"<ACTOR SYSTEM> Invalid actor ID");
- new string[128];
- format(string,sizeof(string),"<ACTOR SYSTEM> Actor ID: %i moved to your current location. Reload actors to apply effects",id);
- SendClientMessage(playerid,COLOR_GREY,string);
- new Float:x,Float:y,Float:z,Float:a;
- GetPlayerFacingAngle(playerid,a);
- GetPlayerPos(playerid,x,y,z);
- sql_MoveActor(id,x,y,z,a);
- return true;
- }
- /* Functions */
- sql_CreateActor(name[]="N/A", skin, Float:x, Float:y,Float:z,Float:a,lib[],libname[]) {
- new query[256];
- mysql_format(mysql,query,sizeof(query),"INSERT INTO `actors` (`Name`,`SkinID`,`X`,`Y`,`Z`,`A`,`anim_lib`,`anim_name`) VALUES ('%e',%i,%f,%f,%f,%f,'%e','%e')",name,skin,x,y,z,a,lib,libname);
- mysql_tquery(mysql,query,"","");
- }
- sql_UpdateActorAnim(id, anim[], animname[]) {
- new query[128];
- mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `anim_lib`='%e', `anim_name`='%e' WHERE `ID`=%d",anim,animname,id);
- mysql_tquery(mysql, query, "","");
- }
- stock PreloadAnimLib(playerid, animlib[])
- {
- ApplyAnimation(playerid,animlib,"null",0.0,0,0,0,0,0);
- }
- sql_LoadAllActors() {
- for(new i = 0; i < MAX_ACTORS; i++) {
- if(ActorData[i][ValidActor] == 1) {
- ActorData[i][aID] = 0;
- DestroyActor(ActorData[i][ActorPlayer]);
- DestroyDynamic3DTextLabel(ActorData[i][ActorText]);
- }
- }
- mysql_tquery(mysql, "SELECT * FROM `actors`", "OnActorLoad", "");
- return true;
- }
- sql_MoveActor(id,Float:x,Float:y,Float:z,Float:a) {
- new query[128];
- mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `X`=%f, `Y`=%f, `Z`=%f, `A`=%f WHERE `ID`=%d",x,y,z,a,id);
- mysql_tquery(mysql,query,"","");
- }
- sql_UpdateActor(id,var[],varamount[]) {
- new query[128];
- if(strcmp(var,"name") == 0) {
- mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `Name`='%e' WHERE `ID`=%d",varamount,id);
- mysql_tquery(mysql,query,"","");
- }
- if(strcmp(var,"skin") == 0) {
- new val = strval(varamount);
- mysql_format(mysql,query,sizeof(query),"UPDATE `actors` SET `SkinID`=%i WHERE `ID`=%d",val,id);
- mysql_tquery(mysql,query,"","");
- }
- }
- strcpy(dest[], const source[], maxlength=sizeof dest) strcat((dest[0] = EOS, dest), source, maxlength);
- /* SQL Callbacks */
- public OnActorLoad() {
- new rows = cache_num_rows(),
- count = 0,
- string[30],
- Sname[30],
- SLib[30],
- SAnimName[30];
- for(new i=0; i < rows; i++) {
- ActorData[i][ValidActor] = 1;
- ActorData[i][aID] = cache_get_field_content_int(i,"ID");
- ActorData[i][ActorSkin] = cache_get_field_content_int(i,"SkinID");
- ActorData[i][aX] = cache_get_field_content_float(i,"X");
- ActorData[i][aY] = cache_get_field_content_float(i,"Y");
- ActorData[i][aZ] = cache_get_field_content_float(i,"Z");
- ActorData[i][aA] = cache_get_field_content_float(i,"A");
- cache_get_field_content(i,"anim_lib",SLib);
- strcpy(ActorData[i][Actor_AnimLib],SLib,50);
- cache_get_field_content(i,"anim_name",SAnimName);
- strcpy(ActorData[i][Actor_AnimName],SAnimName,50);
- cache_get_field_content(i,"Name",Sname);
- strcpy(ActorData[i][aName],Sname,24);
- format(string,sizeof(string),"{00FFFF}%s(%i)",ActorData[i][aName],ActorData[i][aID]);
- ActorData[i][ActorText] = CreateDynamic3DTextLabel(string, 0x008080FF,ActorData[i][aX],ActorData[i][aY],ActorData[i][aZ]+1.05, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0);
- ActorData[i][ActorPlayer] = CreateActor(ActorData[i][ActorSkin],ActorData[i][aX],ActorData[i][aY],ActorData[i][aZ],ActorData[i][aA]);
- count += 1;
- ApplyActorAnimation(ActorData[i][ActorPlayer],ActorData[i][Actor_AnimLib],ActorData[i][Actor_AnimName], 4.0, 1, 0, 0, 0, 0);
- }
- if(count == 0) print("<ACTOR SYSTEM> SQL: No actors found the in the SQL.");
- else printf("<ACTOR SYSTEM> Total %i actors loaded.",count);
- return true;
- }