[Tutorial] How to create actors in game using Y_INI/ZCMD
#1

I've just made it for someone in scripting help so i will share it here too..

First
Code:
#define ACTOR_DATA   "Actors/%d"
#define MAX_ACTORSS  (200)
Code:
enum aInfo
{
	aSkin,
	aName[32],
	Text3D:aText,
	Float:aPosX,
	Float:aPosY,
	Float:aPosZ,
	Float:aPosA,
	aVW
}
new ActorInfo[MAX_ACTORSS][aInfo];

forward LoadActors();
public LoadActors()
{
	new Actor[64];
	for(new idx = 0; idx < sizeof(ActorInfo); idx++)
	{
		format(Actor, 64, ACTOR_DATA, idx);
		INI_ParseFile(Actor, "LoadActor_data", .bExtra = true, .extra = idx );
		if(ActorInfo[idx][aPosX] > 0.0)
		{
			CreateActorInformation(idx);
		}
	}
	print("*Actors Loaded Correctly.");
	return 1;
}
forward SaveActors(idx);
public SaveActors(idx)
{
	new Actorfile[64];
	format(Actorfile, 64, ACTOR_DATA, idx);
	new INI:File = INI_Open(Actorfile);
	INI_SetTag(File,"Actor_Information");
	INI_WriteInt(File,"Skin", ActorInfo[idx][aSkin]);
	INI_WriteString(File,"Name", ActorInfo[idx][aName]);
	INI_WriteFloat(File,"PosX", ActorInfo[idx][aPosX]);
	INI_WriteFloat(File,"PosY", ActorInfo[idx][aPosY]);
	INI_WriteFloat(File,"PosZ", ActorInfo[idx][aPosZ]);
	INI_WriteFloat(File,"Angel", ActorInfo[idx][aPosA]);
	INI_WriteInt(File,"VirtualWorld", ActorInfo[idx][aVW]);
	INI_Close(File);
	return 1;
}

forward LoadActor_data(idx, name[], value[]);
public LoadActor_data(idx, name[], value[])
{
	INI_Int("Skin", ActorInfo[idx][aSkin]);
	INI_String("Name", ActorInfo[idx][aName], 32);
	INI_Float("PosX", ActorInfo[idx][aPosX]);
	INI_Float("PosY", ActorInfo[idx][aPosY]);
	INI_Float("PosZ", ActorInfo[idx][aPosZ]);
	INI_Float("Angel", ActorInfo[idx][aPosA]);
	INI_Int("VirtualWorld", ActorInfo[idx][aVW]);
	return 1;
}

forward CreateActorInformation(idx);
public CreateActorInformation(idx);
{
	new string[500];
	DestroyDynamic3DTextLabel(ActorInfo[idx][aText]);
	format(string, sizeof(string), "{00A2FF}%s (%d)", ActorInfo[idx][aName], idx);
	ActorInfo[idx][aText] = CreateDynamic3DTextLabel(string,-1, ActorInfo[idx][aPosX], ActorInfo[idx][aPosY], ActorInfo[idx][aPosZ]+1,6.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,1,0,0);
	CreateActor(ActorInfo[idx][aSkin], ActorInfo[idx][aPosX], ActorInfo[idx][aPosY], ActorInfo[idx][aPosZ], ActorInfo[idx][aPosA]);
	SetActorVirtualWorld(idx, ActorInfo[idx][aVW]);
	return 1;
}
now commands.. you'll have to use the first command in game to create the files in the directory so you'll be able to create actors
Code:
CMD:resetallactors(playerid, params[])
{
	if(IsPlayerAdmin(playerid))
	{
		for(new id = 0; id < MAX_ACTORSS; id ++)
		{
			CreateActorInformation(id);
			SaveActors(id);
		}
		SendClientMessage(playerid, -1, "You've created the files.");
	} else SendClientMessage(playerid, -1, "You're not authorized to use this command");
	return 1;
}
Code:
CMD:createactor(playerid, params[])
{
	new skin, text[32], string[128];
	if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "You can't do that in a vehicle.");
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You're not authorized to use this command");
	if(sscanf(params, "is[32]", skin, text))
	{
		SendClientMessage(playerid, -1, "/createactor [skin] [name]");
		return 1;
	}
 	if(skin > 311 || skin < 0) return SendClientMessage(playerid, -1, "Skin ID is invalid(0-311).");
	for(new idx=0; idx<MAX_ACTORSS; idx++)
	{
		if(ActorInfo[idx][aPosX] == 0.0)
		{
			GetPlayerPos(playerid, ActorInfo[idx][aPosX], ActorInfo[idx][aPosY], ActorInfo[idx][aPosZ]);
			GetPlayerFacingAngle(playerid, ActorInfo[idx][aPosA]);
                        SetActorVirtualWorld(playerid, GetPlayerVirtualWorld(playerid));
			ActorInfo[idx][aSkin] = skin;
			format(ActorInfo[idx][aName], 32, "%s", text);

			format(string,sizeof(string),"{00A2FF}%s (%d)", text ,idx);
			ActorInfo[idx][aText] = CreateDynamic3DTextLabel(string,-1,ActorInfo[idx][aPosX],ActorInfo[idx][aPosY],ActorInfo[idx][aPosZ]+1,8.0);

			CreateActorInformation(idx);
			SaveActors(idx);
			idx = MAX_ACTORSS;
		}
	}
	return 1;
}
Code:
CMD:deleteactor(playerid, params[])
{
	new id;
	if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You're not authorized to use this command");
	if(sscanf(params, "i", id)) return SendClientMessage(playerid, -1, "/deleteactor [id]");
	if(ActorInfo[id][aPosX] == 0.0) return SendClientMessage(playerid, -1, "Invaild ID");
 	ActorInfo[id][aSkin] = 0;
 	format(ActorInfo[id][aName], 32, "None");
 	ActorInfo[id][aPosX] = 0;
  	ActorInfo[id][aPosY] = 0;
   	ActorInfo[id][aPosZ] = 0;
   	ActorInfo[id][aPosA] = 0;
        ActorInfo[id][aVW] = 0;
        DestroyActor(id);
	DestroyDynamic3DTextLabel(ActorInfo[id][aText]);
	CreateActorInformation(id);
	SaveActors(id);
	return 1;
}
Here's a picture

Have fun.
Reply
#2

Great!
Reply
#3

I'm sorry but what?!:
pawn Code:
if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You're not logged in");
Reply
#4

Quote:
Originally Posted by JamesCaptGeneral
View Post
I'm sorry but what?!:
pawn Code:
if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You're not logged in");
Oh.. i meant IsPlayerAdmin(playerid), thanks
Reply
#5

Quite simple but might be useful for others, good job.
Reply
#6

Great work, good for newbies (especially me xD)
Reply
#7

Thanks , enjoy xD
Reply
#8

Really useful.
Reply
#9

Nice tutorial
Reply
#10

This isn't how you write a tutorial. Why didn't you simply release it as a filterscript if you haven't explained anything?
Reply
#11

what are even the actors ?
what is their functions ?
im asking cuz i dont wanna add a script to server without to know what is
Reply
#12

D:\server\samp\pawno\include\YSI\y_utils.inc(343) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\pawno\include\YSI\y_utils.inc(497) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\pawno\include\YSI\y_utils.inc(540) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\pawno\include\YSI\y_utils.inc(55 : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\pawno\include\YSI\y_malloc.inc(216) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\pawno\include\sscanf.inc(3) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(131) : error 004: function "CreateActorInformation" is not implemented
D:\server\samp\gamemodes\abrffnew.pwn(170) : error 055: start of function body without function header
D:\server\samp\gamemodes\abrffnew.pwn(172) : error 017: undefined symbol "idx"
D:\server\samp\gamemodes\abrffnew.pwn(173) : error 021: symbol already defined: "format"
D:\server\samp\gamemodes\abrffnew.pwn(177) : error 010: invalid function or declaration
D:\server\samp\gamemodes\abrffnew.pwn(261) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(359) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(577) : warning 235: public function lacks forward declaration (symbol "OnPlayerFullyConnected")
D:\server\samp\gamemodes\abrffnew.pwn(592) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(605) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(659) : warning 217: loose indentation
D:\server\samp\gamemodes\abrffnew.pwn(659) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(690) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(714) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(75 : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(777) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(811) : error 004: function "CreateActorInformation" is not implemented
D:\server\samp\gamemodes\abrffnew.pwn(821) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\samp\gamemodes\abrffnew.pwn(836) : warning 217: loose indentation
D:\server\samp\gamemodes\abrffnew.pwn(837) : warning 217: loose indentation
D:\server\samp\gamemodes\abrffnew.pwn(841) : error 017: undefined symbol "CreateDynamic3DTextLabel"
D:\server\samp\gamemodes\abrffnew.pwn(841) : warning 213: tag mismatch
D:\server\samp\gamemodes\abrffnew.pwn(843) : error 004: function "CreateActorInformation" is not implemented
D:\server\samp\gamemodes\abrffnew.pwn(863) : warning 217: loose indentation
D:\server\samp\gamemodes\abrffnew.pwn(865) : warning 217: loose indentation
D:\server\samp\gamemodes\abrffnew.pwn(865) : error 004: function "DestroyDynamic3DTextLabel" is not implemented
D:\server\samp\gamemodes\abrffnew.pwn(866) : error 004: function "CreateActorInformation" is not implemented
D:\server\samp\gamemodes\abrffnew.pwn(870) : warning 203: symbol is never used: "string"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


10 Errors.
Reply
#13

since its a [Tutorial] i think you should explain what u did instead of just giving it out for everyone to copy/paste without understanding anything in it. so they can edit it in the future by themselves :3
Reply
#14

Just make it a FS,its good
Reply
#15

Quote:
Originally Posted by Roberto80
View Post
Just make it a FS,its good
you should make it yourself. It very simple
just put that
PHP Code:
LoadActor() 
in OnGameModeInit ( OnFiterScriptInit) simple
Reply
#16

That's cool mate
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)