Quote:
Originally Posted by JesterlJoker
if you meant that if an actor is being spawned?
PHP код:
//actor variable
new Actor[MAX_ACTOR]; //assuming you have set the MAX_ACTOR to a ideal number
PHP код:
//Place this on gamemodinit
Actor[0] = CreateActor(0, 1605.8220, 1829.0625, 10.5251, 4.3929) //spawns actor CJ infront of Las Venturas Hospital
you won't need to get the actors position coz it will spawn on your specified location.
but
if you meant that if an actor is moved, by i.e players, objects, or bullet?
PHP код:
//Place this somewhere when you try to update the actors, i.e timers, callbacks, etc
new Float:ax, Float:ay, Float:az, Float:angle;
GetActorPos(Actor[0], ax, ay, az);
GetActorFacingAngle(Actor[0], angle);
if(ax != 1605.8220 || ay != 1829.0625) //or you could add Z, which is not ideal since a little movement on the ground changes the actors x and y axis
SetActorPos(actorid, 1605.8220, 1829.0625, 10.5251); //respawns actor CJ infront of Las Venturas Hospital
SetActorFacingAngle(Actor[0], 4.3929);
This will keep the actor teleported back to it's location every time the timer reaches its interval or when you update each actor on the server. In theory
NOTE:
I don't know if there is somewhat a function like
PHP код:
AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, addsiren=0);
That respawns the actor at a given time.
|
Actor position is read from the database and I define a variable called actorrespawn I gave him a second time, but nothing happens Please help me.
PHP код:
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");
ActorData[i][NameColor] = cache_get_field_content_int(i,"namecolor");
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),"{FFFFFF}%s(%i)",ActorData[i][aName],ActorData[i][aID]);
ActorData[i][ActorText] = CreateDynamic3DTextLabel(string, ActorData[i][NameColor],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: No actors found the in the SQL.");
else printf("ACTOR SYSTEM: Total %i actors loaded.",count);
return true;
}
PHP код:
SetTimer("ActorRespawn", 1000, false);
PHP код:
forward ActorRespawn();
public ActorRespawn()
{
for(new i = 0; i < MAX_ACTORS; i++) {
new Float:ax, Float:ay, Float:az, Float:angle;
GetActorPos(i, ax, ay, az);
GetActorFacingAngle(i, angle);
if(ax != ActorData[i][aX] || ay != ActorData[i][aY])
{
SetActorPos(i, ActorData[i][aX], ActorData[i][aY], ActorData[i][aZ]);
SetActorFacingAngle(i, ActorData[i][aA]);
sql_LoadAllActors();
}
}
}