Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - DraGone

#1
Support / Re: Strange exception
Jul 26, 2020, 09:46 AM
Quote from: Yyg on Jul 26, 2020, 03:07 AM2. I don't know if it is related to the first question, but sometimes, when the number of servers is large, I run a bunch of basic codes
CreatePickup( 407, 1, 0, Vector( x.tofloat(), y.tofloat(), z.tofloat() ), 255, true );
Sometimes it is not visible, but the instance is not empty. When I try to query Pickup.ID, it is a string of eight-digit long numbers. I think that although this is not empty, it is not actually generated because I can't found it or Pick up

I don't know if this is a server delay behavior or what, it's worth mentioning that my server has some more pickups and checkpoints, but none of them exceed the maximum number. Maybe there are 100 checkpoints and 1,400 pickups.
My guess is the pickup was mistakenly deleted somewhere in your script. The ID is not supposed to be eight digit (based on pickup limit, the pickup ID should not be more than 1999), you can also confirm whether the pickup still exist in the server by using: FindPickup( pickup_var.ID ); and 'pickup_var' is the variable in which you stored the pickup. It most probably will return null..
#2
You just need to use IsNum() function if you want to check whether the text is a number..

You dont necessarily need to check whether the text is number if you just want to compare two string. You can just do it right away, e.g:
function onPlayerCommand(player, command, text)
{
// Remember, 'text' is a string by default, no matter you typed a number or anything
// Or it is simply null if player left it empty

if ( command == "test" )
{
/* Only proceed if 'text' is not null because we cant compare 'null' with a string */
if ( text != null )
{
/* Compare the 'text' with string '5', notice "5" is a string not integer */
if ( text == "5" ) PrivMessage( player, "You just typed: 5" );
else if ( text == "a" ) PrivMessage( player, "You just typed: a" );
}
}
}

You just need to use IsNum if you really want and need the text to be number, e.g.
function onPlayerCommand(player, command, text)
{
if ( command == "givemecash" )
{
/* Only proceed if 'text' is not null because IsNum function only accept string */
if ( text != null )
{
/* Check whether the 'text' is a number using IsNum function */
/* If it return true, that means the the text is indeed a number */
if ( IsNum( text ) == true )
{
/* Convert 'text' from string to integer. In this example we are going to increase player's cash so it must be integer */
text = text.tointeger( );

/* Compare 'text' with integer 0, we can compare it with integer cuz we already converted it to integer just now */
if ( text <= 0 ) PrivMessage( player, "Hey, the amount must be higher than 0!" );
else
{
player.Cash += text;
PrivMessage( player, "You just got $"+ text +"!" );
}
}
else
{
PrivMessage( player, "Hey, "+ text +" is not a number!" );
}
}
else PrivMessage( player, "Please specify how much you need" );
}
}

The codes above are untested, it's just an example!
#3
I'd say you should avoid timer for that and use table to store such information. E.g. (untested):
/* Global table that will be used to store commands' cooldown for each player */
_cmdCoolDown <- { };


function onPlayerJoin( player ) {
/* Add the player to the cooldown table */
// In this example i use player's name to identify the player but you can also use player's ID or even UID
_cmdCoolDown.rawset( player.Name, { } );
}


function onPlayerPart( player, reason ) {
/* Remove the player from cooldown table */
if ( _cmdCoolDown.rawin( player.Name ) )
{
_cmdCoolDown.rawdelete( player.Name );
}
}


function onPlayerCommand( player, cmd, text )
{
if ( cmd == "fixveh" )
{
// time() will return the unix time
// which is the number of seconds that have elapsed since the time 00:00:00 UTC on 1 January 1970
local unix_time_now = time( );

/* Check whether the cooldown time has passed or not */
// if cooldown time value is higher than unix_time_now, that means it's not passed yet
if ( _cmdCoolDown[player.Name].rawin("FixVeh") && _cmdCoolDown[player.Name]["FixVeh"] > unix_time_now )
{
/* If it's not passed, inform player */
local time_left = ( unix_time_now - _cmdCoolDown[player.Name]["FixVeh"] );
PrivMessage( player, "Please wait "+ time_left +" more seconds to use this command.." );
}
else
{
// Fix veh..etc
//

/* If everything is okay, set new cooldown time */
_cmdCoolDown[player.Name].rawset( "FixVeh", (unix_time_now + 600) ); // 600 sec = 10 mins
}
}
}
#4
Support / Re: : Property system bug
Sep 22, 2018, 04:32 PM
Check/print the value of variable 'name' and 'query' to find the cause..
#5
General Discussion / Re: help here if n else
Sep 22, 2018, 04:15 PM
I'm not sure what you are trying to achieve, but here it is..
function onPlayerSpawn( player )
{
if ( player.World == 24 )
{
/* If player is in world 24, server will run the code below */
if(something == something) {
player.Pos = Vector(  -1734.98,-1725.85,14.868 );
player.Colour = RGB(255, 0, 0);
player.Skin = 73;
}
else if (something == something) {
player.Pos = Vector(-1099.68,1393.21,8.73682);
player.Colour = RGB(0, 0, 255);
player.Skin = 95;
}
}
else if ( player.World == 27 )
{
/* If player is in world 27, server will run the code below */
if (something == something) {
player.Pos = Vector( 605.065,-745.095,11.0712 );
player.Colour = RGB(255, 0,255);
player.Skin = 90;
}
else if (something == something) {
player.Pos = Vector(600.586,-937.486,11.972);
player.Colour = RGB(0, 255, 255);
player.Skin = 145;
}
}
else
{
/* If player is not in world ID 24 nor 27, server will run the code below */
player.World = 1;
}
}

Link below should give you some clue about how if, else if and else works
https://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm