Help with actors - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with actors (
/showthread.php?tid=614930)
Help with actors -
TayFunCZE - 15.08.2016
Hello, I tried to make "/createactor" & "/deleteactor" commands, but "/deleteactor" isn't deleting right, I can create like 4 actors, and delete only 1 or 2 randomly.. please help
PHP код:
enum Actor
{
Float:aX,
Float:aY,
Float:aZ,
aID,
aSkin,
Text3D:aString
};
new ActorData[MAX_ACTORS][Actor];
new Actor_ID;
PHP код:
CMD:createactor(playerid, params[])
{
if(IsPlayerAnAdmin(playerid,3))
{
new modelid,string[200],Float:pos[4];
if(!sscanf(params, "i", modelid))
{
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid,pos[3]);
ActorData[Actor_ID][aID] = CreateActor(modelid,pos[0],pos[1]+0.5,pos[2],pos[3]);
SetActorInvulnerable(ActorData[Actor_ID][aID], false);
SetActorHealth(ActorData[Actor_ID][aID], 100);
format(string, sizeof(string), "ACTOR ID: %d and SKIN ID: %d",Actor_ID,modelid);
ActorData[Actor_ID][aString] = CreateDynamic3DTextLabel(string,ORANGE,pos[0],pos[1],pos[2],20,-1,0);
format(string, sizeof(string), "Actor created, SKIN ID: %d and ID: %d",modelid,Actor_ID); SCM(playerid,GREEN,string);
Actor_ID++;
}
else SCM(playerid,RED,"[INFO]: /createactor <skin>");
}
else SCM(playerid,RED,">> You are not an admin!");
return 1;
}
PHP код:
CMD:deleteactor(playerid, params[])
{
if(IsPlayerAnAdmin(playerid,3))
{
new string[200];
if(!sscanf(params, "u", Actor_ID))
{
if(Actor_ID != INVALID_ACTOR_ID)
{
DestroyActor(ActorData[Actor_ID][aID]);
DestroyDynamic3DTextLabel(ActorData[Actor_ID][aString]);
format(string, sizeof(string), "Actor deleted.. (ACTOR ID: %d)",ActorData[Actor_ID][aID]);
SCM(playerid,GREEN,string);
Actor_ID--;
}
else SCM(playerid,RED,">> Bad actor ID!");
}
else SCM(playerid,RED,"[INFO]: /deleteactor <ID>");
}
else SCM(playerid,RED,">> You are not an admin!");
return 1;
}
Re: Help with actors -
oliverrud - 15.08.2016
Nevermind
Re: Help with actors -
Stinged - 15.08.2016
Use "i" instead of "u"
The "u" specifier in sscanf is used for bots and players, not actors.
So if the player isn't connected, it will return 0xFFFF instead of an integer.
Also, use
IsValidActor instead of INVALID_ACTOR_ID because "i" doesn't work like "u"
Also, take this advice and create strings AFTER the checks, because if someone enters an invalid actor id, you'd be creating a string with 200 cells, and then wasting them because you stopped the command.