PDA

View Full Version : DestroyVehicle problem


Allu
02/03/2012, 10:55 PM
if(strcmp(cmdtext, "/delveh", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /delveh");
return 1;
}
if (PlayerInfo[playerid][pAdmin] >=2)
{
new currentveh;
currentveh = GetPlayerVehicleID(playerid);
DestroyVehicle(currentveh);
}
else SendClientMessage(playerid, COLOR_RED,"You're not admin!");
{
format(string, sizeof(string), "*%d Admin %s: Deleted the vehicle", PlayerInfo[playerid][pAdmin], sendername);
SendAdminMessage(COLOR_YELLOW,string);
}
printf("Admin %s: Deleted the vehicle", sendername);
SendClientMessage(playerid, COLOR_GRAD1,"Vehicle deleted!");
}
return 1;
}


There aren't any errors or warnings in pawno. The command just doesn't work. Can someone fix this code and please explain me what I did wrong?
Thanks :P

Walsh
03/03/2012, 12:13 AM
Your command was a little messy and else statement smack in the middle made the command stop processing.

You should add your else statement at the end of everything like so.

So move this else SendClientMessage(playerid, COLOR_RED,"You're not admin!"); at the end of the command, so it should look like this.
if(strcmp(cmdtext, "/delveh", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /delveh");
return 1;
}
if (PlayerInfo[playerid][pAdmin] >=2)
{
new currentveh;
currentveh = GetPlayerVehicleID(playerid);
DestroyVehicle(currentveh);
format(string, sizeof(string), "*%d Admin %s: Deleted the vehicle", PlayerInfo[playerid][pAdmin], sendername);
SendAdminMessage(COLOR_YELLOW,string);
printf("Admin %s: Deleted the vehicle", sendername);
SendClientMessage(playerid, COLOR_GRAD1,"Vehicle deleted!");
return 1;
}
else
{
return SendClientMessage(playerid, COLOR_RED,"You're not admin!");
}
}
return 1;
}

ricardo178
03/03/2012, 12:25 AM
You lack a "return 1" somewhere. Wont tell you where, just find it out. Not hard. :)

Walsh
03/03/2012, 12:30 AM
You lack a "return 1" somewhere. Wont tell you where, just find it out. Not hard. :)

I don't believe there is, btw if you won't help then don't post man lmao. :P

ricardo178
03/03/2012, 12:35 AM
I don't believe there is, btw if you won't help then don't post man lmao. :P

You are wrong. My post is the one that helps. If i make thhe code for you, you just copy/paste instead of work to fix your own errors. That's how i've learn. Try it.. If doesnn't work, just tell.

But ok.. Here you go, not tested, made almost sleeping, hope it works.


if(strcmp(cmdtext, "/delveh", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /delveh");
return 1;
}
if (PlayerInfo[playerid][pAdmin] >=2)
{
new currentveh = GetPlayerVehicleID(playerid);
DestroyVehicle(currentveh);
return 1;
}
else SendClientMessage(playerid, COLOR_RED,"You're not admin!");
{
format(string, sizeof(string), "*%d Admin %s: Deleted the vehicle", PlayerInfo[playerid][pAdmin], sendername);
SendAdminMessage(COLOR_YELLOW,string);
return 1;
}
printf("Admin %s: Deleted the vehicle", sendername);
SendClientMessage(playerid, COLOR_GRAD1,"Vehicle deleted!");
}
return 1;
}

Walsh
03/03/2012, 12:39 AM
You are wrong. My post is the one that helps. If i make thhe code for you, you just copy/paste instead of work to fix your own errors. That's how i've learn. Try it.. If doesnn't work, just tell.

But ok.. Here you go, not tested, made almost sleeping, hope it works.


if(strcmp(cmdtext, "/delveh", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /delveh");
return 1;
}
if (PlayerInfo[playerid][pAdmin] >=2)
{
new currentveh = GetPlayerVehicleID(playerid);
DestroyVehicle(currentveh);
return 1;
}
else SendClientMessage(playerid, COLOR_RED,"You're not admin!");
{
format(string, sizeof(string), "*%d Admin %s: Deleted the vehicle", PlayerInfo[playerid][pAdmin], sendername);
SendAdminMessage(COLOR_YELLOW,string);
return 1;
}
printf("Admin %s: Deleted the vehicle", sendername);
SendClientMessage(playerid, COLOR_GRAD1,"Vehicle deleted!");
}
return 1;
}


That is why I stated what was wrong, not made up a little trivia to guess where the problem is. Plus our commands are exactly the same, the only difference is the else statement.

ricardo178
03/03/2012, 12:45 AM
Test it... Added some returns... Just test and tell me if it works. I am better with ZCMD + SSCANF but..
Returns are more important than what you think.

EDIT: My bad, you are not the poster. Haha. Sorry. Didn't even see you posted before me. Your one is right i think.. But if you see, you added some returns to the original command.. That's what i said in the comment, lacking returns.