SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 17/05/2020, 07:46 PM   #1
seventyone
Little Clucker
 
Join Date: Feb 2020
Posts: 31
Reputation: 0
Default help please

hi, i need /carwhisper command (/cw) please...
Thanks
seventyone is offline   Reply With Quote
Old 17/05/2020, 08:21 PM   #2
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: help please

What is it with all the people requesting command like it's a script request forum...
You didn't even give a proper explanation of what your command is supposed to do.
Post whatever code snippet you already have.
If you're looking for a person to do it for you, this is the wrong place, look at here instead:
Looking for scripters/helpers? Post here!
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 18/05/2020, 07:53 AM   #3
seventyone
Little Clucker
 
Join Date: Feb 2020
Posts: 31
Reputation: 0
Default Re: help please

Quote:
Originally Posted by Adamoneoone View Post
What is it with all the people requesting command like it's a script request forum...
You didn't even give a proper explanation of what your command is supposed to do.
Post whatever code snippet you already have.
If you're looking for a person to do it for you, this is the wrong place, look at here instead:
Looking for scripters/helpers? Post here!
Code:
CMD:cw(playerid, params[])
{
	static
		userid;
	if (sscanf(params, "u", userid))
		return SendSyntaxMessage(playerid, "/cw [text]");
	new string[128];
	for(new i = 0; i < MAX_PLAYERS; i ++)
    if(IsPlayerInVehicle(i, GetPlayerVehicleID(i)))
    SendClientMessage(playerid, COLOR_YELLOW, string);
	return 1;
}
But when I type /cw [text] in the car, nothing happens
seventyone is offline   Reply With Quote
Old 18/05/2020, 08:17 AM   #4
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 488
Reputation: 37
Default Re: help please

I don't exactly get what you're trying to achieve.
This part:
Code:
new string[128];
for(new i = 0; i < MAX_PLAYERS; i ++)
if(IsPlayerInVehicle(i, GetPlayerVehicleID(i)))
SendClientMessage(playerid, COLOR_YELLOW, string);
Won't do anything at all because:
You create a string and send the player a message using that string, however you never format it or set its text if you will.
The for loop is absolutely pointless, because in the end you never use the "i". Did you mean to write:
Code:
SendClientMessage(i, COLOR_YELLOW, string);
This part won't work either:
Code:
if (sscanf(params, "u", userid))
return SendSyntaxMessage(playerid, "/cw [text]");
You're trying to ask sscanf to look for a valid playerid (the "u" specifier is wrong), and you are expecting to check if it's a string or not.

Should be:
Code:
new string[128]; //or any size.
if (sscanf(params, "s[128]", string)) return SendSyntaxMessage(playerid, "/cw [text]");
And now, you don't need to redeclare a string.
I think you've got everything to get your code sorted.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!

Last edited by Adamoneoone; 18/05/2020 at 08:56 AM.
Adamoneoone is offline   Reply With Quote
Old 18/05/2020, 08:51 AM   #5
Shadow0707
Big Clucker
 
Join Date: Sep 2016
Posts: 92
Reputation: 7
Default Re: help please

Firs you must get if player state if he is driver or passenger
pawn Code:
new pstate[128];
    switch(GetPlayerState(playerid))
    {
        case PLAYER_STATE_DRIVER: pstate = "Driver";
        case PLAYER_STATE_PASSENGER: pstate = "Passenger";
    }

Get player name and the state when sending a message

pawn Code:
new pname[MAX_PLAYER_NAME+1], msg[128];
GetPlayerName(playerid, pname, sizeof pname);

//format for sending message with player state and name and message
format(msg, 128, "%s %s (%d): %s", pstate, pname, playerid, msg);

Now loop then get player vehicle id before sending message so it'll only send to those who's in the car

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++) {
        if(IsPlayerInVehicle(i, GetPlayerVehicleID(playerid)))
        {
            SendClientMessage(i, -1, msg);
        }
}

This is just a sample! don't just copy and paste.
Shadow0707 is online now   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



All times are GMT. The time now is 03:44 AM.


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