SA-MP Forum
February 09, 2010, 11:06:00 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hosted tab listings available from serverFFS
 
   Home   Help Login Register  
Pages: [1] 2 3 ... 71
  Print  
Author Topic: Useful Commands #1  (Read 196568 times)
Allan
Huge Clucker
***
Posts: 499


View Profile
« on: June 18, 2006, 11:24:39 PM »

As posting random "OnPlayerCommandText" is frowned upon in the Useful Functions topic, I thought I'd make a topic for posting some fun/useful/Downright useless functions to add to your OnPlayerCommandText script!

For those in need of it:
strtok:
Code:
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}

new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}

/lock: Locks Car Doors

Code:
if (strcmp(cmdtext, "/lock", true)==0)
{
if(IsPlayerInAnyVehicle(playerid))
{
State=GetPlayerState(playerid);
if(State!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,COLOR_GREY,"You can only lock the doors as the driver.");
return 1;
}
new i;
for(i=0;i<MAX_PLAYERS;i++)
{
if(i != playerid)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
}
}
SendClientMessage(playerid, COLOR_GREY, "Vehicle locked!");
GetPlayerPos(playerid,X,Y,Z);
PlayerPlaySound(playerid,1056,X,Y,Z);
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You're not in a vehicle!");
}
return 1;
}

/unlock: Unlocks Car Doors

Code:

if (strcmp(cmdtext, "/unlock", true)==0)
{
if(IsPlayerInAnyVehicle(playerid))
{
State=GetPlayerState(playerid);
if(State!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,COLOR_GREY,"You can only unlock the doors as the driver.");
return 1;
}
new i;
for(i=0;i<MAX_PLAYERS;i++)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
}
SendClientMessage(playerid, COLOR_GREY, "Vehicle unlocked!");
GetPlayerPos(playerid,X,Y,Z);
PlayerPlaySound(playerid,1057,X,Y,Z);
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You're not in a vehicle!");
}
return 1;
}


« Last Edit: August 25, 2009, 01:13:20 PM by dugi » Logged

[AU]Ownage
Big Clucker
**
Posts: 80


View Profile
« Reply #1 on: June 26, 2006, 10:58:07 PM »

this reely helped
Logged

LT_kaka_999
Little Clucker
*
Posts: 41


View Profile
« Reply #2 on: June 26, 2006, 11:45:24 PM »

Code:
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(136) : error 017: undefined symbol "State"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(137) : error 017: undefined symbol "State"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(139) : error 017: undefined symbol "COLOR_GREY"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(150) : error 017: undefined symbol "COLOR_GREY"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(151) : error 017: undefined symbol "X"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(152) : error 017: undefined symbol "X"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(156) : error 017: undefined symbol "COLOR_GREY"
Pawn compiler 3.0.3367 Copyright (c) 1997-2005, ITB CompuPhase


7 Errors.


Not working for me Cry
Logged

switch
Big Clucker
**
Posts: 161


View Profile
« Reply #3 on: June 27, 2006, 01:28:47 AM »

Code:
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(136) : error 017: undefined symbol "State"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(137) : error 017: undefined symbol "State"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(139) : error 017: undefined symbol "COLOR_GREY"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(150) : error 017: undefined symbol "COLOR_GREY"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(151) : error 017: undefined symbol "X"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(152) : error 017: undefined symbol "X"
C:\DOCUME~1\Owner\Desktop\Mano\GTASER~1\GAMEMO~1\src\111.pwn(156) : error 017: undefined symbol "COLOR_GREY"
Pawn compiler 3.0.3367 Copyright (c) 1997-2005, ITB CompuPhase


7 Errors.


Not working for me Cry

helps if you know how to code too :p

I just used this code (thanks Allan) so heres one that will work straight out of the box

in onplayercommandtext:
Code:
//car locking code copied from Allan.
if (strcmp(cmdtext, "/lock", true)==0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new State=GetPlayerState(playerid);
if(State!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,0xFFFF00AA,"You can only lock the doors as the driver.");
return 1;
}
new i;
for(i=0;i<MAX_PLAYERS;i++)
{
if(i != playerid)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
}
}
SendClientMessage(playerid, 0xFFFF00AA, "Vehicle locked!");
    new Float:pX, Float:pY, Float:pZ;
GetPlayerPos(playerid,pX,pY,pZ);
PlayerPlaySound(playerid,1056,pX,pY,pZ);
}
else
{
SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
}
return 1;
}


if (strcmp(cmdtext, "/unlock", true)==0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new State=GetPlayerState(playerid);
if(State!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,0xFFFF00AA,"You can only unlock the doors as the driver.");
return 1;
}
new i;
for(i=0;i<MAX_PLAYERS;i++)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
}
SendClientMessage(playerid, 0xFFFF00AA, "Vehicle unlocked!");
new Float:pX, Float:pY, Float:pZ;
GetPlayerPos(playerid,pX,pY,pZ);
PlayerPlaySound(playerid,1057,pX,pY,pZ);
}
else
{
SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
}
return 1;
}
and you you want the for loop in on player exit vehicle.

Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
//printf("OnPlayerExitVehicle(%d, %d)", playerid, vehicleid);

for(new i=0;i<MAX_PLAYERS;i++)
{
if(i != playerid)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
}
}


return 1;
}
Logged
OffRoader23
Little Clucker
*
Posts: 40


View Profile WWW
« Reply #4 on: June 27, 2006, 01:51:48 AM »

I got it almost working, but I got these 2 errors within the script:
Code:
D:\Program Files\Rockstar Games\MTASA\samp\gamemodes\src\naziroad.pwn(272) : error 035: argument type mismatch (argument 1)
D:\Program Files\Rockstar Games\MTASA\samp\gamemodes\src\naziroad.pwn(301) : error 035: argument type mismatch (argument 1)
Logged
[CKB]cereal
Big Clucker
**
Posts: 111


View Profile WWW
« Reply #5 on: June 27, 2006, 02:02:06 AM »

Hidden Command

Code:
if(strcmp(cmd, "/other", true) == 0 || strcmp(cmd, "/hidden", true) == 0) {
SendPlayerFormattedText(playerid,"Look at you, you found the hidden command!!!",0);
return 1;
}

Don't put this in your /commands or /help.

800 foot fall from your current location

Code:
if(strcmp(cmd, "/bigfall", true) == 0) {
if(IsPlayerInAnyVehicle(playerid)) {
        new Float:X;
new Float:Y;
new Float:Z;
        new VehicleID;
        GetPlayerPos(playerid, X, Y, Z);
        VehicleID = GetPlayerVehicleID(playerid);
SetVehiclePos(VehicleID, X, Y, Z + 800.00);
SetPlayerFacingAngle(playerid,Ang);
GivePlayerWeapon(playerid,46,1);
} else {
new Float:X;
new Float:Y;
new Float:Z;
GetPlayerPos(playerid, X, Y, Z);
SetPlayerPos(playerid, X, Y, Z + 800.00);
SetPlayerFacingAngle(playerid,Ang);
GivePlayerWeapon(playerid,46,1);
GameTextForPlayer(playerid, "~w~Weeeeeeeeeeeeeeeeee!!",8000,5);
  }
return 1;
}

Wtf?

Code:
else if(strcmp(cmd, "/wtf", true) == 0) {
if(IsPlayerInAnyVehicle(playerid)) {
new Float:X;
new Float:Y;
new Float:Z;
    new VehicleID;
    GetPlayerPos(playerid, X, Y, Z);
    VehicleID = GetPlayerVehicleID(playerid);
SetVehiclePos(VehicleID, X, Y, Z + 100000000000000);
SetPlayerFacingAngle(playerid,Ang);
SetPlayerInterior(playerid,0);
GameTextForPlayer(playerid, "~y~OMGWTF~p~BBQ ~r~BIGP3NISLOLRARROF~g~LCOPTER!!11s~w~hift11one",6000,5);
} else {
new Float:X;
new Float:Y;
new Float:Z;
GetPlayerPos(playerid, X, Y, Z);
SetPlayerPos(playerid, X, Y, Z + 100000000000000);
SetPlayerFacingAngle(playerid,Ang);
SetPlayerInterior(playerid,0);
GameTextForPlayer(playerid, "~y~OMGWTF~p~BBQ ~r~BIGP3NISLOLRARROF~g~LCOPTER!!11s~w~hift11one",6000,5);
}
return 1;
}

OMG ITS GONE!!!

Code:
if(strcmp(cmdtext,"/clearchat",true)==0) // Chat window is gone, fomg!
{
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
SendClientMessage(playerid,COLOR_GREY," ");
                        SendClientMessage(playerid,COLOR_GREY," ");
return 1;
}

i do nothing

Code:
if(strcmp(cmdtext,"/nothing",true)==0)
{
                       //do nothing
return 1;
}


Speak your soul

Code:
else if(strcmp(cmd, "/sayall", true) == 0) { //type "/sayall ~r~ Hello bob!" (Edit the MSG and text)
    new name[256];
    new tmp[256];
        new tstring[256];
    tmp = strtokspace(cmdtext, idx);
    GetPlayerName(playerid,name,sizeof(name));
    format(tstring, sizeof(tstring), "*** %s: %s",name,tmp);
    GameTextForAll(tmp,5000,3);
      return true;
}
« Last Edit: June 27, 2006, 02:05:02 AM by vCE » Logged

http://forum.sa-mp.com/index.php?topic=2750.0 - Are you a scripting beginner?
http://wiki.sa-mp.com - Official SA-MP Wiki
http://stephantom2.st.funpic.de/experiments/samp/files/a_samp-inc.html - For helpful information on the a_samp.inc



Take a look at the above links and search!

switch
Big Clucker
**
Posts: 161


View Profile
« Reply #6 on: June 27, 2006, 02:46:08 AM »

I got it almost working, but I got these 2 errors within the script:
Code:
D:\Program Files\Rockstar Games\MTASA\samp\gamemodes\src\naziroad.pwn(272) : error 035: argument type mismatch (argument 1)
D:\Program Files\Rockstar Games\MTASA\samp\gamemodes\src\naziroad.pwn(301) : error 035: argument type mismatch (argument 1)

assuming you didnt use the one i posted. You need to setup your xyz variables that store where the player is as floats, eg
new Float:X, Float:Y, Float:Z;
instead of
new X, Y, Z;

anyway this thread is about making commands so its time I start thinking of some good ones Cheesy
Logged
Joshua Yu
Big Clucker
**
Posts: 144


View Profile
« Reply #7 on: July 03, 2006, 11:38:36 AM »

I have done something similar to something someone has done before. But I just change it a little bit that the vehicle gets into your front using sine and cosine. Wink This is how a mathematician does things! Evil
Code:
if (strcmp(cmdtext, "/purchase", true)==0) // to set the vehicle that you register to be teleported
{
    if (GetPlayerMoney(playerid) < 5000)
    {
SendClientMessage(playerid,YELLOW,"Sorry, you don't have enough money to buy a car.");
}
else
{
if (IsPlayerInAnyVehicle(playerid) == 1)
{
SetVehicleToRespawn(ownedcar[playerid]);
ownedcar[playerid] = GetPlayerVehicleID(playerid);
owner[ownedcar[playerid]] = playerid;
SendClientMessage(playerid,YELLOW,"Congragulations! You have purchased a new car.");
GivePlayerMoney(playerid,-5000);
}
else
{
            SendClientMessage(playerid,YELLOW,"Please get in a vehicle to buy it.");
}
}
return 1;
}
if (strcmp(cmdtext, "/callmycar", true)==0)
{
    if (ownedcar[playerid] != 0)
    {
          if (GetPlayerMoney(playerid) < 500)
    {
SendClientMessage(playerid,YELLOW,"Sorry, you don't have enough money to use the car teleport service.");
}
else
{
        new Float:playerpos[4];
    GetPlayerPos(playerid,playerpos[0],playerpos[1],playerpos[2]);
    GetPlayerFacingAngle(playerid,playerpos[3]);
    SetVehicleZAngle(ownedcar[playerid],playerpos[3]+90.0);
    SetVehiclePos(ownedcar[playerid],playerpos[0]+3.0*floatsin(-playerpos[3],degrees),playerpos[1]+3.0*floatcos(-playerpos[3],degrees),playerpos[2]+0.5); // This one is cool that I am using trigo functions to set the vehicle just before you.
    SendClientMessage(playerid,YELLOW,"Thank you for using car teleport service. Your car has came.");
    GivePlayerMoney(playerid,-500);
}
    }
return 1;
}
« Last Edit: July 10, 2006, 08:47:24 AM by Joshua Yu » Logged
Donny
High-roller
*****
Posts: 1861



View Profile
« Reply #8 on: July 04, 2006, 03:46:02 AM »

A function for displaying my kills/deaths/teamkills, just added it to my script a moment ago.

Some vars :

Code:
//Players kills + deaths vars
new MyKills[MAX_PLAYERS];
new MyDeaths[MAX_PLAYERS];
new MyTeamKills[MAX_PLAYERS];
//Colour
#define COLOR_YELLOW 0xFFFF00AA

The function :

Code:
//ShowScore
ShowScore(playerid)
{
new tmpTotal[128];
format(tmpTotal, sizeof(tmpTotal), "Kills :%d, Deaths :%d, Team Kills :%d", MyKills[playerid], MyDeaths[playerid], MyTeamKills[playerid]);
SendClientMessage(playerid, COLOR_YELLOW, tmpTotal);
}

OnPlayerDeath() :

Code:
MyDeaths[playerid]++;  //Put at top of the function under printf(.....)
MyKills[killerid]++;   //I have this under the valid kill section of code
MyTeamKills[killerid]++;  //I have this under the invalid(teamkill) section of code

OnPlayerCommandText() :

Code:
//-------------------/score
if(strcmp(cmd, "/score", true) == 0) {
    ShowScore(playerid);
    return 1;
    }

Enjoy... Evil

Logged

HDD failed, lost my current scripts so anything I've released is the final version now.
Whitestrom
Little Clucker
*
Posts: 4


View Profile
« Reply #9 on: July 04, 2006, 05:37:49 AM »

wach! change day to night or night to day!
Code:
if (strcmp(cmdtext, "/night", true)==0)
{
    /* Do something here */
    SetWorldTime(0);
    GameTextForPlayer(playerid,"~b~notte ~b~oscura ~g~LOL",5000,5);
    return 1;
}
Quote
   if (strcmp(cmdtext, "/day", true)==0)
   {
       /* Do something here */
       SetWorldTime(12);
       GameTextForPlayer(playerid,"~p~Giorno ~p~Felice ~p~LOL",5000,5);
       return 1;
   }
good??? afro
« Last Edit: July 04, 2006, 05:40:13 AM by Whitestrom » Logged

---Whitestorms SA-MP SERVER--
For all countries       |  Server     Under Building
                            | 
For all scripters        | The internaitonal sa mp server
                            |   is coming august 2006 !
For  a best gaming   |      NO CHEATERS!
Mike
Huge Clucker
***
Posts: 378


View Profile
« Reply #10 on: July 04, 2006, 12:51:11 PM »

PAWN Code:
if (strcmp(cmd, "/report") == 0)
{
if (strlen(cmdtext) > 8)
{
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "Report from %s(%d): %s", playername, playerid, cmdtext[8]);
    SendMessageToAdmins(string);
format(string, sizeof(string), "Report sent to currently online admins.");
SendMessage(playerid, string);
}
else {
        format(string, sizeof(string), "Usage: /report <text to send>");
        SendMessage(playerid, string);
}
    return 1;
}

--------------------------------------------

SendMessageToAdmins(const str[])
{
for (new i = 0; i < MAX_PLAYERS; i++)
{
    if (IsPlayerConnected(i)) {
        if (IsPlayerAdmin(i)) {
            SendClientMessage(i, 0xFF9900AA, str);
        }
    }
}
}

SendMessage(playerid, const str[])
{
SendClientMessage(playerid, 0xFF9900AA, str);
}
Logged
Roka
Big Clucker
**
Posts: 154


View Profile
« Reply #11 on: July 04, 2006, 01:11:24 PM »

can someone help? i'm idiot in scripting (NO I DONT WANT TO LEARN), can somebody help with this? i integrate all this script and it gets a lot of errors Sad

i want to make it like filterscript, i almost got it, but some kind off shit. can someone help?

Code:
D:\MYGAME~1\GTASAN~1\samp\pawno\new.pwn(19) : error 017: undefined symbol "cmd"
D:\MYGAME~1\GTASAN~1\samp\pawno\new.pwn(23) : error 017: undefined symbol "playername"
D:\MYGAME~1\GTASAN~1\samp\pawno\new.pwn(23) : error 017: undefined symbol "playername"
D:\MYGAME~1\GTASAN~1\samp\pawno\new.pwn(23) : error 029: invalid expression, assumed zero
D:\MYGAME~1\GTASAN~1\samp\pawno\new.pwn(23) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.0.3367 Copyright (c) 1997-2005, ITB CompuPhase


5 Errors.

this is the errors

here is the script

Code:
#include <a_samp>


public OnFilterScriptInit() {
print("\n----------------------------------");
print("Filterscript Blah sucessfully loaded");
print("----------------------------------\n");
}

public OnFilterScriptExit() {
print("\n----------------------------------");
print("Filterscript Blah sucessfully un-loaded");
print("----------------------------------\n");
}


public OnPlayerCommandText(playerid, cmdtext[]) {

if (strcmp(cmd, "/report") == 0)
{
if (strlen(cmdtext) > 8)
{
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string, sizeof(string), "Report from %s(%d): %s", playername, playerid, cmdtext[8]);
    SendMessageToAdmins(string);
format(string, sizeof(string), "Report sent to currently online admins.");
SendMessage(playerid, string);
}
else {
        format(string, sizeof(string), "Usage: /report <text to send>");
        SendMessage(playerid, string);
}
    return 1;
}

--------------------------------------------

SendMessageToAdmins(const str[])
{
for (new i = 0; i < MAX_PLAYERS; i++)
{
    if (IsPlayerConnected(i)) {
        if (IsPlayerAdmin(i)) {
            SendClientMessage(i, 0xFF9900AA, str);
        }
    }
}
}

SendMessage(playerid, const str[])
{
SendClientMessage(playerid, 0xFF9900AA, str);
}
« Last Edit: July 04, 2006, 01:16:02 PM by Roka » Logged

Mhhh....
rapidZ
Huge Clucker
***
Posts: 237


View Profile WWW
« Reply #12 on: July 04, 2006, 01:15:27 PM »

can someone help? i'm idiot in scripting (NO I DONT WANT TO LEARN), can somebody help with this? i integrate all this script and it gets a lot of errors Sad

dont think anyone can do aqnything untill they see your errors which oyu keep getting. And you dont want ot learn how to fix them so you gona have to post your code!!!
Logged

Visit My Site - http://RapidZWorld.tk
Roka
Big Clucker
**
Posts: 154


View Profile
« Reply #13 on: July 04, 2006, 01:16:29 PM »

i posted Wink

oh nevermind, i got it how to mak this filterscript to work Smiley
« Last Edit: July 04, 2006, 01:33:06 PM by Roka » Logged

Mhhh....
Roka
Big Clucker
**
Posts: 154


View Profile
« Reply #14 on: July 09, 2006, 05:10:19 PM »

Y_less oh sorry, now i now how to creat filterscripts, and how to find where is problem Smiley


Logged

Mhhh....
Pages: [1] 2 3 ... 71
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF one | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!