Help with actors
#1

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(playeridparams[])
{
    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(stringsizeof(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(stringsizeof(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(playeridparams[])
{
    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(stringsizeof(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;

Reply
#2

Nevermind
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)