SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 07/05/2015, 09:45 AM   #1
Antoniohl
Huge Clucker
 
Antoniohl's Avatar
 
Join Date: Dec 2013
Location: Home Sweet Home (Egypt)
Posts: 402
Reputation: 37
Default How to create actors in game using Y_INI/ZCMD

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.

Last edited by Antoniohl; 07/05/2015 at 10:52 AM.
Antoniohl is offline   Reply With Quote
Old 07/05/2015, 10:00 AM   #2
aCloudy
Big Clucker
 
Join Date: Apr 2014
Posts: 189
Reputation: 2
Default Re: How to create actors in game using Y_INI/ZCMD

Great!
aCloudy is offline   Reply With Quote
Old 07/05/2015, 10:09 AM   #3
Freshncool
High-roller
 
Freshncool's Avatar
 
Join Date: Aug 2014
Location: United Kingdom, England.
Posts: 1,169
Reputation: 317
Default Re: How to create actors in game using Y_INI/ZCMD

I'm sorry but what?!:
Code:
if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You're not logged in");
__________________
haha
Freshncool is online now   Reply With Quote
Old 07/05/2015, 10:11 AM   #4
Antoniohl
Huge Clucker
 
Antoniohl's Avatar
 
Join Date: Dec 2013
Location: Home Sweet Home (Egypt)
Posts: 402
Reputation: 37
Default Re: How to create actors in game using Y_INI/ZCMD

Quote:
Originally Posted by JamesCaptGeneral View Post
I'm sorry but what?!:
Code:
if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "You're not logged in");
Oh.. i meant IsPlayerAdmin(playerid), thanks
Antoniohl is offline   Reply With Quote
Old 07/05/2015, 10:18 AM   #5
DaniceMcHarley
High-roller
 
DaniceMcHarley's Avatar
 
Join Date: Feb 2012
Location: CoMJ6e4eSAg
Posts: 1,705
Reputation: 92
Default Re: How to create actors in game using Y_INI/ZCMD

Quite simple but might be useful for others, good job.
DaniceMcHarley is offline   Reply With Quote
Old 07/05/2015, 10:40 AM   #6
manishmulchandani11
Big Clucker
 
Join Date: Aug 2012
Posts: 82
Reputation: 18
Default Re: How to create actors in game using Y_INI/ZCMD

Great work, good for newbies (especially me xD)
manishmulchandani11 is offline   Reply With Quote
Old 07/05/2015, 10:40 AM   #7
Antoniohl
Huge Clucker
 
Antoniohl's Avatar
 
Join Date: Dec 2013
Location: Home Sweet Home (Egypt)
Posts: 402
Reputation: 37
Default Re: How to create actors in game using Y_INI/ZCMD

Thanks , enjoy xD
Antoniohl is offline   Reply With Quote
Old 07/05/2015, 11:03 AM   #8
036
Big Clucker
 
036's Avatar
 
Join Date: Apr 2015
Location: UK
Posts: 149
Reputation: 67
Default Re: How to create actors in game using Y_INI/ZCMD

Really useful.
__________________
Retired Intervention RP Owner.
036 is offline   Reply With Quote
Old 07/05/2015, 11:18 AM   #9
LMaxCo
Big Clucker
 
Join Date: Dec 2014
Location: SA-MP Forums - Powered by VBulletin.
Posts: 158
Reputation: 11
Default Re: How to create actors in game using Y_INI/ZCMD

Nice tutorial
LMaxCo is offline   Reply With Quote
Old 07/05/2015, 11:56 AM   #10
Lordzy
High-roller
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,767
Reputation: 1161
Default Re: How to create actors in game using Y_INI/ZCMD

This isn't how you write a tutorial. Why didn't you simply release it as a filterscript if you haven't explained anything?
Lordzy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Gang System w/ Y_INI WhiteAngels Scripting Help 6 18/01/2015 07:57 AM
Why Y_INI create more variables on file. +REP. xHanks Scripting Help 5 04/08/2014 04:40 PM
Does anyone know how to create ucp with y_ini? newbienoob Scripting Help 4 24/10/2012 03:47 PM
Y_INI can't create file? HydraX Help Archive 2 20/08/2011 12:19 PM
ZCMD & Y_INI help blackwave Help Archive 1 11/01/2011 07:37 PM


All times are GMT. The time now is 08:14 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.