beginner race server

Started by habi, Feb 17, 2020, 04:40 PM

Previous topic - Next topic

habi

hi i made a beginner race server.
actually this is all what i had been doing.
today i got little enthusiasm, as checkpoints keep coming. so i am publishing this.
this contains a sound file. it is pickup sound. (copy it to store/sounds folder)

Final download link (19/04/2020):here

Gito Baloch

Programming is the language I speak, the world I shape, and the future I code


Sebastian

Some more info about it would be good.
How does it work?
What commands do we have, if we have any ?!
Screens ?

habi

#4
ok seby. I will detail

how does it work
player A types !race and a checkpoint with a marker is created for him.
player B type !race and a checkpoint with a marker is created for her.
...
player E also types !race  same thing.

player A pickup the first checkpoint, then the second checkpoint appears for him. when he picks the second, the third appears for him.

the colour of the last checkpoint is red. when player A hits it, mission passed $1500
and at the same time mission failed message appears for everybody else. all checkpoints and markers will get destructed the. similarly if a player quits or get killed, his checkpoint and markers and deleted. i have used a thing like stats[player.ID].checkpointid   and stats[player.ID].markerid,  stats[player.ID].onmission.

you can use !widescreen

this is my personal script, so you can find other cool things i made like, when you enter car, you get driveby weapon. when you exit car, you get back last weapon.

i have removed spawn screen, so any new players can spawn easily

this is the checkpoint data.
chkdata.push(Vector(-674.615, 702.617, 10.9149));
chkdata.push(Vector(-679.688, 620.902, 10.6974));
chkdata.push(Vector(-718.341, 272.344, 10.6967));
chkdata.push(Vector(-815.816, -55.297, 10.6972));
...

a command !cc will print playerpos in console
print("Vector("+player.Pos.x+", "+player.Pos.y+", "+player.Pos.z+");")

the command !cp will create a sample checkpoint. edit colours and see what happens using this command. besides !eject command is there.

and also when you spawn, you spawn with some weapons. that is all.

link https://gofile.io/?c=LSm75l
screen https://imgur.com/a/e250qXJ

Sebastian

Thanks for the elaboration!
I said it for your own good, so your releases will be more attractive ;)



Related to the script, I have few suggestions, because it doesn't sound very fair...
But I cannot read the code yet, so corect me if I'm wrong!

If player A uses "!race", then the checkpoint will be created.
If player B uses the same command, a checkpoint will be created for him too.

But is player A frozen until he gets some opponents ?
Because, otherwise, logical, the first person who writes "!race" wins the race, because he will be the first one having checkpoints.

Also, canceling the race for the others, because one guy finishes the race, kinda sucks. Maybe you are having fun racing against some other opponent you have right in front of you, trying your best to win on some curve or straight line, even if you are fighting for the 5th place

habi

seby the player is not frozen . it is a bit problem.
also cancelling the race kinda sucks, i need to work on these.
new code in 2 days.

habi

#7
as i promised..
Quote from: habi on Feb 20, 2020, 06:19 PMseby the player is not frozen . it is a bit problem.
also cancelling the race kinda sucks, i need to work on these.
new code in 2 days.
screen https://imgur.com/a/KglB8sC
we type !race (or /race ) and race starts automatically in 10 seconds. in this 10 seconds, other players can join by !race.
when a player !race, that player is put in a car (sentinel) and frozen. i have made 4 cars.
making of cars
if there is only one player one car is made. if there are two players two cars are made side by side. and if it is 3, then one more car is added on back. if we have four players, then two rows of cars.

tick tick 10.9....1 GO. then player is unfrozen. and race begins. when a player picks the last checkpoint. "You finished rank ". message is shown to him. others can still race.
when the last player finishes, the race ends.

when the race ends those cars which we created are destructed.

if a player /kill or quit or onplayerkill etc, then he is out of the race. all checkpoints and markers get destructed for him.

i have watched The Driver mission video a couple of times, to make  this like that.
there is also a black screen fade in fade out function in script, but i have not used it.

FAQ
Can players join after the race is started?
When a new player types !race, after the race a message is shown "A race is already in progress. please wait".
Can we get out of car?
yes.
Can checkpoints be picked by foot or (as passenger..)
No
How many seconds the player wait inside car?
it was 10. now it is 16 seconds. i.e. within this time, all players must join through !race.

Problems
1. While the player is in the car, frozen waiting for the race to be started a new player can kill them.
2. Cars are made for 4 players only. i have temporarily coded ..if a fifth player is there, a sentinel car is created at player.Pos and he is frozen and put inside :)

that is all. thanks. thanks everybody

link https://gofile.io/?c=UM41mL

Sebastian

Improvements! Good.
There is still much to work, to act like a proper racing acript, but you are on the good way!

Btw, I think this "gamemode" should be converted in a way that everybody can use in their servers, like a "Racing System".
Would be easier to use and implement, for newbies

habi

#9
hi i got a wonderful result. see this. https://imgur.com/7CuaFQ9

created a 100 cars using 'for loop' with initial position and angle.

this is the basic function i made, ( it was like a war . math, trigonometry)
function move(pos, distance, angle)
{
local newx = pos.x - sin(angle)*distance;//I calculated it from all sides. works perfect.
local newy = pos.y + cos(angle)*distance;//for y this
return Vector(newx,newy,pos.z);//assuming z more or less same.
}
where the arrow in the image is the player pointing  somewhere.

this i used with one cars position.
like this
so cars get created automatically.
and the function for that was (from my script)
PI<-3.1415926;
function test()
{
        local pos=Vector(-670.079, 720.795, 10.9149); local angle = PI;//in downtown this is pi
local i =0;local newpos;
for(i=0;i<100;i++)
{
if(i%2==0)//first column
newpos=move(pos,-8*i/2,angle);
else //second column
newpos=move(newpos,5  ,angle-PI/2);//right or clockwise means -PI/2
CreateVehicle( 135, newpos, angle, 2, 0);
}
}

image of my notebook https://imgur.com/UmOq7rB

edit 28/02/2020
how to use this function. black dot is you and you want to move to orange dot. all you need is to find out the angle.

NicusorN5



habi

#12
i have finished it. converted it to a gamemode so players can use.
How to use?
Add these functions

onScriptLoad()
[noae]function onScriptLoad()
{
    PI<-3.1415926;
db <- ConnectSQL( "race.db" );
ALL<-array(100);
local i=0;
for(i=0;i<100;i++)ALL[i]=setPdata();

chkdata<-[];
cdata();

allraces();
start_pos<-Vector(-670.079, 720.795, 10.9149);
start_angle<-PI;//downtown
start_car<-135;//135 is sentinel
race_name<-"downtown";//default.

if(!existsrace(race_name))
saverace(race_name,chkdata,start_car,start_pos,start_angle);//default race

rank<-1;//first rank is 1.
race_started<-false;
race_announced<-false;
race_cars<-[];//storing vehicle instances created for racing.

race_list<-[];//storing list of all races.
updatelist();
race_timers<-[];

//------------------------------creating race---------------------
model<-null;stpos<-null;stangle<-null;tdata<-[];cps<-[];mks<-[];author<-null;
//----------------------------------------------------------------
}
[/noae]
onPlayerJoin
[noae][noae][noae][noae][noae][noae][noae][noae]function onPlayerJoin( player )
{
Announce("Welcome to the server. Type !race to have a race", player,1);

}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]

onPlayerPart
[noae][noae][noae][noae][noae][noae][noae][noae]function onPlayerPart( player, reason )
{
destroy_all_markers( player );
destroy_all_checkpoints( player );
if(ALL[player.ID].onmission==1)
{
ALL[player.ID].onmission=0;
if(isanybodyonmission()==false)endrace();
}
ALL[player.ID]=setPdata();
if(author==player.Name)
{
reset();
}
return
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]
onPlayerDeath()
[noae][noae][noae][noae][noae][noae][noae][noae]function onPlayerDeath( player, reason )
{
Announce("~t~wasted!", player,5);
if(ALL[player.ID].onmission==1)
{
mission_failed(player);
if(isanybodyonmission()==false)endrace();
}
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]
onPlayerKill() and onPlayerTeamKill()
[noae][noae][noae][noae][noae][noae][noae][noae]function onPlayerKill( player, killer, reason, bodypart )
{
if(ALL[killer.ID].onmission==1)
{
mission_failed(killer);
if(isanybodyonmission()==false)endrace();
}
return 1
}
function onPlayerTeamKill( player, killer, reason, bodypart )
{
if(ALL[killer.ID].onmission==1)
{
mission_failed(killer);
if(isanybodyonmission()==false)endrace();
}
return 1
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]
just to use !race onPlayerChat()
[noae][noae][noae][noae][noae][noae][noae][noae]function onPlayerChat( player, text )
{
print( player.Name + ": " + text );
local b =text.slice(0,1);
text=text.slice(1)
if(b=="!")
{
local params = split( text, " " ); // Take out the space array
if(params.len()>1)
onPlayerCommand( player, params[0], text.slice(params[0].len()+1))
else if(params.len()==1)
onPlayerCommand( player, params[0], "")
else MessagePlayer("!cmds", player)
}
return 1;
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]
onPlayerCommand( player, cmd, text )
[noae][noae][noae][noae][noae][noae][noae][noae]function onPlayerCommand( player, cmd, text )
{
cmd = cmd.tolower();
if(cmd == "pos")
{
print( "Vector(" + player.Pos.x + "," + player.Pos.y + "," + player.Pos.z + ")," + player.Angle+ ""  );
}else if(cmd == "eject")
{
player.Pos=player.Pos;
}
else if (cmd =="cmds")
{
MessagePlayer("[#C0C0C0]!eject !race !widescreen !stoprace !list",player);

}else if(cmd =="widescreen")
{
player.Widescreen=!player.Widescreen;
}else if( cmd == "startpos" )
{
//this is the first position of 1st race car.
//all other cars can be created using this position. see forum for details.
if(player.Vehicle)
{
local m = player.Vehicle.Model;
local p=player.Vehicle.Pos;
local q=getvehicleangle(player.Vehicle);
model=m;
stpos=p;
stangle=q;
MessagePlayer("[#C0C0C0]Set Model="+model+" start_pos= "+p+" start_angle="+q, player);
MessagePlayer("[#C0C0C0]Now start adding checkpoints",player);
}else MessagePlayer("[#C0C0C0]You must be in desired vehicle parked at the starting position",player);
} else if(cmd=="cp" )
{
if(ALL[player.ID].onmission==1)return;
if(author!=null&&author!=player.Name)return;
//the checkpoint is created a little down to have correct display 0.9
local p = Vector(player.Pos.x,player.Pos.y, player.Pos.z-0.9);
local q =CreateCheckpoint( null, 0, false, p, ARGB(255, 255, 160, 193), 6);
local r =CreateMarker(player.UniqueWorld, player.Pos, 5, RGB(241, 36, 241), 0 );
tdata.push(p);
cps.push(q.ID);
mks.push(r);
if(author==null)author=player.Name;
MessagePlayer("[#C0C0C0]Checkpoints no: "+tdata.len(),player);

}else if(cmd=="undo")
{
if(tdata.len()==0)return;
if(player.Name!=author.Name)return;
local c=cps.pop();//last checkpoint id
local d =FindCheckpoint(c);
if(d)d.Remove();
d = mks.pop();//just using above variable.
if(d!=null)DestroyMarker(d);
tdata.pop();
MessagePlayer("[#C0C0C0]Checkpoint no:"+tdata.len(),player);
}else if(cmd=="save")
{
if(player.Name!=author.Name)return;
if(tdata.len()==0)return;
if(stpos==null)return;
if(stangle==null)return;
if(model==null)return;
if(!text){MessagePlayer("[#C0C0C0]/save name",player);return;}
if(existsrace(text)){MessagePlayer("[#C0C0C0]that name already exists",player);return;}
local success=saverace(text,tdata,model,stpos,stangle);
if(!success){MessagePlayer("[#C0C0C0]an error occured.",player);return;}
reset();
MessagePlayer("[#C0C0C0]Race created successfully. name:"+text, player);
}else if(cmd=="list")
{
local str="";local i =0;
for(i=0;i<race_list.len();i++)
{
str=str+(i+1)+"."+race_list[i]+" ";
}
MessagePlayer("[#C0C0C0]Use /race id \n"+str,player);
}else if(cmd=="reset")
{
if(player.Name==author)reset();
}else if(cmd=="delete")
{
//if(text)deleterace(text)    //be careful. everybody can delete
}else if(cmd=="getcar")
{
CreateVehicle( 135, Vector(player.Pos.x+2,player.Pos.y+1,player.Pos.z), 0, rand()%94, 0);//random colour
}else if(cmd=="acc")
{
accelerate(player.Vehicle,text.tofloat());
}else if(cmd=="race")
{
if(ALL[player.ID].onmission==1)
{
MessagePlayer("[#C0C0C0]You are already in the race",player);
return;
}
if(text)
{
//text can be id or name
local name;
if(IsNum(text))
{
local a=text.tointeger();
if(a>0 && a<race_list.len())name=race_list[a-1];
}else name=text;
if(!existsrace(name)){MessagePlayer("[#C0C0C0]Invalid id. Use /list",player); return;}
if(race_announced==true)
{
MessagePlayer("[#C0C0C0]"+race_name+" is already loaded. Join? /race",player);
return;
}

local success=loadrace(name);
if(success)Message("[#C0C0C0]race "+name+" loaded");
else return;
}

if(player.IsSpawned==false)return;
local bool =false;

if(race_started==true)
{
Message("[#C0C0C0]There is a race going on. Please wait.");
return;
}else if(race_announced==false)
{
Message("[#C0C0C0]Player "+player.Name+" started a race. !race to join. 20 seconds.");
destroy_all_racecars();
race_announced=true;
bool = true;
}

ALL[player.ID].onmission=1;
destroy_all_markers(player);
destroy_all_checkpoints(player);
createcp_ordinary(player, chkdata[0]);
createmkr(player, chkdata[0]);
ALL[player.ID].cpno=0;

local vehicle =createcar();
player.Pos=player.Pos;
player.Vehicle=vehicle;
player.Immunity=127
vehicle.Immunity=127;
player.IsFrozen=true;

if(bool==true)
{
rank=1;
local seconds= 20; //player wait 20 seconds in car.
local t = NewTimer("startrace",(seconds+3)*1000,1); //3 seconds announce new style.
race_timers.push(t);
MessagePlayer("[#C0C0C0]The race will start soon. Waiting for players to join !race",player);
local i =0;
for( i=0;i<seconds; i++)
{
t=NewTimer("msg_race_players",(i+1)*1000,1,""+(seconds-i),0,2);
race_timers.push(t);
}
t = NewTimer("msg_race_players",(i+1)*1000,1,"",0,2);//clear
race_timers.push(t);

}

}else if(cmd=="stoprace")
{
if(race_started==false)
{
if(ALL[player.ID].onmission==1)
{
player.IsFrozen=false;
player.Immunity=0;
Announce("",player,5);
mission_failed(player);
ALL[player.ID].onmission=0;
if(isanybodyonmission()==false)endrace();
}
return;
}
if(ALL[player.ID].onmission==1)
{
mission_failed(player);
endrace();
//if(isanybodyonmission()==false)endrace();
}
}
return 1;
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]
onCheckPointEntered()
[noae][noae][noae][noae][noae][noae][noae][noae]function onCheckpointEntered( player, checkpoint )
{
if(ALL[player.ID].onmission==1)
{
if(player.Vehicle==null)return;
if(player.Vehicle.Driver.Name!=player.Name)return;
PlaySound( player.UniqueWorld , 50006 , player.Pos );
checkpoint.Remove();
destroy_all_markers(player);
ALL[player.ID].cpno+=1;
local n= ALL[player.ID].cpno;
if(n!=chkdata.len()) //ie not the last checkpoint
{
if(n!=chkdata.len()-1) //ie.  red checkpoint
createcp_ordinary(player, chkdata[n]);
else
createcp_red(player, chkdata[n]);
createmkr(player,chkdata[n]);
}else//ie. last checkpoint
{
Announce("You finished "+getrank(rank), player,1);
Message("[#C0C0C0]"+player.Name+" finished rank "+rank);
rank+=1;
PlaySound( player.UniqueWorld , 50007 , player.Pos );
ALL[player.ID].onmission=0;
ALL[player.ID].cpno=0;
if(isanybodyonmission()==false)endrace();
}

}
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]

other functions
[noae][noae][noae][noae][noae][noae][noae][noae]function setPdata()
{
return {markerid=null,checkpointid=null,onmission=0,cpno=0};
}
function mission_failed(player)
{
destroy_all_checkpoints(player);
destroy_all_markers(player);
ALL[player.ID].onmission=0;
Announce("you lost the race", player,1);
ALL[player.ID].cpno=0;
}

function mission_failed_everybody()
{
local i =0;
for(i=0;i<100;i++)
{
local player = FindPlayer(i);
if(player && ALL[i].onmission==1)mission_failed(player);

}
}
function createnext(pos,angle,i)
{
local newpos;
if(i%2==0)newpos=move(pos,-8*i/2,angle);
else newpos=move(move(pos,-8*(i-1)/2,angle),5,angle-PI/2);
return CreateVehicle( start_car, newpos, angle, rand()%94, 0);//random colour
}
function createcar()
{
local car =createnext(start_pos,start_angle,race_cars.len());
race_cars.push(car);
return car;
}

function createcp_ordinary(player, pos)
{
destroy_all_checkpoints(player);
local c =CreateCheckpoint( player, player.World, false, Vector(pos.x,pos.y,pos.z-0.9), ARGB(255, 255, 160, 193), 6);
//we create the checkpoint like in The Driver mission.
ALL[player.ID].checkpointid=c.ID;
return 1;
}
function createcp_red(player, pos)
{
destroy_all_checkpoints(player);
local c =CreateCheckpoint( player, player.World, false, Vector(pos.x,pos.y,pos.z-0.9), ARGB(255, 255, 0, 0), 6);
ALL[player.ID].checkpointid=c.ID;
return 1;
}
function destroy_all_checkpoints(player)
{
local cid=ALL[player.ID].checkpointid;
if(cid!=null)
{
local c =FindCheckpoint(cid);
if(c)c.Remove();
ALL[player.ID].checkpointid=null;
}
}
function createmkr(player, pos)
{
destroy_all_markers(player);
ALL[player.ID].markerid=CreateMarker(player.UniqueWorld, pos, 5, RGB(241, 36, 241), 0 );
return 1;
}
function destroy_all_markers(player)
{
local mid=ALL[player.ID].markerid;
if(mid!=null)
{
DestroyMarker(mid);
ALL[player.ID].markerid=null;
}
}
function destroy_all_racecars()
{
local veh;
while(race_cars.len()!=0)
{
veh = race_cars.pop();
if(veh)
{
veh.Delete();
}
}
}

function norm(speed)
{
local q = speed.x*speed.x + speed.y*speed.y + speed.z*speed.z;
return sqrt(q);
}
function getvehicleangle(vehicle)
{
return asin(vehicle.Rotation.z)*2;
}
function vehicle_angle(vid)
{
local vehicle = FindVehicle(vid);local q;
if(vehicle)
{
local s=vehicle.Rotation.z;
local c=vehicle.Rotation.w;
local d=asin(s); //theta by 2
if(c<0)
{
if(s>0)d=makeininterval(d,PI/4,PI/2);
else d=makeininterval(d,-PI/2,-PI/4);
}else if(c>0)
{
if(s>0)d=makeininterval(d,0,PI/4);
else d=makeininterval(d,-PI/4,0);
}else if(c==0)
{
d=d;
}
q = 2 *d;
return q;
}
}

function isanybodyonmission()
{
local i =0;
for(i=0;i<100;i++)
{
local player = FindPlayer(i);
if(player && ALL[i].onmission==1)return true;//somebody is on mission
}
return false;
}
function startrace()
{
if(race_started==true || isanybodyonmission()==false)return;
msg_race_players("3",50006,1);
NewTimer("msg_race_players",1000,1,"2",50006,1);
NewTimer("msg_race_players",2000,1,"1",50006,1);
NewTimer("msg_race_players",3000,1,"GO!",50008,1);
NewTimer("gogo",3000,1);
race_started=true;
}
function msg_race_players(message,sound,style)
{
local i =0;local pos;
for(i=0;i<100;i++)
{
local player = FindPlayer(i);
if(player && ALL[i].onmission==1)
{
if(sound)PlaySoundForPlayer(player, sound)
if(style==1)
{
Announce("~g~"+message,player,6);

if(message=="3")
{
player.SetCameraPos(move2(start_pos,start_angle,10,-PI/2),start_pos);
}else if(message=="2")
{
player.SetCameraPos(move2(move2(start_pos,start_angle,2.5,-PI/2),start_angle,10,0),move2(start_pos,start_angle,2.5,-PI/2));
}else if(message=="1")
{
player.SetCameraPos(move2(start_pos,start_angle,10,PI/2),start_pos);
}
}
else if(style==2)Announce(message,player,5);

}
}

}
function gogo()
{
race_timers.clear();
        local i =0;
for(i=0;i<100;i++)
{
local player = FindPlayer(i);
if(player && ALL[i].onmission==1)
{
player.IsFrozen=false;
player.Immunity=0;
player.RestoreCamera();
if(player.Vehicle)player.Vehicle.Radio=10;//radio off?
if(player.Vehicle)player.Vehicle.Immunity=0;
}
}
}
function endrace()
{

//if(race_started==false)return;
mission_failed_everybody();
race_started=false;
race_announced=false;
destroy_timers();
Message("[#C0C0C0]The race has ended");
}
function destroy_timers()
{
foreach(t in race_timers)t.Delete();
}

function move(pos, distance, angle)
{
local newx = pos.x - sin(angle)*distance;
local newy = pos.y + cos(angle)*distance;
return Vector(newx,newy,pos.z);//assuming z more or less same.
}
function move2(pos,pangle,dis,angle)
{
return move(pos,dis,pangle+angle)
}
function accelerate(vehicle,speed)
{
local angle=getvehicleangle(vehicle);
local x=cos(angle);
local y=sin(angle);
//local speed=1.0; //0 to 1;
vehicle.AddSpeed(Vector(-y,x,0)*speed);
}
function GetDistance(pos1,pos2)
{
return sqrt(pow(pos1.x-pos2.x,2)+pow(pos1.y-pos2.y,2)+pow(pos1.z-pos2.z,2))
}
function getrank(n)
{
switch(n)
{
case 1:return "1st";
case 2:return "2nd";
case 3:return "3rd";
return n+"th";
}
}
function cdata()
{
//this is a sample data i created. you can create your own by

chkdata.push(Vector(-674.615, 702.617, 10.9149));
chkdata.push(Vector(-679.688, 620.902, 10.6974));
//chkdata.push(Vector(-718.341, 272.344, 10.6967));
chkdata.push( Vector(-710.418,327.314,10.9244));
chkdata.push(Vector(-815.816, -55.297, 10.6972));
chkdata.push(Vector(-718.05, -487.612, 11.1073));
chkdata.push(Vector(1.17137, -445.063, 16.7009));
chkdata.push(Vector(183.173, -451.383, 10.6592));
chkdata.push(Vector(399.068, -414.652, 9.65843));
chkdata.push(Vector(494.3, -373.89, 10.6658));
chkdata.push(Vector(302.706, -972.626, 10.6759));
}
//---------------------race creating--------------------------------------
function removecps()
{
local i=0;local c;local d;
while(cps.len()>0)
{
c=cps.pop();//last checkpoint id
d =FindCheckpoint(c);
if(d)d.Remove();
}
}
function removemks()
{
local i=0;local mid;
while(mks.len()>0)
{
mid=mks.pop();
DestroyMarker(mid);
}
}
function reset()
{
removecps();
removemks();
tdata.clear();stpos=null;stangle=null;model=null;author=null;
}

//-----------------------Database functions------------------------------
function allraces()
{
QuerySQL( db, "CREATE TABLE IF NOT EXISTS allraces ( name TEXT PRIMARY KEY,"+
"carmodel INTEGER, stpx REAL, stpy REAL, stpz REAL, stangle REAL);");
}
function saverace(name,array,carmodel,pos,angle)
{

QuerySQL( db, "CREATE TABLE IF NOT EXISTS "+name+" ( id INTEGER PRIMARY KEY,"+
   "x REAL, y REAL, z REAL);" );
local query = QuerySQL(db, "SELECT COUNT(*) from "+name);
local string = GetSQLColumnData(query, 0);
FreeSQLQuery( query );
if(string==0)
{
local i =0;
for(i=0;i<array.len();i++)
{
local p=insertinto(name,i+1,array[i].x,array[i].y,array[i].z);
print(p);
QuerySQL( db, p);
}
local st="INSERT into allraces (name,carmodel,stpx,stpy,stpz,stangle) values("+
"'"+name+"',"+carmodel+","+pos.x+","+pos.y+","+pos.z+","+angle+");";
QuerySQL(db,st);
}
query = QuerySQL(db, "SELECT COUNT(*) from "+name);
string = GetSQLColumnData(query, 0);
FreeSQLQuery( query );
updatelist();//update race list names.
if(string!=null&&string!=0)return true;
}

function insertinto(name,...)
{
local str="INSERT into "+name+"(id,x,y,z) values(";
local i=1;
foreach(val in vargv)
{
str+=val;
if(i<vargv.len())str+=",";
else str+=");";
i++;
}
return str;
}

function existsrace(name)
{
local q = QuerySQL(db, "SELECT * from allraces where name='"+name+"';");
if(q)
{
FreeSQLQuery( q );
return true;
}
return false;
}
function loadrace(name)
{
if(!existsrace(name))return;
chkdata.clear();
local q = QuerySQL(db, "SELECT * from '"+name+"' ;");
if(q)
{
do
{
local x = GetSQLColumnData(q, 1); // 0 is id
local y = GetSQLColumnData(q, 2);
local z = GetSQLColumnData(q, 3);
chkdata.push(Vector(x,y,z));
}while( GetSQLNextRow(q) );
FreeSQLQuery( q );
}

q= QuerySQL(db, "SELECT carmodel,stpx,stpy,stpz,stangle from allraces where name='"+name+"' ;");
if(q)
{
start_car = GetSQLColumnData(q, 0);
local x = GetSQLColumnData(q, 1);
local y = GetSQLColumnData(q, 2);
local z = GetSQLColumnData(q, 3);
start_pos=Vector(x,y,z);
start_angle=GetSQLColumnData(q, 4); //here you can edit
//ie. by default cars will be created one by one backwards like
//people standing in queue. also there are two cars in each row.
//you can change those settings. find that function.
race_name=name;
FreeSQLQuery( q );
if(chkdata.len()!=0)return true;

}

}
function deleterace(name)
{
local q = QuerySQL(db, "DELETE from allraces where name='"+name+"';");
q = QuerySQL(db, "DROP TABLE "+name+";");
updatelist();
}
function updatelist()
{
race_list.clear();
local q= QuerySQL(db, "SELECT name from allraces ;");
local name;
if(q)
{
do
{
name = GetSQLColumnData(q, 0);
race_list.push(name);
}while( GetSQLNextRow(q) );
FreeSQLQuery( q );
return true;
}

}

function rename(oldname, newname)
{
local q= QuerySQL(db, "UPDATE allraces SET name='"+newname+"' where name='"+oldname+"';");
q = QuerySQL(db, "ALTER TABLE "+oldname+" RENAME TO "+newname+";");
updatelist();
}
[/noae][/noae][/noae][/noae][/noae][/noae][/noae][/noae]

plugins xmlconf04rel64 announce04rel64 squirrel04rel64 cmdinputrel64 sqlite04rel64

three sound files
https://drive.google.com/open?id=1oBiKQtrhlTxcb53SosXguQuffM87HYAW

you can create races also. documentation attached.

screenshots



habi

#13
so how does it works?
/list shows a list of races eg. 1.downtown 2. startfish 3.oceanbeach
now /race 1 or 2 or 3
so the player started a race. Others can join by /race
20 seconds. others can join. after this race starts. 3 2 1 go
players pickup checkpoints one after another and final checkpoint picked. he is rank 1
second player rank 2 etc. when everybody finishes race ends.

Also you can create a race by /cp commands. cp==check point
go somewhere and type /cp. a checkpoint appears. go ahead and type another cp. another checkpoint.
so you can create checkpoints in this way. you can do this in car also.
so after creating say about 10 or 15 checkpoints, the race can be saved by /save name.

before saving, you need specify where the race cars should be placed, that is done using /startpos
command sitting in a car. it is detailed in the document.

races are saved and loaded through sqlite database.

Commands
/list /race /stoprace
race creation
/startpos /cp /undo /save  /reset
/acc 1 (to speed up high a car(just using AddSpeed command) ;)) /getcar (spawn a sentinel)

Gito Baloch

Please update the download link it's not working for me why?
Programming is the language I speak, the world I shape, and the future I code