29.10.2012, 11:04
(
Последний раз редактировалось Emmet_; 17.03.2014 в 14:45.
)
~~~~
If you return the string directly, you can't specify an array size, it's constrained to the size defined in the array declaration in the function!
pawn Код:
pawn Код:
pawn Код:
I used to think the direct return was good, until I ran into an array size problem with my file script. It used to do this: string = file_GetStr("key"); But that pre-defined the return string as 128 cells, no more, no less. So now it works like this: file_GetStr("key", string); Which also means I can do stuff like: pawn Код:
pawn Код:
|
string_return()
{
new string[500];
format(string, 500, "Hello world!");
return string;
}
main()
{
new string[13];
format(string, 13, "%s", string_return());
print(string);
}
new PlayerIsSpawned[MAX_PLAYERS];
stock IsPlayerSpawned(playerid)
{
if(PlayerIsSpawned[playerid] == 1) return true;
else return false;
}
public OnPlayerSpawn(playerid)
{
PlayerIsSpawned[playerid] = 1;
CallLocalFunction("L_OPS", "d", playerid);
return 1;
}
public OnPlayerConnect(playerid)
{
PlayerIsSpawned[playerid] = 0;
CallLocalFunction("L_OPC", "d", playerid);
return 1;
}
#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn L_OPS
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect L_OPC
forward L_OPS(playerid);
forward L_OPC(playerid);
CMD:suicide(playerid, params[])
{
if(IsPlayerSpawned(playerid))
{
SetPlayerHealth(playerid, 0.0);
}
else
{
SendClientMessage(playerid, 0xFF0000FF, "You must be spawned to use this command.");
}
return 1;
}
stock bool:IsPlayerSpawned(playerid) {
new pstate = GetPlayerState(playerid);
if((pstate >= PLAYER_STATE_ONFOOT && pstate <= PLAYER_STATE_ENTER_VEHICLE_PASSENGER) || pstate == PLAYER_STATE_SPAWNED) return true;
return false;
}
stock IsValidObject(value) {
static const valid_values[563] = {
-1, -4030465, -1048577, -1, -1, -33292289, -1, -1, -1, -113, -1073741825, -1, -2, -1, -1, -1, -1, -1, -65529, -1, -1, -1, -129, -1, -1, -1, -1, -1, -1, -1073741825, -1, -1, -1, -268435457, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -838598657, -1, -1, -1, -1, -1, -1, -1, 25166335, -16777216, 266249, 16512, -134255428, -1, -1, -24577, -1, -1073872897, -1, -1, -1, -1, -1, -1572865, -1, -1, -1, -1, -1, -3, -1, -25165825, -1041, -1, 2147483647, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2139095041, -1, -1, -1, -1, -1, -1, 1048575, -2147483648, -1, -1, -1, -1, -1, -1, -1, -1, 130023423, -1024, -1, -1, -1, -1, -1, -1, -1, 33554431, -128, -1, -1, -1, -1, -1, -1, -1, -1, 4095, -1, -1, -1, -1, -1, -1, -1, -1, -1, -3145729, -65, -1, -1, -1, -1, -1, -1, 1919, -2, -1, -33, -1, -1, -1, -1, 8388607, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -256, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 67108863, -65536, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2147483647, -8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -16377, -1, -8193, -1, -1, -1, -1, -1, -1, -8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -8126465, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1572865, -1, -1, -1, -1, -1, -1, -1, 134217727, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -33554432, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2097151, -32768, -1, 536870911, -2, -1, -1, -1, -1, -1, 268435455, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -256, -1, -1, -1, -67108865, -5242881, -1, -1, -403169281, -1, -15, -253, -1921, -1, -1, -536870917, 126975, 0, 0, 0, -1024, 262143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -33554432, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 65535, 0, 0, 0, 0, 0, 0, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 268435455, -2097152, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 720895, -512, -16385, -1, 38207487, 0, 0, -131072, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
if (615 <= value <= 18630) {
value -= 615;
return (valid_values[value >>> 5] & (1 << (value & 31))) || false;
}
return false;
}
stock RemovePlayerWeapon(playerid, ...) { new Args = numargs(); for(new i = 1; i < Args; i++) { SetPlayerAmmo(playerid, getarg(i), 0); } return 1; }
RemovePlayerWeapon(playerid, 26, 25);
stock IsPaintjobVehicle(value) {
static const valid_values[3] = {
1, 3670016, 806680576
};
if (483 <= value <= 576) {
value -= 483;
return (valid_values[value >>> 5] & (1 << (value & 31))) || false;
}
return false;
}
stock GetVehiclePAWNData(const vehicleid)
{
new TempStr[650];
new Float:_Pos[3],
Float:_Angle;
GetVehiclePos(vehicleid, _Pos[0], _Pos[1], _Pos[2]);
GetVehicleZAngle(vehicleid, _Angle);
format(TempStr, 130, "new const v = CreateVehicle(%d, %f, %f, %f, %f, COLOUR_1, COLOUR_2, RESPAWN_TIME);", GetVehicleModel(vehicleid), _Pos[0], _Pos[1], _Pos[2], _Angle);
new TempLine[60], c;
new const SlotName[14][24] =
{
"CARMODTYPE_SPOILER",
"CARMODTYPE_HOOD",
"CARMODTYPE_ROOF",
"CARMODTYPE_SIDESKIRT",
"CARMODTYPE_LAMPS",
"CARMODTYPE_NITRO",
"CARMODTYPE_EXHAUST",
"CARMODTYPE_WHEELS",
"CARMODTYPE_STEREO",
"CARMODTYPE_HYDRAULICS",
"CARMODTYPE_FRONT_BUMPER",
"CARMODTYPE_REAR_BUMPER",
"CARMODTYPE_VENT_RIGHT",
"CARMODTYPE_VENT_LEFT"
};
for(new i = 0; i < 14; i++)
{
c = GetVehicleComponentInSlot(vehicleid, i);
if(c != 0)
{
format(TempLine, 60, "\r\nAddVehicleComponent(v, %d); // %s", c, SlotName[i]);
strcat(TempStr, TempLine);
}
}
return TempStr;
}
new const v = CreateVehicle(600, 2394.272705, 1034.542236, 10.514182, 140.348159, COLOUR_1, COLOUR_2, RESPAWN_TIME); AddVehicleComponent(v, 1004); // CARMODTYPE_HOOD AddVehicleComponent(v, 1006); // CARMODTYPE_ROOF AddVehicleComponent(v, 1007); // CARMODTYPE_SIDESKIRT AddVehicleComponent(v, 1013); // CARMODTYPE_LAMPS AddVehicleComponent(v, 1010); // CARMODTYPE_NITRO AddVehicleComponent(v, 1020); // CARMODTYPE_EXHAUST AddVehicleComponent(v, 1097); // CARMODTYPE_WHEELS AddVehicleComponent(v, 1087); // CARMODTYPE_HYDRAULICS
stock SetPlayerMoney(playerid, cash) { ResetPlayerMoney(playerid); return GivePlayerMoney(playerid, cash); }